Backing up your cPanel accounts to a remote location with Rsync

LJSHost

Well-known member
Joined
Jul 5, 2016
Messages
1,031
Best answers
0
Ratings
202
Points
63
#1
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

Code:
#!/bin/sh
cat /var/cpanel/users | while read a; do
/scripts/pkgacct $a /rsync_backups/
done
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:
Code:
chmod +x packaccounts.sh
Change permissons so the file can only be excuted by root:
Code:
chmod 700 packaccounts.sh
Move the file to /root:
Code:
 mv packaccounts.sh /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

Code:
#!bin/sh
rsync -avz  --delete-after /rsync_backups/ [email protected]: /home/backup/
Make the file excutable:
Code:
chmod +x packaccounts.sh
Change permissions so the file can only be executed by root:
Code:
chmod 700 rsync_accounts.sh
Move the file to /root/:
Code:
mv packaccounts.sh /root/

As root ad the cron job

Code:
crontab -e
Add the following to bottom of the file

Code:
0 4 * * * /root/rsync_accounts.sh
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.
 

energizedit

Well-known member
Joined
Dec 13, 2016
Messages
259
Best answers
0
Ratings
14
Points
18
#2
LJSHost, interesting way to do this. I just use the builtin backup with WHM, but can see how rsync may be a better solution.

What is the reasoning for doing it this way and not the builtin backup process?
 

LJSHost

Well-known member
Joined
Jul 5, 2016
Messages
1,031
Best answers
0
Ratings
202
Points
63
#3
LJSHost
Yes, it essentially does exactly what the builtin backup system does it just uses Rsync. One way is not better than the other it's just another option.
I just like writing scripts that do stuff :D
 
Joined
Feb 17, 2017
Messages
51
Best answers
0
Ratings
8
Points
0
#4
interestingly any of you use legacy backup configuration in whm?
 
Joined
Mar 21, 2017
Messages
54
Best answers
0
Ratings
4
Points
0
#5
thanks a lot, we are using a third party tool for backups + cpanel backups but this seems more reliable !...
 
Latest Threads
Recommended Threads

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

Latest Blog ArticlesMost Viewed Threads

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top