|
GMTurner
|
 |
« Reply #75 on: August 31, 2006, 03:19:22 PM » |
|
I have a file that include the db connection info which I keep "outside" of the public_html folder and then include it in scripts that need a connection to the DB. I also have some other scripts outside of public_html that are triggered by mail filters or run via cron... so, yes, they can be outside of public_html.
|
|
|
|
|
Logged
|
The above post was made at a time when I gave a dang and doesn't necessarily reflect my current views or opinions. For those no longer with us ... The Redheaded Penguin
|
|
|
Xaneth
Trekkie

Offline
Posts: 19
|
 |
« Reply #76 on: May 20, 2007, 02:13:15 PM » |
|
I read through this thread Friday night, and have been using these scripts to backup my databases, as well as my entire site for the last year. I hadn't been monitoring the emails about the cron jobs, and I noticed that my entire site script has been timing out, so I changed the max_execution_time to 999 in php.ini, which seems to overcome the uploading issue, since my site is close to a gig. I have a couple of domains on my account, and I created a custom script to just backup a certain set of subfolders of public_html as follows: <? $datestamp = date("Y-m-d_H-i-s"); // Current date to append to filename of backup file in format of YYYY-MM-DD
/* CONFIGURE THE FOLLOWING VARIABLES TO MATCH YOUR SETUP */ $filename= "Soldotna-High-School-$datestamp.tar"; // The name (and optionally path) of the dump file $ftp_server = "FTP IP address"; // Name or IP. Shouldn't have any trailing slashes and shouldn't be prefixed with ftp:// $ftp_port = "21"; // FTP port - blank defaults to port 21 $ftp_username = "username"; // FTP account username $ftp_password = "password"; // FTP account password - blank for anonymous $filename = "/home/cpanel-userid/public_html/soldotnahighschool/backup/" . $filename . ".gz";
$command = "tar cvf $filename /home/cpanel-userid/public_html/soldotnahighschool/*"; $result = exec($command);
$command = "gzip -9 -S .gz $filename"; $result = exec($command);
// set up basic connection $ftp_conn = ftp_connect($ftp_server);
// Turn PASV mode on or off
ftp_pasv($ftp_conn, false);
// login with username and password $login_result = ftp_login($ftp_conn, $ftp_username, $ftp_password);
// check connection if ((!$ftp_conn) || (!$login_result)) { echo "FTP connection has failed."; echo "Attempted to connect to $ftp_server for user $ftp_username"; exit; } else { echo "Connected to $ftp_server, for user $ftp_username"; }
// upload the file $upload = ftp_put($ftp_conn, "foo.tar.gz", $filename, FTP_BINARY);
// check upload status if (!$upload) { echo "FTP upload has failed."; } else { echo "Uploaded $filename to $ftp_server."; }
// close the FTP stream ftp_close($ftp_conn);
unlink($filename); //delete the backup file from the server ?> This seems to work, and does tar the files the way I expect. I commented out the gzip command, since the tar file already results in a .gz file, but the script failed, so I un-commented gzip. The cron job works, but uploads foo.tar.gz to my site, instead of the file name I specified? As the operation works, I can see that it puts the correct filename in the area on my website, but uploads foo.tar.gz? How do I fix this? This is the email I get: tar: Removing leading `/' from member names tar: /home/cpanel-userid/public_html/soldotnahighschool/backup/Soldotna-High-School-2007-05-20_11-30-01.tar.gz: file is the archive; not dumped gzip: /home/cpanel-userid/public_html/soldotnahighschool/backup/Soldotna-High-School-2007-05-20_11-30-01.tar.gz already has .gz suffix -- unchanged Connected to FTP IP Address, for user FTPUserUploaded /home/cpanel-userid/public_html/soldotnahighschool/backup/Soldotna-High-School-2007-05-20_11-30-01.tar.gz to FTP IP Address Note: I used cpanel-userid in place of my real cpanel id, and masked my FTP address, username and password.
|
|
|
|
|
Logged
|
|
|
|
|
Gaartok
|
 |
« Reply #77 on: June 05, 2007, 04:49:02 AM » |
|
My ISP blocks incoming port 21, so I need to change the port number of the FTP connection. In the script, it appears that the $ftp_port isn't used anywhere. I'm attempting to figure out how to set the port, but I can't get it to work.
I tried: $ftp_full_server = $ftp_server . ":" . $ftp_port; $ftp_conn = ftp_connect($ftp_full_server);
but that gives the error: Warning: ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/xxxxxx/public_html/backups/siteBackup.php on line 21
I don't know if it's a PHP error or an FTP error. I don't know PHP, and I can't find any information on the proper syntax of changing a port in an FTP client. host:port doesn't work (in a Windows DOS box at least).
Anyone know how to fix this?
Thanks, Dave
UPDATE: Found my own answer:
$ftp_conn = ftp_connect($ftp_server, $ftp_port);
|
|
|
|
« Last Edit: June 05, 2007, 05:06:21 AM by Gaartok »
|
Logged
|
|
|
|
|
codwif
|
 |
« Reply #78 on: July 07, 2007, 06:49:53 PM » |
|
so, i got the script to email me a backup of all my sql databases, but here's a dumb question, if the time comes, how do i restore my databases from this zip file?
|
|
|
|
|
Logged
|
|
|
|
Xaneth
Trekkie

Offline
Posts: 19
|
 |
« Reply #79 on: October 04, 2007, 08:06:30 PM » |
|
So I'm trying to run these scripts, and the ones for my databases to FTP work fine, however the ones for my site to FTP are not. I'm trying to run the following, since I want just a subdirectory zipped up: <? $datestamp = date("Y-m-d_H-i-s"); // Current date to append to filename of backup file in format of YYYY-MM-DD
/* CONFIGURE THE FOLLOWING VARIABLES TO MATCH YOUR SETUP */ /* THIS FILE BACKS UP SOLDOTNA HIGH SCHOOL SITE ENTIRELY */ $filename= "Subdirectory-Full-$datestamp.tar"; // The name (and optionally path) of the dump file $ftp_server = "FTP's IP"; // Name or IP. Shouldn't have any trailing slashes and shouldn't be prefixed with ftp:// $ftp_port = "21"; // FTP port - blank defaults to port 21 $ftp_username = "user"; // FTP account username $ftp_password = "password"; // FTP account password - blank for anonymous $filename = "" . $filename . ".gz";
$command = "tar cvf ~/$filename ~/public_html/mysubdirectory/*"; $result = exec($command);
$command = "gzip -9 -S .gz ~/$filename"; $result = exec($command);
// set up basic connection $ftp_conn = ftp_connect($ftp_server);
// Turn PASV mode on or off
ftp_pasv($ftp_conn, false);
// login with username and password $login_result = ftp_login($ftp_conn, $ftp_username, $ftp_password);
// check connection if ((!$ftp_conn) || (!$login_result)) { echo "FTP connection has failed."; echo "Attempted to connect to $ftp_server for user $ftp_username"; exit; } else { echo "Connected to $ftp_server, for user $ftp_username"; }
// upload the file $upload = ftp_put($ftp_conn, "foo.tar.gz", $filename, FTP_BINARY);
// check upload status if (!$upload) { echo "FTP upload has failed."; } else { echo "Uploaded $filename to $ftp_server."; }
// close the FTP stream ftp_close($ftp_conn);
unlink($filename); //delete the backup file from the server ?>
The file get's tarred, but I get the following in the email: Failed loading /cpanelusername/public_html/ioncube/ioncube_loader_lin_4.4.so: /cpanelusername/public_html/ioncube/ioncube_loader_lin_4.4.so: cannot open shared object file: No such file or directory tar: Removing leading `/' from member names gzip: /home/cpanelusername/Subdirectory-Full-2007-10-04_19-44-01.tar.gz already has .gz suffix -- unchanged X-Powered-By: PHP/4.4.7 Content-type: text/html
Connected to FTP's IP, for user userFTP upload has failed.
A couple of things here. One the file gets created in the root, but is about 2.5 GB. It connects to my FTP server, then promptly disconnects for no reason. Is there a setting in the php.ini file I need to make for such a large transfer? Possibly a time out? My max execution time is cranked. Here's my php.ini: upload_max_filesize = 20M max_execution_time = 999 ; Maximum execution time of each script, in seconds register_globals = Off allow_url_fopen = Off zend_optimizer.optimization_level=14 zend_extension = /cpanelusername/public_html/ioncube/ioncube_loader_lin_4.4.so
I also have another script that is identical to this one to grab a different subdirectory. It ran and uploaded the file foo.tar.gz and was the wrong file size and corrupted. What am I doing wrong here? Edit: Guess I posted something similar just above a while back. Well, looking at the file, I may have some pathing wrong, but still getting the funky foo.tar.gz thing going on. And it's not staying logged in to my FTP server for some unknown reason.
|
|
|
|
« Last Edit: October 04, 2007, 08:10:01 PM by Xaneth »
|
Logged
|
|
|
|
|
scanman20
|
 |
« Reply #80 on: October 12, 2007, 08:41:54 AM » |
|
Not sure why the file would be corrupted but as for the dropped connection try changing to a pasv connection.
// Turn PASV mode on or off
ftp_pasv($ftp_conn, true);
|
|
|
|
|
Logged
|
Even a broken clock is right twice a day. NotOneBit.comMCSE - MCSA - MCP
|
|
|
Xaneth
Trekkie

Offline
Posts: 19
|
 |
« Reply #81 on: October 14, 2007, 01:05:36 PM » |
|
Thanks scanman, I'll give that a shot! Full backup runs today, so we'll see what happens!
|
|
|
|
|
Logged
|
|
|
|
Xaneth
Trekkie

Offline
Posts: 19
|
 |
« Reply #82 on: October 14, 2007, 01:50:55 PM » |
|
I get the following error in the email when trying to turn PASV mode on: <br /> <b>Warning</b>: ftp_pasv() expects parameter 1 to be resource, boolean given in <b>/home/<cpanel account>/sohi.php</b> on line <b>24</b><br /> <br /> <b>Warning</b>: ftp_login() expects parameter 1 to be resource, boolean given in <b>/home/<cpanel account>/sohi.php</b> on line <b>27</b><br /> FTP connection has failed.Attempted to connect to ftp.server.com for user <ftp user>
I did reduce the file size to 1.4 GB, so I'm working with it today to see what I can accomplish as well with a smaller file size.
|
|
|
|
|
Logged
|
|
|
|
Xaneth
Trekkie

Offline
Posts: 19
|
 |
« Reply #83 on: October 14, 2007, 02:05:21 PM » |
|
so, i got the script to email me a backup of all my sql databases, but here's a dumb question, if the time comes, how do i restore my databases from this zip file?
To restore your DB, use phpMyAdmin to restore. Say you are using WAMP ( www.wampserver.com) installed locally and you want to restore. Open phpMyAdmin and create a database with the same name as the one you backed up. Go to the database and "import". Browse to your zip file and import it. If you are importing from a different version of mySQL, you may need to choose that version under "SQL compatibility mode". One thing I found also when restoring my Joomla site locally as well was this. I restored all the databases I had, as well as the file structure. I then had to edit the configuration.php file to point to the right local folders. I also had to edit my local "hosts" file to make sure that my site, www.soldotnahighschool.com, pointed to 127.0.0.1 and/or my local IP address (i.e. 192.168.0.x). Without doing this, the site would come up, but the theme was broken, and links went to the real website, not locally. Just wanted to share my experience.
|
|
|
|
|
Logged
|
|
|
|
Xaneth
Trekkie

Offline
Posts: 19
|
 |
« Reply #84 on: October 14, 2007, 02:09:43 PM » |
|
After turning PASV mode off and reducing the file size, the script uploaded foo.tar.gz to my server, but failed again and just disconnected, without much in the way of an error. The email I get is: Connected to ftp.server.com, for user <ftp user><br /> <b>Warning</b>: ftp_put() [<a href='function.ftp-put'>function.ftp-put</a>]: Opening data connection for foo.tar.gz. in <b>/home/<cpanel account>/sohi.php</b> on line <b>42</b><br /> FTP upload has failed.
Anywhere else I can look for more information about what's happening? It uploaded about 300 Mb of the file and just disconnected.
|
|
|
|
|
Logged
|
|
|
|
Xaneth
Trekkie

Offline
Posts: 19
|
 |
« Reply #85 on: October 14, 2007, 04:53:21 PM » |
|
I guess if all else fails, I can script something from my FTP server to log in and grab the backup and delete it when it's done, but it would be nice to get the script working. Going to try a more complete php.ini file and see if it helps.
|
|
|
|
|
Logged
|
|
|
|
Xaneth
Trekkie

Offline
Posts: 19
|
 |
« Reply #86 on: October 21, 2007, 04:22:31 PM » |
|
The backup script has been working daily, however it downloads the file foo.tar.gz and overwrites it daily I'm assuming at this line: // upload the file $upload = ftp_put($ftp_conn, "foo.tar.gz", $filename, FTP_BINARY);
If I remove "foo.tar.gz" from the line, the script fails with: <b>Warning</b>: ftp_put() expects at least 4 parameters, 3 given in <b>/home/<cpanel username>/sohi.php</b> on line <b>42</b><br /> FTP upload has failed.
Question is, how do I get it to upload $filename instead?
|
|
|
|
|
Logged
|
|
|
|
|
lunpcdm
|
 |
« Reply #87 on: November 05, 2007, 02:40:39 PM » |
|
Hi there. Today i try to run the Site Backup via Cron (the first one at the first page of this topic) and the following error comes up. Connected to ftp.mysitename.com, for user myusernameFTP upload has failed. Warning: unlink(/home/myusername/public_html/Full_Account_Backup-2007-11-05_08-57-15.tar.gz) [function.unlink]: No such file or directory in /home/myusername/public_html/nameofthescript.php on line 56  please 
|
|
|
|
|
Logged
|
|
|
|
|
lunpcdm
|
 |
« Reply #88 on: November 13, 2007, 02:05:43 AM » |
|
Good morning. After we have scramble to manage this issue with LP i come buck to announce my new problems with this script. I am trying to use Site Backup via Cron. The code i use is the following <? $datestamp = date("Y-m-d_H-i-s"); // Current date to append to filename of backup file in format of YYYY-MM-DD
/* CONFIGURE THE FOLLOWING VARIABLES TO MATCH YOUR SETUP */ $filename= "Full_Account_Backup-$datestamp.tar"; // The name (and optionally path) of the dump file $ftp_server = "my_domain_name.com"; // Name or IP. Shouldn't have any trailing slashes and shouldn't be prefixed with ftp:// $ftp_port = "21"; // FTP port - blank defaults to port 21 $ftp_username = "my_username"; // FTP account username $ftp_password = "my_password"; // FTP account password - blank for anonymous $filename = "/home/my_account_name/public_html/" . $filename . ".gz";
$command = "tar cvf ~/$filename ~/sopa/*"; $result = exec($command);
$command = "gzip -9 -S .gz ~/$filename"; $result = exec($command);
// set up basic connection $ftp_conn = ftp_connect($ftp_server);
// Turn PASV mode on or off
ftp_pasv($ftp_conn, false);
// login with username and password $login_result = ftp_login($ftp_conn, $ftp_username, $ftp_password);
// check connection if ((!$ftp_conn) || (!$login_result)) { echo "FTP connection has failed."; echo "Attempted to connect to $ftp_server for user $ftp_username"; exit; } else { echo "Connected to $ftp_server, for user $ftp_username"; }
// upload the file $upload = ftp_put($ftp_conn, $filename, $filename, FTP_BINARY);
// check upload status if (!$upload) { echo "FTP upload has failed."; } else { echo "Uploaded $filename to $ftp_server."; }
// close the FTP stream ftp_close($ftp_conn);
unlink($filename); //delete the backup file from the server ?> The advice of LP was: The cron should indeed read: php -q /home/my_username/public_html/name_of_the_script.php You would need to ensure the absolute path to the file is specified when running a cron. It appears the cause of the issue is that the backup file is not created by the script so the FTP upload and the unlink command both fail (since the information they are passed is not valid). The error on the page indicates that the backup file is not being created: http://www.my_domain_name.com/name_of_the_script.php----- Connected to my_domain_name.com, for user my_username Warning: ftp_put() [function.ftp-put]: Rename/move failure: No such file or directory in /home/my_username/public_html/name_of_the_script.php on line 41 FTP upload has failed. Do you have any advice to provide me please? i will also pm scanman20. Thanks guys.
|
|
|
|
|
Logged
|
|
|
|
mefromla
Trekkie

Offline
Posts: 11
|
 |
« Reply #89 on: November 26, 2007, 09:49:05 AM » |
|
Hi Danielle, Scanman, others
I just joined this backup club. How can I backup my site but not entirely? I want to exclude couple subdirectories that contain media files. Where should I make changes to the script?
Thanks
|
|
|
|
|
Logged
|
|
|
|
|