Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2007
    Posts
    23
    Plugin Contributions
    0

    Default Cron backup help

    Hi guys, hope this is the right place to post this....

    I am relatively new to ZC and cronjobs too, and php for that matter. I found a nice php script that compresses the database files and emails them to a specified address. I have uploaded the script and it works by typing the URL path of the script into a browser - the script is then executed and I receive a backup file to the email address I specified.

    The problem is when I setup a cronjob through my hosts cPanel - the cronjob goes off at 3am everymorning but it returns an error:

    Code:
    /home/noahsark/public_html/directory/email_backup.php: line 1: ?: No such file or directory
    /home/noahsark/public_html/directory/email_backup.php: line 2: syntax error near unexpected token `('
    /home/noahsark/public_html/directory/email_backup.php: line 2: `$datestamp = date("Y-m-d");      // Current date to append to filename of backup file in format of YYYY-MM-DD'
    it can obviously see the script file as it is quoting particular lines but I don't know why it wont work, can anyone shed any light for me? (the file has permissions set to 755 as specified where I got the script from).



    here is the script:

    Code:
    <?
    $datestamp = date("Y-m-d");      // Current date to append to filename of backup file in format of YYYY-MM-DD
    
    /* CONFIGURE THE FOLLOWING SEVEN VARIABLES TO MATCH YOUR SETUP */
    $dbuser = "username";            // Database username
    $dbpwd = "password";            // Database password
    $dbname = "--all-databases";            // Database name. Use --all-databases if you have more than one
    $filename= "backup_noahsark_all_databases-$datestamp.sql.gz";   // The name (and optionally path) of the dump file
    $to = "[email protected]";      // Email address to send dump file to
    $from = "[email protected]";      // Email address message will show as coming from.
    $subject = "MySQL backup file";      // Subject of email
    
    $command = "mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename";
    $result = passthru($command);
    
    $attachmentname = array_pop(explode("/", $filename));   // If a path was included, strip it out for the attachment name
    
    $message = "Compressed database backup file $attachmentname attached.";
    $mime_boundary = "<<<:" . md5(time());
    $data = chunk_split(base64_encode(implode("", file($filename))));
    
    $headers = "From: $from\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: multipart/mixed;\r\n";
    $headers .= " boundary=\"".$mime_boundary."\"\r\n";
    
    $content = "This is a multi-part message in MIME format.\r\n\r\n";
    $content.= "--".$mime_boundary."\r\n";
    $content.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
    $content.= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $content.= $message."\r\n";
    $content.= "--".$mime_boundary."\r\n";
    $content.= "Content-Disposition: attachment;\r\n";
    $content.= "Content-Type: application/x-gzip; name=\"$attachmentname\"\r\n";
    $content.= "Content-Transfer-Encoding: base64\r\n\r\n";
    $content.= $data."\r\n";
    $content.= "--" . $mime_boundary . "\r\n";
    
    mail($to, $subject, $content, $headers);
    
    unlink($filename);   //delete the backup file from the server
    ?>

  2. #2
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: Cron backup help

    You probably can't run the PHP file directly.
    Try prefixing it with the path to the php binary so that it knows to treat the script as a php file.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    May 2006
    Location
    Texas
    Posts
    565
    Plugin Contributions
    4

    Default Re: Cron backup help

    I have the same script on my server.. i use the following command:

    php -f '/path/to/script'

    and run it every 15 minutes. Yes.. it may seem like overkill.. but i would rather have a backup of 10 minutes ago than 10 hours ago if for some reason my site was to go down

  4. #4
    Join Date
    Feb 2007
    Posts
    23
    Plugin Contributions
    0

    Default Re: Cron backup help

    ah, mine didn't have the ''s in... I'll try that. or did you use them for illustrative purposes... ?

  5. #5
    Join Date
    Feb 2007
    Posts
    23
    Plugin Contributions
    0

    Default Re: Cron backup help

    thanks samad64, that got it working, was pulling my hair out there trying to get it working, so many thanks!

  6. #6
    Join Date
    May 2006
    Location
    Texas
    Posts
    565
    Plugin Contributions
    4

    Default Re: Cron backup help

    Quote Originally Posted by arumdevil View Post
    thanks samad64, that got it working, was pulling my hair out there trying to get it working, so many thanks!
    no problem :)

  7. #7
    Join Date
    Apr 2007
    Posts
    20
    Plugin Contributions
    0

    Default Re: Cron backup help

    Quote Originally Posted by arumdevil View Post
    thanks samad64, that got it working, was pulling my hair out there trying to get it working, so many thanks!
    I am using the same script but it can't access the database. Where did you put the script on your host?

  8. #8
    Join Date
    Feb 2007
    Posts
    23
    Plugin Contributions
    0

    Default Re: Cron backup help

    php -f '/home/yourserver/public_html/folder/email_backup.php' > /dev/null

    that is the command I have, it is in a folder of the public folder of my site, but really you should have it above the public_html folder so others can't get to it......

  9. #9
    Join Date
    Apr 2007
    Posts
    20
    Plugin Contributions
    0

    Default Re: Cron backup help

    Thanks for your help...
    I had a typo in the database username so that's why it didn't work.
    Also I moved the script from public folder, along with the currencyupdate script to above public_html for security. Both scripts are working fine. Currencies and Backup update on the hour every hour. Wonderful!

 

 

Similar Threads

  1. Cron Jobs Help Need
    By LittleAngell52 in forum General Questions
    Replies: 5
    Last Post: 29 Jun 2016, 10:38 AM
  2. Can I run Backup MYSQL Plugin v1.4 via cron job?
    By Renz in forum General Questions
    Replies: 2
    Last Post: 23 Mar 2012, 06:25 AM
  3. CRON job help
    By Jeff G in forum General Questions
    Replies: 10
    Last Post: 9 Oct 2008, 12:20 AM
  4. Cron script help for demo page please.
    By oavs in forum General Questions
    Replies: 0
    Last Post: 23 Apr 2008, 02:19 AM
  5. Automated Backup via CRON ??
    By Netsmurf in forum General Questions
    Replies: 4
    Last Post: 14 May 2007, 06:05 PM

Posting Permissions

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