Jump to content

Cronjob Of Cpanel Backup


Recommended Posts

  • 3 weeks later...

Ok I am running the above script with the changes needed. IE username password ftp information and such. This is how I have my cron setup.

>30 3 * * */public_html/local/backup.php

And this is what I had in my email today.

/bin/sh: 30: command not found
Does anyone have any idea what i did wrong.
Link to post
Share on other sites

1) The cron job itself is not set up correctly, as it is trying to run the command "30" instead of your script. If you used the "Advanced (Unix Style)" page in CPanel / Cron Jobs, each of the "30 3 * * *" parameters should be in their own box to the left of the command. If you used the "Standard" page in CPanel / Cron Jobs, then you should have selected the time for your script to run in the various boxes. In either case, no part of the parameters that specify when the cron job should run should be in the "Command" box.

 

2) The path to your script is not correct. Your script would have a full path of /home/cpanelName/public_html/local/backup.php, where 'cpanelName' is your CPanel username.

Link to post
Share on other sites

Help me understand security with this type of thing. This file has username and passwords. Where does it need to be put for security? If it is placed in the public_html folder will it be viewable by anyone? Is it more secure outside the public_html folder? can someone Brose to it and view the source?

Link to post
Share on other sites
Where does it need to be put for security?

Ideally, it should be placed outside (above) the public_html directory if you don't want anyone to be able to call it up in a browser.

 

If it is placed in the public_html folder will it be viewable by anyone?

It isn't necessarily viewable. Since it is a PHP script, someone that opened the script in a browser would cause the script to be run. It would not display the script's source code in the browser.

 

Is it more secure outside the public_html folder? can someone Brose to it and view the source?

Yes, it would be more secure outside the public_html folder. If someone browsed to it, they would cause the script to be run. I don't think it would be good for an anonymous user to be able to run a backup of my site any time they wanted. If the script was called multiple times, it could result in a DOS of your own site, and might even lead to your account being suspended due to excessive server loads.

Link to post
Share on other sites

Can you give an example of Outside the public_html folder please. Or would this work?? As it is outside my public_html file??

 

>30 3 * * */user/bin/backup.php

Edited by JTD
Link to post
Share on other sites

Hmm ok I am getting more confused by the minute. Here is a screenshot of my ftp and the folders in it. Its points to the folder that I placed backup.php into. How would a do my cron with it like that. Also inside the user folder is another one called bin

 

ftp.gif

Edited by JTD
Link to post
Share on other sites

>30 3 * * * /usr/bin/php -q /home/yourCpanelid/user/backup.php

 

If you placed the backup.php script into the root of "user" it would look as above. If it's in a subfolder of "user" just add the path to /user above (IE: /user/bin)

Link to post
Share on other sites
>30 3 * * * /usr/bin/php -q /home/yourCpanelid/user/backup.php

 

If you placed the backup.php script into the root of "user" it would look as above. If it's in a subfolder of "user" just add the path to /user above (IE: /user/bin)

 

 

Ok I am still getting this in my emails instead of a backup. My cron is as follows user name deleted ofcourse.

 

>3 30 * * * /usr/bin/php -q /home/********/user/backup.php

 

 

>/bin/sh: 3: command not found

Link to post
Share on other sites
Ok I am still getting this in my emails instead of a backup. My cron is as follows user name deleted ofcourse.

 

>3 30 * * * /usr/bin/php -q /home/********/user/backup.php

>/bin/sh: 3: command not found

 

"3 30 * * *" is part of the scheduling, put that in the appropriate scheduling fields when you setup the cron job. The actual command is "/usr/bin/php -q /home/********/user/backup.php" and is the *only* thing that should be in the command field. Right now you are putting the scheduling items in the command field so it's attempting to run "3" as the first command.

Link to post
Share on other sites
"3 30 * * *" is part of the scheduling, put that in the appropriate scheduling fields when you setup the cron job. The actual command is "/usr/bin/php -q /home/********/user/backup.php" and is the *only* thing that should be in the command field. Right now you are putting the scheduling items in the command field so it's attempting to run "3" as the first command.

 

 

Well I give up. This is still all I get

>/bin/sh: 3: command not found

My cron is set up correctly according to above post from TCH-Dick

>3 30 * * * /usr/bin/php -q /home/*********/user/bin/backup.php

So I guess Ill just do it the old fashion way. :)

Link to post
Share on other sites
Well I give up. This is still all I get
>/bin/sh: 3: command not found

My cron is set up correctly according to above post from TCH-Dick

>3 30 * * * /usr/bin/php -q /home/*********/user/bin/backup.php

So I guess Ill just do it the old fashion way. :(

 

 

It really isnt that big of an issue. I just thought I would try something new is all. There is alot to be said with sticking to the old way of doing things. IE manual backups. :)

Link to post
Share on other sites
  • 2 months later...

Good morning,

 

1) code for fullbackup.php in Post #4 of this thread does not include:

>// Info required for saving locally
$savedir = "/home/stblogs/"; //Save to this directory

Code in Post # 97 does. which version do I use and why? where does cron job place back up file? is it overwritten each time? Do I need to create a backups folder? If so, what should permissions be set to?

 

2)Post # 114 says command line should say

>3 30 * * * /usr/bin/php -q /home/********/user/backup.php

but Post #4 said

>30 3 * * * /usr/local/bin/php /home/youraccount/fullbackup.php

. why do you add -q after /php ? which do you use?

 

3)If I understand correctly, placing fullbackup.php parallel to public_html folder places it above the root, is that true? and does that render file inaccessible? would you still need to set permissions to 600? would cron job command change to

>3 30 * * * /usr/bin/php -q /home/********/backup.php

 

4)My cpanel theme is X v2.5.0, how do you specify $skin for this theme?

>$skin = "bluelagoon"; // Set to cPanel skin you use (script won't work if it doesn't match)

 

5)On a related topic, where can I see other cpanel themes? Can themes be switched without a support ticket?

Link to post
Share on other sites
Good morning,

 

1) code for fullbackup.php in Post #4 of this thread does not include:

>// Info required for saving locally
$savedir = "/home/stblogs/"; //Save to this directory

Code in Post # 97 does. which version do I use and why? where does cron job place back up file? is it overwritten each time? Do I need to create a backups folder? If so, what should permissions be set to?

You are looking at the same script in both. The first one uses FTP to send the back up to another location. The second one you add the code for the $savedir and modify the $dest to include where to save it. The permissions should be 755 and you place the folder at the same root level as your public_html folder.

 

2)Post # 114 says command line should say
>3 30 * * * /usr/bin/php -q /home/********/user/backup.php

but Post #4 said

>30 3 * * * /usr/local/bin/php /home/youraccount/fullbackup.php

. why do you add -q after /php ? which do you use?

The -q flag is the "quiet" switch which will not produce any output other than what the script is supposed to do or errors. You can use either.

 

3)If I understand correctly, placing fullbackup.php parallel to public_html folder places it above the root, is that true? and does that render file inaccessible? would you still need to set permissions to 600? would cron job command change to
>3 30 * * * /usr/bin/php -q /home/********/backup.php

Anything above your public_html folder is not accessible directly by the web server. The path would be /home/your-cpanel-id/folder-you-specify/backup.php

 

4)My cpanel theme is X v2.5.0, how do you specify $skin for this theme?

>$skin = "bluelagoon"; // Set to cPanel skin you use (script won't work if it doesn't match)

While logged into your cpanel look at the address bar, it should have the skin name in the address.

>https://www.your-domain.ext:2083/frontend/bluelagoon/index.html

 

 

5)On a related topic, where can I see other cpanel themes? Can themes be switched without a support ticket?

If you are not a reseller the only way is with a support ticket.

Link to post
Share on other sites

Thanks Bruce fir the super quick reply. testing the following changes:

 

1) created backup folder with permission level 755 at root level and specified $savedir = "/home/szboora/backup/"; // in fullbackup.php

I kept the // Info required for FTP host declarations in fullbackup.php

why would you use the FTP to send backup to another location instead of site web server?

2) removed the -q flag "quiet" switch from cron job command line.

3) saved fullbackup.php to /home/cpanelid/scripts/fullbackup.php

set permission on scripts folder to 755

set permission on fullbackup.php to 600

4)cpanel skin is " http://www.your-domain.ext:2082/frontend/x/index.html "

5)where can I see what the available cpanel themes look like?

Link to post
Share on other sites
why would you use the FTP to send backup to another location instead of site web server?
To automate downloading the backup and not waste your web space.

 

where can I see what the available cpanel themes look like?

Without having a reseller account not sure if you can see them. cPanel doesn't even have screen shots of what's available.

 

Your cpanel skin is x

Link to post
Share on other sites

Also, another reason why you should FTP your backups (instead of store them on your server) is in the event of data loss, your backups will be lost as well. It's always a wise idea to store your backups on a different machine (and even burn them to a CD/DVD for longer term storage).

Link to post
Share on other sites

ok so use ftp to write backup file to another location instead of writing backup to your site server to:

 

1. automate backup process.

2. save web space.

3. increased security should your site drive fails.

 

benefits 2 & 3 are intuitive. Benefit 1 suggests that I may not yet fully understand cron job. Is it not true that cron job automates backup regardless of weather it is writing to a localhost space or writing to ftp location elsewhere.

 

where would I ftp backup to in order to gain greater security? should i ftp to another TCH server machine ( I am hosting three sites at TCH) , outside TCH server machine?

Link to post
Share on other sites

one more thing fullbackup.php sent an email which appears to be of HTML mime type but my outlook recognized this html email as plain text. My outlook is set up to read both text and html types. Is there a MIME type specification missing in the fullbackup.php script that is causing this?

Link to post
Share on other sites

I really don't have an answer to using the fullbackup script. I manually make my backups. I also download them to my own machine.

 

Yes, cron automates the process for you so you don't have to do it.

 

If you have other siites on other servers yes, you could FTP to them. If the other sites are on the same server it's sort of pointless. If the server went down and had to be restored your backups would have been on the same drive (not good). Another thing is make sure which ever account you are FTPing to has enough space to hold the backup.

 

Aaron - create an ftp account that only has access to the folder you want to send the back up too.

Link to post
Share on other sites

Bruce, I could do that, but I was hoping for a way to pass the directory parameters much the same way a manual backup does. I run backups for my 3 sites and have each stored in a seperate folder. I'd prefer not to add 3 user accounts to my backup server just for this but if it's all that can be done I will do that. Perhaps later I'll take a look at what's being passed to cpanel when you fill in the form for a manual backup.

Link to post
Share on other sites

Yes, there is a way to specify the remote directory for backups. I'll dig up that info and update here.

 

I'll also get the script originally posted in this thread updated soon, too. I know I have a revised version, I just haven't looked at it in awhile.

Link to post
Share on other sites
I forgot to ask, is there a way to specify in this script what folder on the remote FTP server to upload the backups to? I can do it when I do a manual backup through cpanel, but need a way to specify it through this script. Thanks!

 

The remote directory is passed in "rdir" (&rdir=folder_name in the URL)

Link to post
Share on other sites

I just looked at the script again. The only thing I see that would cause it to send you html is if you have $debug = 1. You should be able to set $debug = 0 and put your email in $notifyemail to get a text summary of the backup. The email should be from cpanel@yourdomain, not Cron Daemon.

Link to post
Share on other sites

yes, email is from cpanel, yet it does contain HTML while its internet headers is missing MIME declaration. See below. Sorry about long post. There maybe is a way to define html mime version and content type in fullbackup.php. fullbackup.php contains where to send email and to show debug results:

$notifyemail = "emailbox@****";

$debug = 1;

// Make POST to cPanel

fputs($socket,"POST /frontend/".$skin."/backup/dofullbackup.html?".$params." HTTP/1.0\r\n");

Intenet headers of the email I recieve does not have MIME version and content type, it only shows:

Return-path: <cpanelid@server115.tchmachines.com>

Received: from cpanelid by server115.tchmachines.com

From: root@server115.tchmachines.com (Cron Daemon)

To: emailbox@****

Subject: Cron <cpanelid@server115> /usr/local/bin/php /home/cpanelid/scripts/fullbackup.php

X-Cron-Env: <MAILTO=emailbox@****>

X-Cron-Env: <SHELL=/bin/sh>

X-Cron-Env: <HOME=/home/cpanelid>

X-Cron-Env: <PATH=/usr/bin:/bin>

X-Cron-Env: <LOGNAME=cpanelid>

Message-Id: <xxxxxxx-xxxx-xx@server115.tchmachines.com>

Email contains:

HTTP/1.0 200 OK

Server: cpsrvd/10.6.1

Connection: close

Date: Mon, 06 Feb 2006 03:30:01 -0700

Content-type: text/html

Cache-Control: no-cache

Pragma: no-cache

 

<html>

<head>

<title>cPanel X</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">

<link rel="stylesheet" href="../style.css">

<script language="JavaScript">

<!--

JScript function definitions

function MM_swapImgRestore() etc.

function MM_preloadImages() etc.......

function MM_findObj(n, d) etc.........

function MM_swapImage() etc......

//-->

</script>

</head>

<body onLoad="MM_preloadImages('../images/home_on.gif','../images/logout_on.gif')">

<table width="603" border="1" cellspacing="2" cellpadding="0" bgcolor="#FFFFFF" bordercolor="#D4D9DB" align="center">

<tr valign="top">

<td height="142">

<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">

<tr>

<td height="2" colspan="3">

<table width="100%" border="0" cellspacing="0" cellpadding="0" background="/frontend/x/branding/top_01_bg.gif">

<tr>

<td><img alt="cPanel" src="/frontend/x/branding/top_01_1.gif" width="637" height="41"></td>

<td align="right" width="44"><a target="_top" href="../index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('image01','','../images/home_on.gif',1)"><img alt="[ Home ]" name="image01" border="0" src="../images/home_off.gif" width="44" height="41"></a></td>

<td align="right" width="44"><a target="_top" href="/logout/" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('image02','','../images/logout_on.gif',1)"><img alt="[ Logout ]" name="image02" border="0" src="../images/logout_off.gif" width="44" height="41"></a></td>

</tr>

</table>

</td>

</tr>

<tr>

<td height="19" colspan="3">

<table width="100%" border="0" cellspacing="0" cellpadding="0" background="/frontend/x/branding/top_01-sm_bg.gif">

<tr>

<td align="left" width="145" nowrap><img alt="" src="/frontend/x/branding/top_01-sm_1.gif" width="145" height="70"></td>

<td align="left" width="145" nowrap><img alt="" src="/frontend/x/branding/top_01-sm_2.gif" width="145" height="70"></td>

<td align="left" width="145" nowrap background="/frontend/x/branding/top_01-sm_3.gif"> </td>

<td align="left" width="145" nowrap><img alt="" src="/frontend/x/branding/top_01-sm_4.gif" width="145" height="70"></td>

<td align="left"><img alt="" src="/frontend/x/branding/top_01-sm_5.gif" width="145" height="70"></td>

</tr>

</table>

</td>

</tr>

<tr>

<td height="2" colspan="3">

<table width="100%" border="0" cellspacing="0" cellpadding="0" background="/frontend/x/branding/top_03_bg.gif">

<tr>

<td width="135" nowrap align="left"><img alt="" src="/frontend/x/branding/top_03_1.gif" width="125" height="26"></td>

<td align="right"><img alt="" src="/frontend/x/branding/top_03_2.gif" width="600" height="26"></td>

</tr>

</table>

</td>

</tr>

<tr valign="top">

<td colspan="3">

<table width="100%" border="0" cellspacing="10" cellpadding="0">

<tr valign="top">

<td>

 

<div align="center">

<font class="med"><b>Full Backup in Progress...</b></font> </div> <br><br>

<font class="med">

Once the full backup of your account has been completed you will receive an email message to the address you specified (emailbox@****) </font> <br> <br><br> <div align="center"> <b>[</b> <a href="fullbackup.html"><font class="med">Go Back</font></a> <b>]</b> </div> <br> <br></td></tr></table></td></tr><tr align="center">

<td height="2" colspan="3">

<table width="100%" border="0" cellspacing="0" cellpadding="0" background="/frontend/x/branding/bottom_bg.gif">

<tr align="center">

<td><img alt="" src="/frontend/x/branding/bottom_label.gif" width="327" height="23"></td>

</tr>

</table>

</td>

</tr>

</table>

</td>

</tr>

</table>

</body>

</html>

 

<!---cPanel [10.8.1-STABLE_114] () Copyright © 1997-2005 cPanel, Inc. Licensed on server115.tchmachines.com --->

Link to post
Share on other sites
$debug = 1;
From: root@server115.tchmachines.com (Cron Daemon)

That email was sent from "Cron Daemon."

 

Since you have debug set to "1", fullbackup.php is just dumping the resulting web page to the cron daemon which is in turn emailing it to you. Since the cron daemon is sending the email, it is setting the headers and doesn't know anything about what's being sent. I don't think there is any way to change that.

 

Unless you're trying to debug something, you should be able to set "$debug = 0" and let it email you through the "$notifyemail" address.

Link to post
Share on other sites
I will keep tracking this thread just in case someone figures out how to define html mime version and content type in fullbackup.php so that when you set $debug=1; you recieve html instead of plain text email.

Just curious... Why do you want to keep $debug=1?

Link to post
Share on other sites
I will keep tracking this thread just in case someone figures out how to define html mime version and content type in fullbackup.php so that when you set $debug=1; you recieve html instead of plain text email.

 

The debug was really thrown in there just to troubleshoot when it doesn't work (hence why it gives you the raw output). It's also a little limited in how I can format it because it's Cron that generates the email (and will always generate plain text), not my script. There are things that could probably be done to beautify it, but to be honest, that's adding a lot of complexity for debug output.

Link to post
Share on other sites
  • 11 months later...

Howdy

 

How can cron job delete all but most recent backup to eliminate need to manually delete older backups to save webserver disk space?

 

The cron job referenced in this topic creates a backup named as below on a daily basis and locates the backup at webserver root:

backup-12.30.2006_03-30-03_cpanelid.tar.gz ; over time disk space is filled up and older backups have to be deleted manually.

Link to post
Share on other sites
  • 1 month later...

I run fullbackup.php on several domains at TCH using cron jobs, and for the pastcouple weeks, one of them has been failing every day with the error:

 

Warning: fsockopen() [function.fsockopen]: unable to connect to www.davenallison.com:2082 in /home/davenal/public_html/fullbackup.php on line 40

Failed to open socket connection... Bailing out!

 

I've verified that all the login information and CPanel theme are correct, and I haven't made any changes to the site or script that should've caused this. Strangely, it worked once when I manually ran it a day or two ago, though manually running it today has failed over and over. I'd appreciate any input.

 

Dave

Edited by ashesnglass
Link to post
Share on other sites
  • 1 year later...
This is fast and easy.

I'll post it even though i'm not a TCH client any more because this thread got me to write this script.

Should work great for server to server backups because its FTP.

This can be set up as a one touch backup system or threw a cron job.

><?
// A script produced by BrockHosting.com
// For more help visit h**p://www.brockhosting.com/bb/viewtopic.php?p=13
$user_name = "not_root"; // YOUR cpanel user name

$user_pass = "password_here"; // YOUR cpanel password
$user_website = "www.brockhosting.com"; // YOUR website do NOT include http://

$ftp_server_ip = "1.2.3.4"; // Server IP here
$ftp_server_user = $user_name."_ftp"; // FTP login name here
$ftp_server_pass = "Hd3Z6wpf"; // FTP password here


$db_list = array("phpbb1","ptp","rcash"); // List of your databases
// Must be "database1","Database2"
// DO NOT ENTER "username_database1", "username_database2"


// Do not edit below this line
$dc = time();
$looper = 0;
while($db_list[$looper] != null) {
 $db_name = $db_list[$looper];
 $get_this = "http://".$user_name.":".$user_pass."@".$user_website.":2082/getsqlbackup/".$db_name.".gz";
 echo "\n<br><br>\nAtempting to downlaod $db_name";
 $handle = fopen($get_this, "r");
  $save_as = "backup_".$db_name."_".$dc."_.gz";
 if ($handle != null) {
$local_handle = fopen($save_as,"x");
 echo "\n<br>Saveing \"$db_name\" as \"$save_as\" ";
 while(!feof($handle)){ fwrite($local_handle,fgets($handle)); }
 }
 fclose($handle);
 fclose($local_handle);
 // Got file need ftp home
 $ftp_conn_id = ftp_connect($ftp_server_ip) or die("Couldn't connect to $ftp_server_ip");
 ftp_login($ftp_conn_id,$ftp_server_user,$ftp_server_pass);
 $upload = ftp_put($ftp_conn_id, $save_as, $save_as, FTP_BINARY);
 if ($upload != null) {
 echo "\n<br>File Sent!\n";
 unlink($save_as);
 } else { 
 echo "\n<br>File NOT SENT!\n";
 }

 $looper++;
}
?>

 

 

Hi

 

I've joined this forum soley to say thanks for the above script. I now use it to backup my databases to drivehq as an offsite copy. I had previously backed up to my root, but wanted something a bit safer, so I asked a guy at ScriptLance to amend the code so it would save to drivehq's site in passive ftp mode (the only way to save stuff there, apparently).

 

Anyway, I thought I'd share the amended code in case someone else found it useful. Thanks again to the brockhosting poster. Here's the new version (including the corrected spelling):

 

 

<?

 

// A script produced by BrockHosting.com

// For more help visit h**p://www.brockhosting.com/bb/viewtopic.php?p=13

 

$user_name = "yourusernamehere"; // YOUR cpanel user name

$user_pass = "yourpasswordhere"; // YOUR cpanel password

$user_website = "www.yourwebsitehere.com"; // YOUR website do NOT include http://

 

$ftp_server_ip = "ftp.drivehq.com"; // Server IP here

$ftp_server_user = "yourusernamehere"; // FTP login name here

$ftp_server_pass = "yourpasswordhere"; // FTP password here

 

$db_list = array("phpbb1","ptp","rcash"); // List of your databases

// Must be "database1","Database2"

// DO NOT ENTER "username_database1", "username_database2"

 

 

// Do not edit below this line

$dc = time();

$looper = 0;

while($db_list[$looper] != null) {

$db_name = $db_list[$looper];

$get_this = "

echo "\n<br><br>\nAttempting to download $db_name";

$handle = fopen($get_this, "r");

$save_as = "backup_".$db_name."_".$dc."_.gz";

if ($handle != null) {

$local_handle = fopen($save_as,"x");

echo "\n<br>Saving \"$db_name\" as \"$save_as\" ";

while(!feof($handle)){ fwrite($local_handle,fgets($handle)); }

}

fclose($handle);

fclose($local_handle);

// Got file need ftp home

$ftp_conn_id = ftp_connect($ftp_server_ip) or die("Couldn't connect to $ftp_server_ip");

ftp_login($ftp_conn_id, $ftp_server_user, $ftp_server_pass);

$passive = ftp_pasv ($ftp_conn_id, true );

$upload = ftp_put($ftp_conn_id, $save_as, $save_as, FTP_BINARY);

if ($upload != null) {

echo "\n<br>File Sent!\n";

unlink($save_as);

} else {

echo "\n<br>File NOT SENT!\n";

}

ftp_close($ftp_conn_id);

$looper++;

}

?>

Link to post
Share on other sites
  • 2 months later...

Hey,

 

I think I'm pretty close to getting this figured out but the new backup file is not created. Here is the report and thanks for any and all help. Note *domain.com and *username replace the real thing.

 

> 

Net::FTP>>> Net::FTP(2.77)
Net::FTP>>>   Exporter(5.58)
Net::FTP>>>   Net::Cmd(2.29)
Net::FTP>>>   IO::Socket::INET(1.29)
Net::FTP>>>	 IO::Socket(1.29)
Net::FTP>>>	   IO::Handle(1.25)
Net::FTP=GLOB(0x8a1dec4)<<< 220---------- Welcome to Pure-FTPd [TLS] ---------- Net::FTP=GLOB(0x8a1dec4)<<< 220-You are user number 25 of 50 allowed.
Net::FTP=GLOB(0x8a1dec4)<<< 220-Local time is now 12:46. Server port: 21.
Net::FTP=GLOB(0x8a1dec4)<<< 220-This is a private system - No anonymous login Net::FTP=GLOB(0x8a1dec4)<<< 220-IPv6 connections are also welcome on this server.
Net::FTP=GLOB(0x8a1dec4)<<< 220 You will be disconnected after 15 minutes of inactivity.
Net::FTP=GLOB(0x8a1dec4)>>> USER *username Net::FTP=GLOB(0x8a1dec4)<<< 331 User *username OK. Password required Net::FTP=GLOB(0x8a1dec4)>>> PASS ....
Net::FTP=GLOB(0x8a1dec4)<<< 230-User *username has group access to:  *username Net::FTP=GLOB(0x8a1dec4)<<< 230 OK. Current restricted directory is / Net::FTP=GLOB(0x8a1dec4)>>> TYPE I Net::FTP=GLOB(0x8a1dec4)<<< 200 TYPE is now 8-bit binary Net::FTP=GLOB(0x8a1dec4)>>> ALLO 590067 Net::FTP=GLOB(0x8a1dec4)<<< 200 Zzz...
Net::FTP=GLOB(0x8a1dec4)>>> PASV
Net::FTP=GLOB(0x8a1dec4)<<< 227 Entering Passive Mode (74,124,203,198,119,188) Net::FTP=GLOB(0x8a1dec4)>>> STOR backup-10.5.2008_12-46-02_mirand6.tar.gz
Net::FTP=GLOB(0x8a1dec4)<<< 150 Accepted data connection Net::FTP=GLOB(0x8a1dec4)<<< 226 File successfully transferred Net::FTP=GLOB(0x8a1dec4)>>> QUIT Net::FTP=GLOB(0x8a1dec4)<<< 221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
Net::FTP=GLOB(0x8a1dec4)<<< 221 Logout.
--------------------------------------------------------
pkgacct started.
pkgacct version 7.1 - archive version: 2 - running with uid 0 using time::hires for speedups Copying Reseller Config...Done Copying Suspension Info (if needed)...Done Copying SSL Certificates, CSRS, and Keys...Done Copying Counter Data....Done Copying Bandwidth Data.......*domain.com......*domain.com......*domain.com.*domain.com...Done
Copying Dns Zones.......*domain.com......*domain.com..Done
Copying Mail files....Done
Copying frontpage files....Done
Copying proftpd file....Done
Copying www logs.............
Done
Copy userdata............
Copy custom virtualhost templates............
Done
Grabbing mysql dbs........*username_calgary horde.turba_objects horde.horde_prefs horde.kronolith_events horde.kronolith_storage horde.mnemo_memos horde.nag_tasks ...Done Grabbing mysql privs...Done Copying mailman lists....Done Copying mailman archives....Done Copying homedir....Done Copying cpuser file.......Done Copying crontab file.......Done Copying quota info.......Done Storing Subdomains....
Done
Storing Parked Domains....
Done
Storing Addon Domains....
Done
Storing ssl domain......Done
Copying password.......Done
Copying shell.......Done
pkgacctfile is: /home/*username/backup-10.5.2008_12-46-02_*username.tar.gz
Creating Archive ....Done
md5sum is: 0f4261a34803b9f982e11e2c20b6dd47
--------------------------------------------------------

Link to post
Share on other sites
  • 1 year later...
  • 5 months later...

Hi

 

I've joined this forum soley to say thanks for the above script. I now use it to backup my databases to drivehq as an offsite copy. I had previously backed up to my root, but wanted something a bit safer, so I asked a guy at ScriptLance to amend the code so it would save to drivehq's site in passive ftp mode (the only way to save stuff there, apparently).

 

Anyway, I thought I'd share the amended code in case someone else found it useful. Thanks again to the brockhosting poster. Here's the new version (including the corrected spelling):

 

 

<?

 

// A script produced by BrockHosting.com

// For more help visit h**p://www.brockhosting.com/bb/viewtopic.php?p=13

 

$user_name = "yourusernamehere"; // YOUR cpanel user name

$user_pass = "yourpasswordhere"; // YOUR cpanel password

$user_website = "www.yourwebsitehere.com"; // YOUR website do NOT include http://

 

$ftp_server_ip = "ftp.drivehq.com"; // Server IP here

$ftp_server_user = "yourusernamehere"; // FTP login name here

$ftp_server_pass = "yourpasswordhere"; // FTP password here

 

$db_list = array("phpbb1","ptp","rcash"); // List of your databases

// Must be "database1","Database2"

// DO NOT ENTER "username_database1", "username_database2"

 

 

// Do not edit below this line

$dc = time();

$looper = 0;

while($db_list[$looper] != null) {

$db_name = $db_list[$looper];

$get_this = "
'>http://".$user_name.":".$user_pass."@".$user_website.":2082/getsqlbackup/".$db_name.".gz";

echo "\n<br><br>\nAttempting to download $db_name";

$handle = fopen($get_this, "r");

$save_as = "backup_".$db_name."_".$dc."_.gz";

if ($handle != null) {

$local_handle = fopen($save_as,"x");

echo "\n<br>Saving \"$db_name\" as \"$save_as\" ";

while(!feof($handle)){ fwrite($local_handle,fgets($handle)); }

}

fclose($handle);

fclose($local_handle);

// Got file need ftp home

$ftp_conn_id = ftp_connect($ftp_server_ip) or die("Couldn't connect to $ftp_server_ip");

ftp_login($ftp_conn_id, $ftp_server_user, $ftp_server_pass);

$passive = ftp_pasv ($ftp_conn_id, true );

$upload = ftp_put($ftp_conn_id, $save_as, $save_as, FTP_BINARY);

if ($upload != null) {

echo "\n<br>File Sent!\n";

unlink($save_as);

} else {

echo "\n<br>File NOT SENT!\n";

}

ftp_close($ftp_conn_id);

$looper++;

}

?>

I also solely joined this site to say thanks for this script. (2.5 years after this post. :-) ) This really was helpful for me after messing with system() and wget for awhile. The change I made was to now send the backups to an Amazon S3 account. For my host I needed to include the username_ when specifying the data bases. I actually now use a variant of this as a cron job to send daily backups to my S3 account. You need CURL installed and it uses the S3.php library. I made a few code changes. (e.g changed to date() from time() for better readability and moved it inside the loop because I thought it would be nice to get the date/time to the second for each backup.) Anyway so far it works for me but as they say "your mileage may vary".

<?

require_once './lib/S3.php';

 

if (!extension_loaded('curl') && !@dl(PHP_SHLIB_SUFFIX == 'so' ? 'curl.so' : 'php_curl.dll'))

die("\nERROR: CURL extension not loaded\n\n");

 

$awsAccessKey = 'xxxxxxxxxxxxxxx';

$awsSecretKey = 'xxxxxxxxxxxxxxxxxxxxxxxx';

$bucketName = 'xxxxxxxxxxx';

 

$user_name = "xxxxxxxx";

$user_pass = "xxxxxxxx";

$user_website = "www.yoursite.org";

 

$db_list = array("usrname_Backthisup.sql","usrname_backthisup2.sql");

 

// No need to edit below this line unless you want to keep a copy on your local host

$s3 = new S3($awsAccessKey, $awsSecretKey);

$looper = 0;

while($db_name = $db_list[$looper++]) {

$dc = Date('Y-m-d_G-i-s');

$get_this = "http://".$user_name.":".$user_pass."@".$user_website.":2082/getsqlbackup/".$db_name.".gz";

echo "<br>Attempting to download $db_name";

$handle = fopen($get_this, "r");

$save_as = "./dbbkuptmp/".$dc."_".$db_name.".gz";

if ($handle != null) {

$local_handle = fopen($save_as,"x");

echo "<br>Saving $db_name as $save_as <br>";

while(!feof($handle)) fwrite($local_handle,fgets($handle));

}

fclose($handle);

fclose($local_handle);

 

Echo "<br>Transferring $save_as to S3 $bucketName bucket";

$tries = 1;

while(!$s3->putObjectFile($save_as, $bucketName, baseName($save_as), S3::ACL_PRIVATE) && $tries<=3)

$tries++; //Not sure how robust this is so trying up to three times.

 

unlink($save_as); // comment this out if you want to save a copy on your host

}

exit();

?>

Link to post
Share on other sites
  • 1 month later...

I'm trying to implement the s3 version of this script, but I keep getting an error message on line 22 (the $get_this...) --

Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in /home/mosaicid/public_html/s3backup.php on line 22

any thoughts or ideas?

Link to post
Share on other sites
  • 3 weeks later...

Did you get this sorted out? I've not had that problem.

 

On another matter I'm looking for the inverse of the topic of this thread. Using the same basic approach how would one programmatically take a database archive (as what is produced as described above) and update/replace the database data. The idea here is that on a primary host you ftp your database to another host which serves as a back up to the primary host. So looking for once I've got the gzipped database to be able to replace the existing back up database. (Better yet update just the changes but I suppose that's asking a lot.)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...