Skip to content

Instantly share code, notes, and snippets.

@SleepWalker
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SleepWalker/776f3c72227d1985fcb0 to your computer and use it in GitHub Desktop.
Save SleepWalker/776f3c72227d1985fcb0 to your computer and use it in GitHub Desktop.
MYSQL Dump downloader
<?php
// thanks to: http://stackoverflow.com/a/19575620/2039203
$DBUSER="user";
$DBPASSWD="password";
$DATABASE="user_db";
$filename = $_SERVER['HTTP_HOST'] . "-" . date("d-m-Y") . ".sql.gz";
$mime = "application/x-gzip";
header( "Content-Type: " . $mime );
header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
$cmd = "mysqldump -u $DBUSER --password=$DBPASSWD $DATABASE | gzip --best";
passthru( $cmd );
exit(0);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment