zoukankan      html  css  js  c++  java
  • lnmp php使用命令行去备份数据库

    <?php 
        //备份数据库we8和foshan
        $time = date("Y-m-d",time());
        $backtime = date("Y-m-d",strtotime("-5 day"));
        $exec="mysqldump -h localhost -uroot -pXiaozuanfeng --default-character-set=utf8 we8 > /var/www/backsql/we8".$time.".sql";//we8数据库
        exec($exec, $result, $status);//命令行执行
        $exec2="mysqldump -h localhost -uroot -pXiaozuanfeng --default-character-set=utf8 foshan > /var/www/backsql/foshan".$time.".sql";//foshan数据库
        exec($exec2, $result2, $status2);
        echo "<pre>";
        header("Content-type: text/html; charset=utf-8");
        if( $status ){
            echo "shell命令{$exec}执行失败";
        } else {
            //删除5天前的SQL文件
            // unlink("/var/www/backsql/we8".$backtime.".sql");
            //file_exists:文件是否存在
            $file = "/var/www/backsql/we8".$backtime.".sql";
            if(file_exists($file))
            {
                echo "当前目录中,文件".$file."存在,现在删除";
                //删除5天前的SQL文件
                unlink($file);
            }
            else
            {
                 echo "当前目录中,文件".$file."不存在";
            }
            echo "shell命令{$exec}成功执行, 结果如下<hr>";
            print_r( $result );
        }
    
        if( $status2 ){
            echo "shell命令{$exec2}执行失败";
        } else {
            //删除5天前的SQL文件
            //file_exists:文件是否存在
            $file2 = "/var/www/backsql/foshan".$backtime.".sql";
            if(file_exists($file2))
            {
                echo "当前目录中,文件".$file2."存在,现在删除";
                //删除5天前的SQL文件
                unlink($file2);
            }
            else
            {
                 echo "当前目录中,文件".$file2."不存在";
            }
            echo "shell命令{$exec2}成功执行, 结果如下<hr>";
            print_r( $result2 );
        }
  • 相关阅读:
    DGA域名可以是色情网站域名
    使用cloudflare加速你的网站隐藏你的网站IP
    167. Two Sum II
    leetcode 563. Binary Tree Tilt
    python 多线程
    leetcode 404. Sum of Left Leaves
    leetcode 100. Same Tree
    leetcode 383. Ransom Note
    leetcode 122. Best Time to Buy and Sell Stock II
    天津Uber优步司机奖励政策(12月28日到12月29日)
  • 原文地址:https://www.cnblogs.com/lvtiansong/p/9373306.html
Copyright © 2011-2022 走看看