diff --git a/readme.md b/readme.md index 7681659..83894bc 100644 --- a/readme.md +++ b/readme.md @@ -2,23 +2,31 @@ ## Overview -The **MB Backup Manager** is a comprehensive backup solution designed for managing automated backups of web applications, particularly those running on the Virtuozzo Application Platform. This tool leverages cron jobs for scheduling backups and utilizes Restic for efficient backup storage and management. +The **MB Backup Manager** is a comprehensive backup solution designed for managing automated backups of web applications, particularly those running on the Virtuozzo Application Platform. This tool leverages Restic for efficient backup storage and management, with support for automated scheduling through cron jobs. ## Features -- **Automated Backups**: Schedule daily, weekly, or custom backups using cron jobs. -- **Backup Types**: Supports backing up core files, media files, and databases. -- **Logging**: Detailed logging of backup operations for monitoring and troubleshooting. -- **Backup Rotation**: Automatically manages old backups to save storage space. +- **Automated Backups**: Schedule and manage backups using `manage_backup_schedule.sh` +- **Backup Types**: + - Core files backup (`backup_core_files.sh`) + - Media files backup (`backup_media.sh`) + - Database backup (`backup_database.sh`) +- **Backup Management**: + - View snapshots with tag filtering (`view_snapshots.sh`) + - Direct backup restoration (`restore_backup_direct.sh`) + - Repository statistics and maintenance (`check_repo_stats.sh`) + - Repository validation (`check_backup_repo.sh`) +- **Logging**: Comprehensive logging system with separate directories for automated and manual backups +- **Backup Orchestration**: Centralized backup management through `backup_all.sh` ## Installation 1. **Clone the Repository**: - Clone the repository containing the backup manager scripts to your local machine or server. The repository can be found at: + Clone the repository containing the backup manager scripts to your local machine or server. [MB Backup Manager Repository](https://deploy.mightybox.io/addons/mb-backup-manager) 2. **Install Dependencies**: - Ensure that `Restic` and `cron` are installed on your system. You can install them using the following commands: + Ensure that `Restic` and `cron` are installed on your system: ```bash sudo dnf install -y cronie @@ -26,7 +34,7 @@ The **MB Backup Manager** is a comprehensive backup solution designed for managi ``` 3. **Set Up Directory Structure**: - Create the necessary directories for logs and scripts: + Create the necessary directories for logs: ```bash mkdir -p /home/litespeed/mb-backups/logs/auto @@ -34,136 +42,167 @@ The **MB Backup Manager** is a comprehensive backup solution designed for managi ``` 4. **Configure Environment**: - Ensure that the environment variables and configuration files are set up correctly, including the Restic password stored in `/etc/restic-password`. + Ensure the Restic password is stored in `/etc/restic-password`. -5. **Install from the Virtuozzo Marketplace**: - To install the MB Backup Manager from the Virtuozzo Marketplace, follow these steps: - - Log in to your Virtuozzo Application Platform dashboard. - - Navigate to the **Marketplace** section. - - Search for "MB Backup Manager" in the marketplace. - - Click on the application to view its details and click the **Install** button. - - Follow the prompts to complete the installation process. +## Core Scripts and Usage - For more detailed instructions on using the Virtuozzo Marketplace, refer to the official documentation: [Virtuozzo Marketplace Documentation](https://www.virtuozzo.com/application-platform-docs/marketplace/). +### Backup Management -## Usage +1. **Viewing Snapshots** (`view_snapshots.sh`): + - View all snapshots or filter by specific tags + - Displays snapshot IDs, timestamps, and associated tags + - Supports an `all` tag to show all snapshots regardless of tags -### Managing Backup Schedules +2. **Direct Backup Restoration** (`restore_backup_direct.sh`): + - Restores specific backup types based on tags + - Handles direct database restoration by piping SQL files from Restic to MySQL + - Automatically detects database credentials from `wp-config.php` -The `manage_backup_schedule.sh` script is used to add, update, or remove backup schedules. +3. **Backup Scheduling** (`manage_backup_schedule.sh`): + - Add or update backup schedules with cron + - Remove existing backup schedules + - Validates cron syntax and dependencies + - Logs all scheduling actions -- **Add or Update a Backup Schedule**: - - To add or update a backup schedule, run the following command: +4. **Repository Maintenance** (`check_repo_stats.sh`): + - Retrieves repository statistics + - Applies retention policies (keeps last 7 backups by default) + - Performs integrity checks + - Removes stale locks + - Logs to `repo_stats_YYYY-MM-DD.log` - ```bash - ./manage_backup_schedule.sh add '0 1 * * *' 'your_restic_password' - ``` +5. **Repository Validation** (`check_backup_repo.sh`): + - Validates repository integrity + - Initializes empty repositories + - Handles stale locks + - Logs to `/home/litespeed/logs/backup_repo_check.log` - This example schedules a backup to run daily at 1 AM. +### Backup Components -- **Remove a Backup Schedule**: +1. **Complete Backup** (`backup_all.sh`): + - Orchestrates the entire backup process + - Calls individual backup scripts for core, media, and database + - Applies consistent tagging (`manual-backup` or `auto-backup` with timestamps) + - Handles error logging and reporting - To remove an existing backup schedule, use: +2. **Individual Backup Scripts**: + - `backup_core_files.sh`: Backs up essential application files + - `backup_media.sh`: Handles media file backups + - `backup_database.sh`: Manages database backups + - Each script can run independently or as part of `backup_all.sh` - ```bash - ./manage_backup_schedule.sh remove - ``` - -### Checking Scheduled Backups - -You can check the current scheduled backups using the `check_sched.sh` script: +### Schedule Monitoring +**Check Scheduled Backups** (`check_sched.sh`): ```bash ./check_sched.sh ``` +Displays current backup-related cron jobs and automation status. -This will log the current cron jobs related to the backup script and indicate whether automated backups are enabled. +## Available Commands -### Running Backups Manually +### Backup Management Commands -To run backups manually, you can execute the `backup_all.sh` script directly: +1. **Schedule Management** (`manage_backup_schedule.sh`): + ```bash + # Add or update a backup schedule + ./manage_backup_schedule.sh add "0 0 * * *" "your_restic_password" + + # Remove all backup schedules + ./manage_backup_schedule.sh remove + + # List current backup schedules + ./manage_backup_schedule.sh list + ``` -```bash -bash /home/litespeed/mb-backups/backup_all.sh -``` +2. **Manual Backup Operations** (`backup_all.sh`): + ```bash + # Run a manual backup + ./backup_all.sh manual + + # Run an automated backup (used by cron) + ./backup_all.sh auto + ``` + +3. **Individual Backup Components**: + ```bash + # Core files backup + ./backup_core_files.sh "restic_password" "backup_tag" + + # Database backup + ./backup_database.sh "restic_password" "backup_tag" + + # Media files backup + ./backup_media.sh "restic_password" "backup_tag" + ``` + +4. **Repository Management**: + ```bash + # Check repository status + ./check_repo_stats.sh + + # Validate repository + ./check_backup_repo.sh + + # View snapshots (all or by tag) + ./view_snapshots.sh + ``` + +5. **Schedule Monitoring**: + ```bash + # Check current backup schedules + ./check_sched.sh + ``` + +6. **Backup Restoration**: + ```bash + # Restore backups directly + ./restore_backup_direct.sh + ``` + +### Environment Variables + +The following environment variables are used by the scripts: + +- `RESTIC_PASSWORD`: Stored in `/etc/restic-password` +- `RESTIC_REPOSITORY`: Default path `/mnt/backup` + +### Log File Locations + +- Automated backup logs: `/home/litespeed/mb-backups/logs/auto/` +- Manual backup logs: `/home/litespeed/mb-backups/logs/manual/` +- Repository stats: `repo_stats_YYYY-MM-DD.log` +- Repository check logs: `/home/litespeed/logs/backup_repo_check.log` +- Schedule actions log: `/home/litespeed/mb-backups/logs/auto/schedule_actions.log` +- Backup addon log: `/var/log/backup_addon.log` ## Troubleshooting 1. **Cron Service Issues**: - - If the cron service is not running, ensure it is installed and started: - ```bash - sudo systemctl start crond - sudo systemctl enable crond - ``` - - To check the status of the cron service, you can run: - ```bash - systemctl status crond - ``` - - If the service fails to start, check the system logs for any error messages related to cron: - ```bash - journalctl -xe | grep crond - ``` + ```bash + sudo systemctl status crond + sudo systemctl start crond + sudo systemctl enable crond + ``` -2. **Log Files**: - - Check the log files located in `/home/litespeed/mb-backups/logs/auto` for any errors or issues during backup operations. - - Each backup run generates a log file with a timestamp, which can help identify when issues occurred. +2. **Log Locations**: + - Automated backup logs: `/home/litespeed/mb-backups/logs/auto/` + - Manual backup logs: `/home/litespeed/mb-backups/logs/manual/` + - Repository stats: `repo_stats_YYYY-MM-DD.log` + - Repository check logs: `/home/litespeed/logs/backup_repo_check.log` -3. **Restic Issues**: - - Ensure that Restic is installed and configured correctly. You can verify its installation by running: - ```bash - restic version - ``` - - If you encounter issues with Restic, check the Restic logs for detailed error messages. You can enable verbose logging by adding the `-v` flag to your Restic commands. +3. **Common Issues**: + - Stale locks: Automatically handled by scripts + - Repository access: Verify Restic password in `/etc/restic-password` + - Backup failures: Check corresponding log files for error messages + - Cron job issues: Verify cron service status and job configuration -4. **Backup Failures**: - - If a backup fails, check the corresponding log file for detailed error messages. The logs are typically located in `/var/log/backup_addon.log`. - - Look for specific error messages that indicate what went wrong during the backup process. - -5. **Cron Job Not Found**: - - If the scheduled cron job is not found, ensure that the `manage_backup_schedule.sh` script was executed successfully and that the cron job was added correctly. - - You can list the current cron jobs by running: - ```bash - crontab -l - ``` - - If the job is missing, re-run the `manage_backup_schedule.sh` script with the correct parameters. - -6. **Debugging Cron Jobs**: - - If your cron job is not executing as expected, you can redirect the output and error messages to a log file by modifying the cron command in the `manage_backup_schedule.sh` script. For example: - ```bash - CMD="RESTIC_PASSWORD=\"$3\" $BACKUP_SCRIPT > \"${BACKUP_LOG_PREFIX}\$(date +\\%Y-\\%m-\\%d_\\%H-\\%M-\\%S).log\" 2>&1" - ``` - - This will help capture any errors that occur when the cron job runs. - -7. **Environment Variables**: - - Ensure that any environment variables required by your scripts (like `RESTIC_PASSWORD`) are set correctly. You can check the environment variables in your cron jobs by adding a command to print them to a log file: - ```bash - env > /home/litespeed/mb-backups/logs/cron_env.log - ``` - -8. **Permissions**: - - Ensure that the scripts have the correct permissions to execute. You can set the executable permission using: - ```bash - chmod +x /home/litespeed/mb-backups/*.sh - ``` - -9. **Testing Scripts Manually**: - - If you suspect an issue with a specific script, try running it manually in the terminal to see if it executes without errors. This can help isolate the problem. - -10. **Check for Running Processes**: - - If you suspect that a backup process is already running, you can check for running instances of your backup scripts using: - ```bash - pgrep -f backup_all.sh - ``` - - This will show you if there are any active processes related to your backup operations. - -By following these debugging tips, you can effectively troubleshoot issues related to the MB Backup Manager and ensure that your backup processes run smoothly. - -## Conclusion - -The MB Backup Manager provides a robust solution for managing backups in a cloud environment. By following the guidelines outlined in this documentation, developers can effectively set up, manage, and troubleshoot the backup processes. For further assistance, please refer to the log files or reach out to the development team. +4. **Permissions**: + ```bash + chmod +x /home/litespeed/mb-backups/scripts/imports/*.sh + ``` ## Repository Information -For the latest updates and commit history, you can find the repository at: +For the latest updates and commit history: [MB Backup Manager Repository](https://deploy.mightybox.io/addons/mb-backup-manager)