cron job for backup the database in linux/php

后端 未结 5 1681
独厮守ぢ
独厮守ぢ 2021-02-10 22:02

Am new to linux cron job, i am using mysql DB, my database name finaldb, i want to take this database every one hour,

I have folder called dailbackup, in this i have fol

5条回答
  •  囚心锁ツ
    2021-02-10 22:54

    Create a PHP Script containing the following:

    $dbFile = 'final_db'.date('H').'.sql.gz';
    $dbHost = 'localhost'; // Database Host
    $dbUser = 'username'; // Database Username
    $dbPass = 'password'; // Database Password
    exec( 'mysqldump --host="'.$dbHost.'" --user="'.$dbUser.'" --password="'.$dbPass.'" --add-drop-table "finaldb" | gzip > "'.$dbFile.'"' );
    

提交回复
热议问题