The cPanel Backup System
Us cPanel system admins pity those who neglect to back up their sites and then blame their hosts when something goes awry…especially when cPanel makes it so damn easy to back up your entire account in just a few clicks — And we’re going to tell you how to do it.
Of course, we’re not going to stop there. We’re going to tell you exactly how the cPanel backup system works, how to generate/restore backups, what’s in the backups, and how to automate them so you can spend more time at the bar definitely working and not drinking beer, instead of worrying about what’s going to happen if a gnome crawls into your server vent and eats your hard drive.
Understanding the Process
The method in which cPanel generates backups is very unique, and is formulated by the cPanel developers to allow site owners and web hosts to seamlessly move entire accounts between cPanel servers. Below is the basic process that occurs when a cPanel backup is run:
- A folder is created in /home/cpmove-$user (assuming /home is the home folder)
- Configurations are copied to the above cpmove folder (reseller, suspension info, counter data, bandwidth stats, DNS zones, FTP data, logs, SSL certificates, mailing lists, etc)
- The entire home directory is copied to the cpmove folder
- All databases and crons are dumped into the cpmove folder into ‘mysql’
- The cpmove folder is gzipped into a file called /home/cpmove-$user.tar.gz
That being said, there are some pros and cons to the way cPanel does its backups:
Pros:
- The backup is portable to almost any other cPanel server, and is fully automated (and somewhat flawless since cPanel 11)
- The backup is complete, and can be pieced apart for transferring site content to other [non-cpanel] servers
- The actual backup file tends to be up to 80% smaller than the size of the account, since it’s gzipped
- With this system, it’s very easy to mass-transfer a large number of sites from one cPanel server to another
Cons:
- Due to the way the backup is run, it’s NOT optimal for larger accounts since the files are copied to the disk and then gzipped. Compressing a large amount of data can be very CPU intensive. Larger sites may not be able to utilize cPanel backups without taxing the resources on the server
- The actual process of generating a backup for a larger account essentially doubles the amount of disk space that the account is using for a short amount of time, so the administrator needs to make sure plenty of space is available
- cPanel has changed a lot (for the better) in the way that processes are run, so backups made by older versions of cPanel may not come over cleanly on newer versions, and vice-versa
Ways to Generate Backups
You can generate backups on-demand using a couple methods:
/scripts/pkgacct $user [location]
*By default, backups made with this option will go to /home, unless [location] is specified
Or you can go into cPanel and select Backups ~> Download or Generate Full Web Site Backup , or use the Backup Wizard. This will start generating the backup in /home (if /home is your home dir) and then move it to the user’s home folder when complete, and the file will be named backup-<date/time>-.tar.gz
Tip: If you want to generate a backup of a large account and skip the account’s home folder, you can pass the –skiphomedir option. This will back up all the account files, minus /home/
Restoring Backups
To restore a full backup, you have to be an administrator on the server, however, you can restore MySQL and cPanel home directory backups from a user’s cPanel as long as the backups being restored are actually of those types and not a full backup. To restore from command line, move the backup file to /home and run:
/scripts/restorepkg $user [file]
This will automatically look in a few directories for a cPanel backup file (cpmove-$user.tar.gz, backup–$user.tar.gz) and start restoring it. The user should be terminated from the system prior to restoring a full backup, for the best results. If the backup is located elsewhere on the server, specify that in the [location] parameter to the command. If the user was a reseller and you want to remove those privileges upon restore, pass –skipres before the username. If the user on the server already exists and you want to restore anyway, pass –force before the username. You can pass –ip=(y|n|) if you want to give the account a dedicated IP address.
You can also restore backups from within WHM ~> Restore Backups, where you’d enter the username and let WHM restore it for you. A restored backup file is moved to /home/cprestore .
What’s inside
There may be a time when you want to restore parts of a full backup but not the whole thing, so it’s helpful to know where certain things are kept within a cPanel backup archive. For starters, take the backup and uncompress it (tar -xvzf ) and enter into the resulting folder. You’ll see a bunch of folders and files, to name a few and where they correspond on the server:
- sslkeys/sslcerts – contain the SSL key, csr, and certificate files for the account
- meta – contains information about the user’s home folder location and what kind of mail system they were on (Courier,Dovecot,cppop)
- resellerconfig – contains the ACL and permissions if the user is a reseller
- counters – the files in /var/cpanel/Counters (the counters they create in cPanel)
- bandwidth – the user’s bandwidth usage data (/var/cpanel/bandwidth)
- dnszones – any DNS zones for the domains in the account
- mysql/psql – the MySQL and PostgreSQL databases, respectively, as database dumps (.sql files)
- homedir/homedir.tar – the entire /home directory for that user (everything in /home/$user)
- cron – the cron jobs configured for that user (/var/spool/cron/$user)
- cp – the cPanel user file (/var/cpanel/users/$user)
- va/vad – forwarders and domain forwards (/etc/valiases, /etc/vdomainaliases)
- logs – the Apache domlogs/raw logs (/usr/local/apache/domlogs)
- userdata – the Apache userdata files for building httpd.conf (/var/cpanel/userdata/$user)
- shell – the shell enabled for the user (goes in /etc/passwd)
- shadow – the linux encrypted password for the user (goes in /etc/shadow)
- quota – what the user’s disk quota is
- nobodyfiles – what files were owned by nobody, so they can be chown’d during the restore
- ssldomain – if the domain had an SSL, which hostname it was for
Skipping Files and Accounts
You may wish to skip files or certain accounts. To sip files, create a cpbackup-exclude.conf file in the account root and simply list (you can use regular expressions) the files that you don’t want to back up. If you want to globally skip certain files, you can edit /etc/cpbackup-exclude.conf (which already contains a list of skipped files) to be excluded from all cPanel backups created. To exclude users from backups, create /etc/cpbackup-userskip.conf and list the users you don’t want to back up.
Automating cPanel Backups
There are a couple ways to automate cPanel backups on your server.
Server-Wide
In WHM ~> Backup Configuration you can enable backups for all (or selected) users as well as certain server configurations. This is essentially the same as periodically running cPanel backups of all your accounts, so again, you’ll want to make sure you have the CPU power and disk space to support this option, especially if a) you have a crapload of accounts or b) you have large accounts.
This configuration directly corresponds with the /usr/local/cpanel/bin/backup cron job in the root crontab. It runs at a specific interval and does the automated backup, if backups are configured.
This will also usually allow users to download the full backups from within their cPanel. If you are not using server-wide backups, I would recommend that you enable the settings in WHM > Tweak Settings to NOT warn users about server backups not being enabled, as even if you’re using a custom backup solution, it may confuse some users when they see the warning in cPanel that server backups are not running.
You can test the automated backups by running:
/usr/local/cpanel/bin/backup
If it says “Backup Not Enabled”, you didn’t set it up right.
Per Account
This method is mainly useful when you don’t have root access to your server to be able to configure server-wide backups, or if you only want backups for a couple users, and allow the user to control it. Below is a link to a popular script for automating cPanel backups via cron job:
http://www.v-nessa.net/2007/01/03/cpanel-automated-backup-script/
Conclusion
Now that you know everything you could possibly need to know about cPanel’s backup system, your lazy ass has no reason not to back up your server. If you’re the server administrator, you should always keep backups of your site, even if you think your hosting provider is doing it for you. You never know when something is going to go wrong, and I don’t even know why some people would rather risk losing their site than taking a few minutes to back it up. So just do it…really…
Also keep in mind that using cPanel’s backup feature is not the only way to back up your site, and isn’t optimal for all types of servers. If you find that your site/server is in this category, you may want to look into offsite or custom backup solutions.
9 Comments
Pingback: 11 Ways to Free Up Disk Space on a cPanel Server :: The cPanel Admin
Pingback: Ways to Free Up Disk Space on a cPanel Server « Server~Techs
Pingback: Restoring Daily Backup - cPanel Forums
Thanks for a very thorough article and as a newcomer to whm and cpanel it was very helpful. I have a question though about the server as a whole. Which is besides backing up all the individual user accounts which I can now do thanks to the above – how do you suggest backing up the whm base server and settings itself.
Some configuration files are already backed up, but you can always use a script to back up everything else!
Thanks Vanessa
Pingback: FarhanFaisal » cPanel backup and restore, per user
Good stuff Vanessa. I refer noobs to your site!
Pingback: 景博的blog » Blog Archive » cpanel还原大文件