August 25, 2006
CPanel Backup and Restore
I recently had the experience of needing to backup, move, then restore all of the accounts of a VPS driven by Web Host Manager. What I thought would be a painful experience actually turned out to be quite pleasant.
The tech support helped me with a few simple, but very powerful commands.
What’s important here is that you have access to a second server, root access, so you can move files over to. And, you want to save all of your files in an accessible directory, typically a directory below the /home directory (assuming your directory structure looks like /home/username/).
Without further ado, here’s what you need to do to backup, ftp, then restore a CPanel driven site that you have root access to.
First thing to do is to tar all of the MySQL databases using the following command.
tar zcpf mysql.tar.gz /var/lib/mysql
Move this .gz file to an accessible /home/username directory, something like this: mv mysql.tar.gz /home/username/. <- note well that is a "dot" at the end of the command and not a period to end the sentence.
Next, run the following command on the command line, be sure to include the quotes - single and double.
for i in `ls -A /var/cpanel/users`;do echo “Packaging ” $i “at ” `date`;/scripts/pkgacct $i; echo $i >>/home/acct_list;done
This loops through all of your accounts and runs a packaging script, when complete it dumps the account names into /home/acct_list.
After this is complete on the server. Login into another server - if you are using a Windows PC type computer, Putty is a free program available that allows you to SSH into your server. On the other server, you need to ftp into the original server and run the following commands.
ftp -i
ftp> open ftp.domain.com
Name: username
Password: password
ftp> mget *gz
ftp> get mysql.tar.gz
ftp> bye
This sequence of commands will move all of the files to your new server, don’t worry, they don’t take up much room at all.
Once you are ready to move back all the files to your original server, login to the original server and using the ftp commands mentioned above to bring back all of those files to the /home directory. Then run the following.
for i in `cat /home/acct_list`;do echo “Restoring ” $i “at ” `date`;/scripts/restorepkg $i;done
This will loop through all of the accounts listed in /home/acct_list and restore those accounts including MySQL databases.



