Automatic Database Backup Guide
Note: This cron job runs on the host machine, not inside a Docker container.
1. Prepare the Backup Script
Copy the sample backup script and make it executable:
cp /root/wuwei-docker/db-backup.sh.sample /root/wuwei-docker/db-backup.sh
chmod +x /root/wuwei-docker/db-backup.sh
2. Set Up a Cron Job
Open the crontab editor:
crontab -e
Add the following line to schedule a daily backup at 3:00 AM:
0 3 * * * /usr/bin/bash /root/wuwei-docker/db-backup.sh > /dev/null 2>&1 &
This will run the script silently every day at 3 AM.
3. Test the Backup Script
Run the backup script manually to ensure it's working:
bash /root/wuwei-docker/db-backup.sh
Check if the backup file was created:
ls /root/wuwei-docker/mysql/data/backup
Look for files with a .sql.gz
extension.