Skip to content

Instantly share code, notes, and snippets.

@aabidos
Created June 27, 2014 22:07
Show Gist options
  • Select an option

  • Save aabidos/6e9ba01422969123b978 to your computer and use it in GitHub Desktop.

Select an option

Save aabidos/6e9ba01422969123b978 to your computer and use it in GitHub Desktop.
PHP (large) DB backup
<?php
$DBHOST="host";
$DBUSER="user";
$DBPASSWD="pass";
$DATABASE="db";
$filename = "backup-" . date("d-m-Y") . ".sql.gz";
$mime = "application/x-gzip";
header( "Content-Type: " . $mime );
header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
$cmd = "mysqldump --single-transaction --host=$DBHOST -u $DBUSER --password=$DBPASSWD $DATABASE | gzip --best";
passthru( $cmd )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment