- Install rclone:
curl https://rclone.org/install.sh | sudo bash
- Setup a new Backblaze B2 target: https://rclone.org/b2/
Install a new crontab to run this script daily:
$ crontab -l
30 15 * * * /home/www/db-backup.sh 2>&1>> /tmp/db.log
curl https://rclone.org/install.sh | sudo bash
Install a new crontab to run this script daily:
$ crontab -l
30 15 * * * /home/www/db-backup.sh 2>&1>> /tmp/db.log
#!/bin/bash | |
DATE="$(date +'%Y-%m-%d')" | |
BLOG_NAME=my-db-backup | |
BACKUP_DIR=/home/www/backups | |
BACKUP_FILE=$BACKUP_DIR/$BLOG_NAME-db-$DATE.sql.gz | |
WP_DB_NAME=wordpress | |
WP_USER=user | |
WP_PASS=password | |
BACKBLAZE_BUCKET=my-backups | |
/usr/bin/mysqldump --user=$WP_USER --password="$WP_PASS" $WP_DB_NAME | gzip > $BACKUP_FILE | |
rclone copy $BACKUP_FILE b2:$BACKBLAZE_BUCKET | |
# Keep only the last 30 days worth of backups | |
rclone delete b2:$BACKBLAZE_BUCKET --min-age 30d | |
# Cleanup the local backups dir | |
rm /home/www/backups/*.gz |