Skip to content

Instantly share code, notes, and snippets.

@camaleaun
Last active June 27, 2018 13:10
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 camaleaun/b1531a96e3f44538823aceb6e8e65bd9 to your computer and use it in GitHub Desktop.
Save camaleaun/b1531a96e3f44538823aceb6e8e65bd9 to your computer and use it in GitHub Desktop.
Dump wp database by file
<?php
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', dirname( __FILE__ ) . '/' );
}
error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
if ( file_exists( ABSPATH . 'wp-config.php') ) {
require_once( ABSPATH . 'wp-config.php' );
}
header( 'Content-Type: application/x-gzip' );
header( 'Content-Disposition: attachment; filename="mysqldump.sql.gz"' );
$cmd = 'mysqldump -u %s -h %s --password=%s %s | gzip --best';
$cmd = sprintf( $cmd, DB_USER, DB_HOST, DB_PASSWORD, DB_NAME );
passthru( $cmd );
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment