Jump to content

Moved hosters PHP was 5.x now 7.x PHP scripts no longer work.


Recommended Posts

I had to move hosters recently and I have a couple of scripts run using CRON to backup my MySql database and manage the number of backups that I keep.  I can ask the hosters to deprecate the version of PHO backwards but I don't want to lose the opportunity of features that may be available in the new version.  The main script essentially performs a MySqlDump to a specified directory and then emails me to tell me that it completed successfully.  The second script just deletes any files in the backup folder more than x days old.

I know mysqldump is a valid call so I should need to use anything other than that but I'm lost when it comes to seeing what is wrong with my scripts.

backup.php

<?
$datestamp = date("Y-m-d");      // Current date to append to filename of backup file in format of YYYY-MM-DD
                                 // run the command php -q /home/mysite/public_html/scripts/ffbackup.php

/* CONFIGURE THE FOLLOWING SEVEN VARIABLES TO MATCH YOUR SETUP */
//    require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
    require("/home/mysite/config/db_config.php");
    $connection = mysql_connect($db_host, $db_user, $db_password);
    mysql_select_db($db_name, $connection);

//$dbuser = $db_user, $conection ;            // Database username
//$dbpwd = ($db_password, $conection);            // Database password
//$dbname = ($db_name, connection);            // Database name. Use --all-databases if you have more than one
$backdir ="/home/mysite/forumbackup/";
$filename= "backup-$datestamp.sql.gz";   // The name (and optionally path) of the dump file
$to = "my-email@address.com";      // Email address to send dump file to
$from = "admin@mysite.com";      // Email address message will show as coming from.
$subject = "Mysite MySQL backup file-$datestamp";      // Subject of email

$command = "mysqldump -u $db_user --password=$db_password $db_name | gzip > $filename";
$result = passthru($command);
$newfile = $filename;

copy ($filename, $backdir.$newfile);


$message = "Compressed database backup file $filename copied to backup directory.";
$headers = "From: $from\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


mail($to, $subject, $message, $headers);

unlink($filename);   //delete the backup file from the server
?>

 

and delold.php

<?php
$path = "/home/mysite/forumbackup/";

//echo "script is running";
//echo "the path is $path ";

      if (is_dir("$path") )
        {
           $handle=opendir($path);
           while (false!==($file = readdir($handle))) {
               if ($file != "." && $file != "..") { 
                   $Diff = (time() - filectime("$path/$file"))/60/60/24;
                   if ($Diff > 10) unlink("$path/$file");

               }
           }
           closedir($handle);
   }
?>

 

Oh dear, I'll just do it manually I think, trying to learn yet another new code just isn't worth the hassle, I mean it may all just change again next year.  I hate it when things aren't backward compatible.  Thanks anyway. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.