MdmHost backs up every account daily with JetBackup. Some businesses also want an independent copy under their own control, for example on an office NAS or another server. With SSH keys, a database dump cron job and rsync, you can pull only the changes every night, efficiently and automatically.
Before you start
- SSH access on your cPanel account with a key; see SSH access and keys.
- A Linux machine, NAS or Mac that is always on and has
rsyncandssh. On Windows, use WSL. - Enough storage at the destination.
Step 1: dump databases on the server
Files can be copied directly, but databases should be exported first. Create a file ~/.my.cnf on the hosting account (in File Manager or Terminal) so passwords are not in scripts:
[client]
user=cpuser_backup
password=STRONG-PASSWORDSet it to 600 permissions. The user needs access to the databases you back up (add the user to each database). Then add a cron job at 02:00 daily:
mkdir -p ~/db-dumps; for db in cpuser_wp cpuser_shop; do mysqldump --single-transaction "$db" | gzip > ~/db-dumps/$db.sql.gz; doneKeep db-dumps outside public_html.
Step 2: pull with rsync from your machine
On the destination machine, test once:
rsync -az --delete -e "ssh -i ~/.ssh/id_ed25519" cpuser@example.com:public_html/ /backups/example/public_html/rsync -az -e "ssh -i ~/.ssh/id_ed25519" cpuser@example.com:db-dumps/ /backups/example/db-dumps/-akeeps permissions and dates,-zcompresses during transfer.--deletemirrors deletions; leave it off if you prefer to keep deleted files.- Exclude caches to save time:
--exclude 'wp-content/cache/'.
Step 3: schedule it
On the destination machine run crontab -e and add, for 03:00 daily (after the dump finished):
0 3 * * * rsync -az -e "ssh -i /home/me/.ssh/id_ed25519" cpuser@example.com:public_html/ /backups/example/public_html/ && rsync -az -e "ssh -i /home/me/.ssh/id_ed25519" cpuser@example.com:db-dumps/ /backups/example/db-dumps/Tip: A mirror is not a history: if files get corrupted, the next sync copies the damage. Snapshot the destination (NAS snapshots, or a tool such as restic) to keep several days of versions; see rsync and restic backups.
Email too?
Mail lives in ~/mail. You can include it with another rsync line, but it changes constantly and can be large. For most people JetBackup's daily email backups are enough; see restore email.
Restoring from your copy
- Upload files back with rsync (swap source and destination) or FTP.
- Import a dump with phpMyAdmin or
gunzip < db.sql.gz | mysql cpuser_wpin Terminal.
Troubleshooting
- Permission denied (publickey): the key is not authorised in cPanel SSH Access.
- mysqldump access denied: wrong credentials in
.my.cnfor the user lacks privileges. - Connection blocked after many attempts: your IP was blocked; contact support.
