harbor run -t LiteCoder/lamp-stack-automated-backupharbor download LiteCoder/lamp-stack-automated-backupSet up an automated backup system that performs scheduled backups of web application files and a MySQL database, with compression, rotation, logging, and cron scheduling.
/var/www/html/ containing at least:
index.php file with PHP content.config.php file.ecommerce_db with at least two tables:
customers (columns: id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100), email VARCHAR(100))orders (columns: id INT PRIMARY KEY AUTO_INCREMENT, customer_id INT, amount DECIMAL(10,2), order_date DATE)Create the following directory layout with permissions 750:
/backup/
├── files/
├── database/
└── logs/
Create an executable Bash backup script at /app/backup.sh. The script must:
File Backup: Archive and compress /var/www/html/ into a .tar.gz file saved under /backup/files/ with the naming format:
files_backup_YYYYMMDD_HHMMSS.tar.gz
Database Backup: Dump the ecommerce_db database using mysqldump and compress it into a .gz file saved under /backup/database/ with the naming format:
db_backup_YYYYMMDD_HHMMSS.sql.gz
Backup Rotation: Delete backup files (in both /backup/files/ and /backup/database/) that are older than 7 days.
Logging: Append a log entry for each backup run to /backup/logs/backup.log. Each log entry must include:
YYYY-MM-DD HH:MM:SSSUCCESS or FAILUREExample log lines:
2025-01-15 02:00:01 SUCCESS Files backup completed: files_backup_20250115_020001.tar.gz
2025-01-15 02:00:05 SUCCESS Database backup completed: db_backup_20250115_020005.sql.gz
If any step fails, log a FAILURE entry with a description of the error.
Exit Code: The script must exit with code 0 if all backups succeed, and a non-zero exit code if any step fails.
Add a cron job for the root user that runs /app/backup.sh daily at 2:00 AM. The cron entry must be verifiable via crontab -l.
After setup, run /app/backup.sh once manually. After a successful run:
.tar.gz file must exist in /backup/files/..sql.gz file must exist in /backup/database/./backup/logs/backup.log must contain at least two SUCCESS lines (one for files, one for database).customers and orders tables.index.php and config.php files.