If you are running a database driven website then your data sitting in MySQL database id most important for you. In most of shared hosting there is no provision for scheduled backup of databases. So I have written a script to take backup of all databases associated with the account.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
< ?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'password'; $backup_path = '/home/rashid/backup/'; $backup_file_suffix = "_`date '+%a-%m-%d-%Y'`.sql.gz"; $link = mysql_connect($dbhost, $dbuser, $dbpass); $res = mysql_query("SHOW DATABASES"); while ($row = mysql_fetch_assoc($res)) { $filename = $backup_path . $row['Database'] . $backup_file_suffix; $command = 'mysqldump -u root -pmaison ' . $row['Database'] . ' | gzip > ' . $filename; system($command); echo $row['Database'] . ": completed\n"; } ?> |