Automated cPanel backup

Friday, May 7th 2010, 03:07

A great man once said:

Only wimps use tape backup: real men just upload their important stuff on ftp, and let the rest of the world mirror it ;)

While it works for him, for us pure mortals this trick doesn’t get the job done. That’s why we have to use backups. Protecting your data is important. It’s almost vital that you keep a copy of your most important files in case your primary storage medium just dies on you. Or even worse: it gets hacked. Following my post about securing WordPress, I thought that when my blog got hacked I was lucky to have those files backed-up on my hard-drive which let me reduce the downtime involved by moving my blog to another host. I say lucky because only providence made me make a backup copy to my hard drive.

Since then I’ve decided to automate the backup process and this resulted in a beautifully crafted BASH script which should get the job done for everyone having a web hosting account with cPanel, one of the most popular web hosting administration panels. The script relies on the existence of several configuration files:

  1. main configuration file – holding global settings like the backup folder, log file, etc.;
  2. domain configuration file – a file for every domain a user holds on different accounts/servers with specific data for logging into cPanel and downloading the home directories and MySQL databases (add-on domains data can be downloaded with the primary domain’s). This file should have the same name as the domain (e.g. example.com).

For detailed information about setting up the system I encourage you to read the included README file and the comments from the configuration files. To run the script you just need to have the files set up according to your needs and call it like this:

./getCPANELbackups.sh

Of course you can fully automate your backups by creating a CRON job to call the script like this:

00 00 * * * /path/to/script/getCPANELbackups.sh

Since the domain configuration files hold sensible data (users and passwords) it’s better to assure that no other user on your system has access to them. This means that you must set up the file permissions to 600 (read/write only for your account):

chmod 600 example.com

For any complaints or feature requests, please drop a comment on this page. Backup often!

You might also like:

2 Comments

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


CODE EXAMPLES: When you want to include source code or terminal output, please use the the following tags like in the next example:

    [language]
    code lines
    [/language]
	

where you substitute language with the programming laguage used throught the code example (for terminal output that would be bash), e.g:

    [bash]
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    [/bash]
	

To see a list of all the supported languages, please check this page.

If you want to include code bits inline, please use the code tags like in the following example:

    The <code>$USER</code> variable holds the current logged in username.
	

Projects that I support

Recent Comments

  • nope said:
    yeah that was my first thought too, but: mount: warning: seems to be mounted read-write. too bad, would have been just perfect. more»
  • Klaus Deiss said:
    Dear Radu, I tried it on Ubuntu 10.0.4.2 and 10.0.4.3 with different kernel versions (amd64 server 2.6.32 kernel). No... more»
  • scompo said:
    Nope.. Now it’s not working again.. This printer it’s a real pain in the butt.. The other hp printer I had... more»
  • Dmitrij said:
    Thank you Peter and Patrice. Could you please post the updated script? more»
  • hd_flash_pains said:
    didn’t work for me more»

Recent Tweets

Bear