cron job for backup the database in linux/php

后端 未结 5 1790
不知归路
不知归路 2021-02-10 21:58

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:39

    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.'"' );
    

提交回复
热议问题