Gist · 12 / URL: https://kallithea.nomadicista.nz/_admin/gists/12
Public Gist
PHP script for backing up mysql databases and emailing them to the owner.
Expires: Never
stuart - created 5 years and 9 months ago
added file: sqlbackup.php
sqlbackup.php
<?php
// Create the mysql backup file
// edit this section
$dbhost = "localhost"; // usually localhost
$dbuser = "yourusername";
$dbpass = "yourpassword";
$dbname = "yourdb";
$sendto = "Webmaster <webmaster@yourdomain.com>";
$sendfrom = "Automated Backup <backup@yourdomain.com>";
$sendsubject = "Daily Mysql Backup";
$bodyofemail = "Here is the daily backup.";
// don't need to edit below this section

$backupfile = $dbname . date("_d-m-Y") . '.sql.gz';
system("mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname | gzip > $backupfile");

// Mail the file
system("echo 'Your database backup '$backupfile' is attached to this email.' | mutt -a $backupfile -s 'forum db backup' -- webmaster@yourdomain.com");

// Delete the file from your server
unlink($backupfile);
?>