I just scratched an itch I’ve had for a long time – a proper way to backup cPanel accounts from a reseller account. Up until now I’ve been scripting w get to grab the daily-generated backup of specific accounts every week (imitating what you can do manually by logging into cPanel and navigating to the Backup tab). It was annoying because I had to manually put in the username and password of each account I wanted to backup. What I really wanted was a solution to backup all accounts with minimal fuss.
The solution is a cron job that runs from my reseller account (you don’t need SSH access to do this as cPanel gives you access to your crontab). The solution looks like this:
nice -n 19 tar czhf - ~/backups | ssh user@server.com "cat > /cPanel_backups/$(date +\%A).tgz"
My reseller server puts the daily-generated backups into ~/backups. So, all we have to do is tar this up and copy it over to a backup server.
Notes:
- We give tar the h option so that it stores the contents of symlinked directories in the archive, not real symlinks (the /backups directory in the primary reseller account contains symlinks inside sub-account subdirectories to the real location of eg. mysql snapshots etc..)
- We compress the entire directory and pipe it across the wire via ssh
- The backup is stored with the current day of the week in the name, effectively giving us 7-day rotation
- You should set up password-less SSH access using public/private keys so that the command isn’t prompted for a password
- The above command should be run from cron
- The backslash escaping of the percentage sign in the date command is necessary when the command is run from cron
- UPDATE: nice‘d the command so that it doesn’t consume too many resources and get killed by my provider
As usual, I’ve documented this for future reference in Paddypedia.
Pat, this is a very timely post.
I am going through a similar quandry here at work. We have a dedicated server that we host all our websites on. Before my involvement in this project, the main account on the server was set up with 230+ subdomains, all with their own Joomla install, but all running off the one SQL database. How efficient do you reckon a 14,000+ table SQL database is?! but that’s another story.
So, back to the backups. The cPanel backup that runs every night, creates a daily/weekly/monthly set of all accounts, public_html, sql etc, but the daily set is replaced the very next day. That wasn’t acceptable to me, because you could easily need to restore back more than one day, but less than one week. So I was SSHing to the server with PuTTY to tar the sql folder every morning. At least this would allow for a data/sql restoration even if we needed to find the public_html stuff from another source. The reason I don’t archive the full daily cPanel backup? – it’s 9GB Big!
Now I need to spend time to split all those sub domains into their own accounts, with their own database just to make things more manageable. Joy.
Yikes! 9GB compressed? I guess a lot of that is 230+ duplicate copies of the Joomla install? I’m not familiar with Joomla but does it have some sort of “user uploads” or “user data” directory that you could focus on backing up instead? On some CMS’ you can run multiple sites off a single codebase (which makes updates easier for a start) – looks like Joomla doesn’t support that yet (http://forum.joomla.org/viewtopic.php?f=428&t=199298&st=0&sk=t&sd=a&sid=32d602120d27cae9b33d743db74b4b28) but hopefully one day it will to make your life easier (and your cPanel backups smaller).
Have you thought about setting up a cron job to take care of the daily tarring/rotating of the sql files?
Patrick