cPanel

Keep your own off-site copy of a cPanel account with rsync over SSH

Automatically copy your cPanel website files and database dumps to your own computer or server with rsync over SSH, as an extra backup next to MdmHost's daily JetBackup.

AdvancedcPanel hosting2 min read

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 rsync and ssh. 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-PASSWORD

Set 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; done

Keep 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/
  • -a keeps permissions and dates, -z compresses during transfer.
  • --delete mirrors 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_wp in Terminal.

Troubleshooting

  • Permission denied (publickey): the key is not authorised in cPanel SSH Access.
  • mysqldump access denied: wrong credentials in .my.cnf or the user lacks privileges.
  • Connection blocked after many attempts: your IP was blocked; contact support.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.