Skip to content

Instantly share code, notes, and snippets.

@robertobarlocci
Created July 2, 2017 11:08
Show Gist options
  • Save robertobarlocci/1cc55364891b025fda0db7142201c155 to your computer and use it in GitHub Desktop.
Save robertobarlocci/1cc55364891b025fda0db7142201c155 to your computer and use it in GitHub Desktop.
<?php
/*
* This script only works on linux.
*/
define('DB_HOST', 'localhost');
define('DB_NAME', 'databsename');
define('DB_USER', 'username');
define('DB_PASSWORD', 'password');
define('BACKUP_SAVE_TO', '/path/to/backup/folder'); // without trailing slash
$time = time();
$day = date('j', $time);
if ($day == 1) {
$date = date("H:i", $time);
} else {
$date = $day;
}
$backupFile = BACKUP_SAVE_TO . '/' . DB_NAME . '_' . $time . '.gz';
if (file_exists($backupFile)) {
unlink($backupFile);
}
$command = 'mysqldump --opt -h ' . DB_HOST . ' -u ' . DB_USER . ' -p\'' . DB_PASSWORD . '\' ' . DB_NAME . ' | gzip > ' . $backupFile;
system($command);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment