Skip to content

Instantly share code, notes, and snippets.

@kshoufer
Created December 31, 2014 16:23
Show Gist options
  • Save kshoufer/94263de88392c052cdb7 to your computer and use it in GitHub Desktop.
Save kshoufer/94263de88392c052cdb7 to your computer and use it in GitHub Desktop.
Run a full backup of your database.
<?php
$dbhost = 'localhost';
$dbuser = 'username';
$dbpass = 'password';
$dbname = 'databasename';
$currentdir = dirname(__FILE__);
$backup_file = $currentdir . '/bkup_files/' . $dbname . date("Y-m-d-H-i-s") . '.sql';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p'$dbpass' $dbname > $backup_file";
exec($command);
$to = "you@yourdomain.com";
$from = "you@yourdomain.com";
$subject = 'Backup Ran Successfully!!';
$message = "<h2>The backup ran fine.</h2><p>Date: " . date('Y-m-d-H-i-s') . "</p>" . "<p>File Name: " . $dbname . date("Y-m-d-H-i-s") . ".sql" . "</p>" ;
$headers = "From: you@yourdomain.com\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
mail($to, $subject, $message, $headers);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment