Backup with CLI - markhowellsmead/helpers GitHub Wiki
Database
Create database_backup.sh and save it to the webroot of the project.
#!/bin/sh
/home/USER/bin/wp db export --path=/home/USER/public_html/DOMAIN/ - | gzip > /home/USER/public_html/DOMAIN/wp-content/backups/backup-DOMAIN-$(date +"%Y-%m-%d").sql.gz && rsync -avz -e "ssh -i /home/USER/.ssh/id_rsa" /home/USER/public_html/DOMAIN/wp-content/backups/ REMOTEUSER@REMOTEHOST:/FOLDER/ && rm /home/USER/public_html/DOMAIN/wp-content/backups/*
Add a call to this file as the crontab. This example runs every day at 2 a.m.
* 2 * * * sh /home/USER/public_html/DOMAIN/database_backup.sh
Files
Create files_backup.sh and save it to the webroot of the project.
rsync -avz -e "ssh -i /home/USER/.ssh/id_rsa" /home/USER/public_html/DOMAIN/wp-content/ REMOTEUSER@REMOTEHOST:/FOLDER/ --exclude='.git' --exclude='node_modules' --exclude='backupbuddy_backups'
Add a call to this file as the crontab. This example runs every day at 2:30 a.m.
30 2 * * * sh /home/USER/public_html/DOMAIN/files_backup.sh