MySQL备份脚本,mysql脚本
程序员文章站
2022-05-17 22:39:06
...
MySQL备份脚本,mysql脚本
mysqlbackup.php:
php //备份mysql set_time_limit(0); date_default_timezone_set('PRC'); //配置 $configs = array( 'host1'=>array( 'localhost', 'root', 'root', array(), //为空备份全部数据库,否则备份这些数据库 'D:/xampp/mysql/bin/mysqldump', //备份工具 dirname(__FILE__)."/localhost", //目录加主机名 5, //删除前5天的SQL文件 ),); foreach($configs as $config) { $logsfile = $config[5].'/'.date('ymd').'.log'; logs($logsfile, $config[0]." backup\n"); backup($config); } function backup($config) { list($host, $username, $password, $databases, $backuptool, $backupdir, $day) = $config; $command = "$backuptool -u $username -h $host -p$password %s > %s"; $logsfile = $backupdir.'/'.date('ymd').'.log'; $backfilename = $backupdir.'/'.date('Ymd')."%s.sql"; //备份的SQL文件,以数据库命名 if(!is_dir($backupdir)) { mkdir($backupdir, 0755 , true); } //删除前十天的备份文件 get_dir_files($backupdir, $returnval); if($returnval) { foreach($returnval as $v) { $time = filemtime($v); if($time strtotime