Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 4 of 4

This is a discussion on database backup script not running properly... in the Shared & Semi-Dedicated forum
Hello everyone. . . I just had a quick question, l've had the following script running via CRON for the past several months, and w/out ...

  1. #1
    JPC Senior Member
    Join Date
    Nov 2003
    Posts
    73

    database backup script not running properly...

    Hello everyone. . .

    I just had a quick question, l've had the following script running via CRON for the past several months, and w/out altering anything about a week or two ago it quit working.

    The output errors that l get when the cron runs are 500 (i think) server time outs. I haven't changed anything and to be honest the database isn't that large, compared to some of the other sites with phpbbs running on them. Is there any good reason that any of you could come up with, why this script isn't running properly?
    Like l said, it was running fine for months straight, every 3 days, and then bang one day it just stopped. I've tried actually running the script from the web just myself, and l get the same result. After about 5 minutes of waiting, l just get timed out on the server.

    ~JSlime


    PHP Code:
    <?php
    /* Database Backup Utility 1.0 By Eric Rosebrock, [url]http://www.phpfreaks.com[/url]
    Written: July 7th, 2002 12:59 AM

    If running from shell, put this above the <?php  "#! /usr/bin/php -q"  without the quotes!!!

    This script is dedicated to "Salk". You know who you are :)

    This script runs a backup of your database that you define below. It then gzips the .sql file
    and emails it to you or ftp's the file to a location of your choice. 

    It is highly recommended that you leave gzip on to reduce the file size.

    You must chown the directory this script resides in to the same user or group your webserver runs
    in, or CHMOD it to writable. I do not recommend chmod 777 but it's a quick solution. If you can setup
    a cron, you can probably chown your directory! 

    IMPORTANT!!! I recommend that you run this outside of your
    web directory, unless you manually want to run this script. If you do upload it inside your web
    directory source tree, I would at least apply Apache access control on that directory. You don't 
    want people downloading your raw databases!

    This script is meant to be setup on a crontab and run on a weekly basis
    You will have to contact your system administrator to setup a cron tab for this script
    Here's an example crontab:

    0 0-23 * * * php /path/to/thisdirectory/dbsender.php > dev/null

    */


    $dbhost 'localhost';
    $dbuser 'my_user';
    $dbpass 'my_password';
    $dbname 'my_database';
    $use_gzip "yes";
    $remove_sql_file "yes";
    $remove_gzip_file "no";
    $savepath "/home/mine/BACKUPS"
    $send_email "yes";
    $to      "me@hotmail.com";
    $from    "database@mysite.com";
    $senddate date("j F Y");

    $subject "MySQL Database Backup - $senddate";
    $message "Your MySQL database has been backed up and is attached to this email";


    $use_ftp "no";
    $ftp_server "localhost";
    $ftp_user_name "ftp_username";
    $ftp_user_pass "ftp_password";
    $ftp_path "/";


        
    $date date("mdy-hia");
        
    $filename "$savepath/$dbname-$date.sql";    
        
    passthru("mysqldump --opt -h$dbhost -u$dbuser -p$dbpass $dbname >$filename");
        
        if(
    $use_gzip=="yes"){
            
    $zipline "tar -czf ".$dbname."-".$date."_sql.tar.gz $dbname-$date.sql";
            
    shell_exec($zipline);
        }
        if(
    $remove_sql_file=="yes"){
            
    exec("rm -r -f $filename");
        }
        
        if(
    $use_gzip=="yes"){
            
    $filename2 "$savepath/".$dbname."-".$date."_sql.tar.gz";
        } else {
            
    $filename2 "$savepath/$dbname-$date.sql";
        }
        
        
        if(
    $send_email == "yes" ){
            
    $fileatt_type filetype($filename2);
            
    $fileatt_name "".$dbname."-".$date."_sql.tar.gz";
            
            
    $headers "From: $from";
            
            
    // Read the file to be attached ('rb' = read binary)
            
    $file fopen($filename2,'rb');
            
    $data fread($file,filesize($filename2));
            
    fclose($file);
        
            
    // Generate a boundary string
            
    $semi_rand md5(time());
            
    $mime_boundary "==Multipart_Boundary_x{$semi_rand}x";
        
            
    // Add the headers for a file attachment
            
    $headers .= "\nMIME-Version: 1.0\n" ."Content-Type: multipart/mixed;\n" ." boundary=\"{$mime_boundary}\"";
        
            
    // Add a multipart boundary above the plain message
            
    $message "This is a multi-part message in MIME format.\n\n" ."--{$mime_boundary}\n" ."Content-Type: text/plain; charset=\"iso-8859-1\"\n" ."Content-Transfer-Encoding: 7bit\n\n" .
            
    $message "\n\n";
        
            
    // Base64 encode the file data
            
    $data chunk_split(base64_encode($data));
        
            
    // Add file attachment to the message
            
    $message .= "--{$mime_boundary}\n" ."Content-Type: {$fileatt_type};\n" ." name=\"{$fileatt_name}\"\n" ."Content-Disposition: attachment;\n" ." filename=\"{$fileatt_name}\"\n" ."Content-Transfer-Encoding: base64\n\n" .
            
    $data "\n\n" ."--{$mime_boundary}--\n";
        
            
    // Send the message
            
    $ok = @mail($to$subject$message$headers);
            if (
    $ok) {
                echo 
    "This message was generated automatically, and scripted by the GOD of all things internet,\r Joe \"da man\" Slime. \rGuess what!! Your database backup is now available for download. \rPlease visit: http://www.tdtcoalition.net/BACKUP/$fileatt_name \rto download your backup file as soon as possible, and update your records.\r The next backup is scheduled in 72 hours from now.\r\n";
            } else {
                echo 
    "<h4><center>Mail could not be sent. Sorry!</center></h4>";
            }
        }
        
        if(
    $use_ftp == "yes"){
            
    $ftpconnect "ncftpput -u $ftp_user_name -p $ftp_user_pass -d debsender_ftplog.log -e dbsender_ftplog2.log -a -E -V $ftp_server $ftp_path $filename2";
            
    shell_exec($ftpconnect);
            echo 
    "<h4><center>$filename2 Was created and uploaded to your FTP server!</center>";
        
        }
        
        if(
    $remove_gzip_file=="yes"){
            
    exec("rm -r -f $filename2");
        }

    ?>

  2. #2
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,775
    Heh! OMG! "Out of the mouth of babes"...

    Believe me, I'm NOT changing the subject here, but for the last week (or two) the 'server load' on 'my' server has been 'motorboating' up 'n' down like crazy. I have complained to 'tech support' about this situation several times. The 'pat' answer has been, the backup script is causing the problem, these are scheduled events, and we are watching it.

    Now, you are having problems with scheduled backups, just like JagPC...

    I think I'm spotting a trend here...
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL © 2010

  3. #3
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,306
    You jump to conclusions faster than a crack addict on a Big Mac.

  4. #4
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,775
    Quote Originally Posted by Ron
    You jump to conclusions faster than a crack addict on a Big Mac.
    Is this not a considered opinion, e.g. your conclusion?
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL © 2010

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •