Web Hosting Talk







View Full Version : Auto Backup CPanel


Vortech
06-06-2001, 11:59 PM
Does any one have a simple script to back up all of CPanel and users on a CPanel server.

What i need it to do is run once a night backup every thing to FTP on anther server. Once a day and make the file names of the backups some thing like cpanel_2001_6_6.tar or some thing like this.

What i want it to be able to do is if the server fails i could take the last good back setup a new CPanel server and put the files right back where they go and server is right back. Maybe even keep 1 or 2 sitting just in case.

If anyone has something to do this would be great. Ensim had it made in and was nice but i need some thing to do this with CPanel and all its users,mail,mysql every thing that has to do with user server setting for cpanel and cpanel its self.


Will save some time over backing up the hole server.

If it can back every thing that is said in this post it may work.
http://webhostingtalk.com/showthread.php?threadid=12149

I think we could make the simple script i am just not sure how to do ftp from command line.. :rolleyes:
Thanks.:D

Brian Farkas
06-07-2001, 02:17 AM
I believe that to accomplish this you'd have to have 2 scripts... One that would run on the first server, tar up everything, then after it was downloaded via FTP, delete it. On the second server, you would use a script that would open up an FTP connection to the first server, and then get the file.

The first script would have to use this command:

tar -cfz DATEHERE.tgz /

(I think this is correct, but it could also be tar -cfz DATEHERE.tgz * and run in the root directory)

The above command would backup the entire / directory (and all contents) to a file named DATEHERE.tgz.

The script on the second server would then FTP into the first server:

ftp server1.com
< locate the file - probably in the / directory >

Then use this command:
get DATEHERE.tgz /path/to/backup_storage


After the FTP update was done, you'd want to delete the tar file on the 1st server... which is pretty easy:
rm DATEHERE.tgz

Here's the thing: make sure you are going to have enough disk space to backup the entire / directory. If you don't, you'll run into problems. I hope this helps!

Brian

Vortech
06-07-2001, 10:25 AM
I know how to do everything but command line ftp in a script so that it can login in and get the files. can you post an example of how to do this please

gordita
06-07-2001, 08:42 PM
yeah, this would be really nice!

I can see it now....


[gordita@host]# cpanelar --help
Usage: cpanelar [OPTION] [ACCNT NAME]
Archives account data and settings for a CPanel account.
-c Creates an archive.
-x Extracts an archive thus setting up a CPanel account.


... *dream sequence ends*..

Let's do it!

gordita
06-07-2001, 09:05 PM
If you had the module installed (if not, try http://search.cpan.org/search?dist=libnet) you could do something like:


use Net::FTP;

$ftp = Net::FTP->new("some.host.name", Debug => 0);
$ftp->login("anonymous",'me@here.there');
$ftp->cwd("/backup_cpanels");
$ftp->get("that.file");
$ftp->quit;

Darkedge
06-08-2001, 04:02 PM
That doesn't seem to be working I am very unfamiliar with this command here is what i scripted

ftp Net::FTP->new("198.172.189.110", Debug => 0);
ftp->login("xxxxx",'xxxxx');
ftp->lcd("/home/mpence")
ftp->cwd("/");
ftp->put("itworked.txt");
ftp->quit;


this is what i get back

./test: syntax error near unexpected token `Net::FTP->new("'
./test: ./test: line 1: `ftp Net::FTP->new("198.172.189.110", Debug => 0);'

probably my limited knowledge is causing the problem so please help me out here

JonnyQuags
06-08-2001, 04:11 PM
Check out scp

man scp in your box


You will probably just have to make a trust relationship between the 2 servers but the second server wouldn't have to do anything but recieve the file ;)

If you are usin gperl use the system command to call something like

scp -r /location/on/newserver hostname.com:/path/to/backup.tgz

Vortech
06-08-2001, 10:37 PM
Not sure if you were messing with me or what.
But that command would be killer.. hehe

We are trying to come up with a easy one or two commands to run get every thing together and send it off to a server off site or a anther server. This way if the server crashed we could just install CPanel put back the last good files and done..


We can do every thing right now but getting the FTP part to work still can't get so anyother ideas would be great or a working sample of code would be great.

Can't use copy becase it could go to a windows server or a server off site.

Thanks

gordita
06-09-2001, 12:45 AM
Try creating a file on your server named testftp.pl and then put your ftp user and pass as the first and second arg of the login() function.


#!/usr/bin/perl -w

use Net::FTP;

$ftp = Net::FTP->new("127.0.0.1", Debug => 0);
$ftp->login("xxx","xxx");
$ftp->put("./testftp.pl");
$ftp->quit;


exit;


Then run the script and this should FTP it the script itself to your home directory.

For the purpose of your backup files you could just create a loop around a statement that would look like:


$ftp->put("/server1_baks/$file","/server2_baks/$file");


The second arg of put() is the remote file.

carpman
06-13-2001, 04:23 AM
Did any one finalise this proceedure? a final script and short howto would be great if they had.

carpman
06-13-2001, 05:48 AM
this script seems to be one that might work, anyone in the know want to look at it and give feed back

http://www.superscripts.com/scripts/backup.html

Box0
12-29-2003, 01:04 PM
This is a good thread on backups in CPanel :

http://howtoadmin.com/index.php?showtopic=19

Techark
12-29-2003, 01:18 PM
Originally posted by Box0
This is a good thread on backups in CPanel :

http://howtoadmin.com/index.php?showtopic=19

Did you happen to look at the date on this thread?

Talk about diggin up the dead.