I read this great post today that shows how to automatically backup cPanel with PHP and a cron job and FTP the backup to a remote host. The guy that wrote this recommends that you keep the file on the server you want to backup, but I have like 50 cPanel sites and so I thought it would be better just to keep all of the login info in one file on my laptop and run it with my local version of PHP (set up WAMP or XAMPP to run php locally on windows). I modified the script by adding an array of sites and then the script loops over each set and backs up that site. Pretty awesome way to do this and the neat thing is that it uses functionality that is built into cPanel to do it.
Here's the code:
So I use this straight from the command line on my local computer and plan to set it up with Windows Scheduler to automate this about every 3 to 5 days. I feel a lot better about having a file with all of my cpanel passwords on my computer rather than on a web server. I think some of the variables I set up like scp usage and the ftp directory are newer so if you have an old version of cpanel then it might not support that. Hope this helps someone else to backup cpanel automatically.
Comments (10)
Feb 13, 2009 at 08:18 PM
Web Development Manila:
nice post, thanks for sharing!
Feb 19, 2009 at 12:49 PM
Sauvegarde automatique de son site » In Mulot Veritas:
[...] adaptation (à lire en anglais) à ce script existe si vous avez plusieurs sites à sauvegarder ainsi [...]
Sep 11, 2009 at 09:49 AM
Justin:
nice, will definately give this a try rather than paying for CP Site Saver.... Cheers!!
Oct 14, 2009 at 04:27 AM
Dagelijkse volledige backups maken van mijn cPanel reseller account naar thuispc ? - webhostingtalk.nl:
[...] moet installeren (eventueel met xampp). Dit script komt overigens flink in de buurt met wat ik wil: http://www.devtrench.com/automatic-cpanel-backup/ Alvast [...]
Dec 31, 2009 at 05:56 AM
Warwick:
Great Script, works well a few small bugs but saves heaps of time. Bug 1 = If a sites password has symbols (or certain symbols anyway) you get the following error when in debug mode and the backup fails Sorry, all fields are required when using FTP or scp. I don't have a fix for this as yet Bug 2 = Improve reliability when backing up lots of sites lots of sites I added the following lines #2 set_time_limit(600); #55 sleep(5); #62 sleep(5); #64 sleep(5); #79 sleep(5);
Jun 09, 2010 at 11:26 AM
Suni:
This is a good choice for small account . But for bigger accounts the remote ftp backup solution is not good. Because it will take good resource to gzip the file. Here you can see a cPanel remote incremental backup pluggin which will help you to manage incremental backups remotely . See here http://www.sherin.co.in/cpremote/
Jun 23, 2010 at 05:26 AM
BALAGURU:
hello, This script is working fine.I am getting backup to my root directory.. IF I WANT TO GET BACKUP DIRECTLY TO MY LOCAL PC.WHAT CAN I DO? PLS SUGGEST ME A SOLUTIONS.THANKS IN ADVANCE
Jun 23, 2010 at 09:44 AM
devtrench:
you'll want to research tools like rsync, scp or WinSCP's scripting feature. cPanel doesn't have a feature like this - it can only save to your root directory or send to an FTP server. So you have 2 options: 1) you can set up your local machine to be an ftp server, or 2) you can use one of the tools above to write a script that logs in periodically and downloads your backup. If you only need files, then you can use rsync to do all of this, but if you want the backup that cPanel generates, then the above 2 methods are all I can think of at the moment.
Aug 09, 2010 at 01:27 PM
Will Ashworth:
Great script. I simplified the arrays a little so I don't have to add the initial array key (ie., 1, 2, 3) every time I add another website. That's pretty much the only thing I changed.http://pastebin.com/VjAipQ11
Sep 22, 2010 at 02:47 AM
Work Sucks:
NEEDS TO SPECIFY PORT!!! Line:51 $params=......&port=.... Port needs to be 21 for SCP