Backing up your cPanel accounts to a remote location with Rsync
WHM supports FTP transfer for backups to a remote location but not Rsync, if you would like to use Rsync for transfer here is how you do it, several plugins and paid for solutions are available for Rsync remote backups but with a couple of simple scripts you can Rsync yourself for free.
Create and Rsync Full Account Backups
These backups can be used to restore whole accounts or you can extract individual files from the archive to restore a specific file, email or database. The whole process is completed by using two scripts.
Create the backup directory as root: mkdir /rsync_backups
Script 1 - Packaging accounts
Create a file called packaccounts.sh and add the following to the file
Run the script as a cron job
crontab -e
Add the following to bottom of the file
0 1 * * * /root/packaccounts.sh
Everyday at 1:00am your account will be packaged and ready to Rsync.
Note: this will create the backup files in the /rsync_backups/ directory, ensure more than enough space is available before running the script.
Make the file excutable:
Change permissons so the file can only be excuted by root:
Move the file to /root:
An alternative to using the packaging script is to use the WHM backup manager but make sure the destination for the backups is /rsync_backups/
Script 2 - Rsync the files to the remote server and delete backups
Make the file excutable:
Change permissions so the file can only be executed by root:
Move the file to /root/:
As root ad the cron job
Add the following to bottom of the file
Save and exit the cron file
That's it you're all done everyday at 4:00am rsync will sync the backup files to the remote location and delete the backups on the source server to free up space. It is recommend that you run the packaging script first and see how long it takes to complete as you want Rsync to for example an hour later.
WHM supports FTP transfer for backups to a remote location but not Rsync, if you would like to use Rsync for transfer here is how you do it, several plugins and paid for solutions are available for Rsync remote backups but with a couple of simple scripts you can Rsync yourself for free.
Create and Rsync Full Account Backups
These backups can be used to restore whole accounts or you can extract individual files from the archive to restore a specific file, email or database. The whole process is completed by using two scripts.
Create the backup directory as root: mkdir /rsync_backups
Script 1 - Packaging accounts
Create a file called packaccounts.sh and add the following to the file
Code:
#!/bin/sh
cat /var/cpanel/users | while read a; do
/scripts/pkgacct $a /rsync_backups/
done
crontab -e
Add the following to bottom of the file
0 1 * * * /root/packaccounts.sh
Everyday at 1:00am your account will be packaged and ready to Rsync.
Note: this will create the backup files in the /rsync_backups/ directory, ensure more than enough space is available before running the script.
Make the file excutable:
Code:
chmod +x packaccounts.sh
Code:
chmod 700 packaccounts.sh
Code:
mv packaccounts.sh /root/
Script 2 - Rsync the files to the remote server and delete backups
Code:
#!bin/sh
rsync -avz --delete-after /rsync_backups/ root@backupserver: /home/backup/
Code:
chmod +x packaccounts.sh
Code:
chmod 700 rsync_accounts.sh
Code:
mv packaccounts.sh /root/
As root ad the cron job
Code:
crontab -e
Code:
0 4 * * * /root/rsync_accounts.sh
That's it you're all done everyday at 4:00am rsync will sync the backup files to the remote location and delete the backups on the source server to free up space. It is recommend that you run the packaging script first and see how long it takes to complete as you want Rsync to for example an hour later.