Nax Posted December 31, 2020 Share Posted December 31, 2020 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/311953-moved-hosters-php-was-5x-now-7x-php-scripts-no-longer-work/ Share on other sites More sharing options...
maxxd Posted December 31, 2020 Share Posted December 31, 2020 All the mysql_* functions were removed in 7.0. You'll need to rewrite the script entirely using either mysqli_* or PDO (recommended) in order for this to work. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311953-moved-hosters-php-was-5x-now-7x-php-scripts-no-longer-work/#findComment-1583561 Share on other sites More sharing options...
Nax Posted December 31, 2020 Author Share Posted December 31, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311953-moved-hosters-php-was-5x-now-7x-php-scripts-no-longer-work/#findComment-1583562 Share on other sites More sharing options...
mac_gyver Posted December 31, 2020 Share Posted December 31, 2020 there's no reason for the php code to even be making a database connection, unless it was testing if the database server is running and the connection credentials are valid, which it isn't doing. Quote Link to comment https://forums.phpfreaks.com/topic/311953-moved-hosters-php-was-5x-now-7x-php-scripts-no-longer-work/#findComment-1583564 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.