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:
main configuration file - holding global settings like the backup folder, log file, etc.;
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:
Of course you can fully automate your backups by creating a CRON job to call the script like this:
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):
For any complaints or feature requests, please drop a comment on this page. Backup often!