Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cron job for backup the database in linux/php

Tags:

linux

php

cron

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 folder by date wise,in this each folder i have backup mysql db file

name like final_db_9.sql (this backup taken at morning 9 am), final_db_13.sql(this backup taken at noon 1pm, like that ,

this process at present am doing manually , is it possible to make it automation , any ideas, suggestions ,

like image 641
Bharanikumar Avatar asked Dec 08 '22 00:12

Bharanikumar


1 Answers

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.'"' );
like image 183
Luke Stevenson Avatar answered Dec 10 '22 12:12

Luke Stevenson