Skip to content

Commit

Permalink
Merge pull request #36 from wp-cli/ymd-export-file
Browse files Browse the repository at this point in the history
Include Y-m-d in default export file
  • Loading branch information
gitlost committed Aug 24, 2017
2 parents a359506 + 7700ecf commit 5159191
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ Runs `mysqldump` utility using `DB_HOST`, `DB_NAME`, `DB_USER` and
**OPTIONS**

[<file>]
The name of the SQL file to export. If '-', then outputs to STDOUT. If omitted, it will be '{dbname}.sql'.
The name of the SQL file to export. If '-', then outputs to STDOUT. If
omitted, it will be '{dbname}-{Y-m-d}-{random-hash}.sql'.

[--<field>=<value>]
Extra arguments to pass to mysqldump
Expand All @@ -271,31 +272,31 @@ Runs `mysqldump` utility using `DB_HOST`, `DB_NAME`, `DB_USER` and

# Export database with drop query included
$ wp db export --add-drop-table
Success: Exported to 'wordpress_dbase.sql'.
Success: Exported to 'wordpress_dbase-db72bb5.sql'.

# Export certain tables
$ wp db export --tables=wp_options,wp_users
Success: Exported to 'wordpress_dbase.sql'.
Success: Exported to 'wordpress_dbase-db72bb5.sql'.

# Export all tables matching a wildcard
$ wp db export --tables=$(wp db tables 'wp_user*' --format=csv)
Success: Exported to 'wordpress_dbase.sql'.
Success: Exported to 'wordpress_dbase-db72bb5.sql'.

# Export all tables matching prefix
$ wp db export --tables=$(wp db tables --all-tables-with-prefix --format=csv)
Success: Exported to 'wordpress_dbase.sql'.
Success: Exported to 'wordpress_dbase-db72bb5.sql'.

# Skip certain tables from the exported database
$ wp db export --exclude_tables=wp_options,wp_users
Success: Exported to 'wordpress_dbase.sql'.
Success: Exported to 'wordpress_dbase-db72bb5.sql'.

# Skip all tables matching a wildcard from the exported database
$ wp db export --exclude_tables=$(wp db tables 'wp_user*' --format=csv)
Success: Exported to 'wordpress_dbase.sql'.
Success: Exported to 'wordpress_dbase-db72bb5.sql'.

# Skip all tables matching prefix from the exported database
$ wp db export --exclude_tables=$(wp db tables --all-tables-with-prefix --format=csv)
Success: Exported to 'wordpress_dbase.sql'.
Success: Exported to 'wordpress_dbase-db72bb5.sql'.



Expand Down
19 changes: 10 additions & 9 deletions src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ public function query( $args, $assoc_args ) {
* ## OPTIONS
*
* [<file>]
* : The name of the SQL file to export. If '-', then outputs to STDOUT. If omitted, it will be '{dbname}.sql'.
* : The name of the SQL file to export. If '-', then outputs to STDOUT. If
* omitted, it will be '{dbname}-{Y-m-d}-{random-hash}.sql'.
*
* [--<field>=<value>]
* : Extra arguments to pass to mysqldump
Expand All @@ -275,31 +276,31 @@ public function query( $args, $assoc_args ) {
*
* # Export database with drop query included
* $ wp db export --add-drop-table
* Success: Exported to 'wordpress_dbase.sql'.
* Success: Exported to 'wordpress_dbase-db72bb5.sql'.
*
* # Export certain tables
* $ wp db export --tables=wp_options,wp_users
* Success: Exported to 'wordpress_dbase.sql'.
* Success: Exported to 'wordpress_dbase-db72bb5.sql'.
*
* # Export all tables matching a wildcard
* $ wp db export --tables=$(wp db tables 'wp_user*' --format=csv)
* Success: Exported to 'wordpress_dbase.sql'.
* Success: Exported to 'wordpress_dbase-db72bb5.sql'.
*
* # Export all tables matching prefix
* $ wp db export --tables=$(wp db tables --all-tables-with-prefix --format=csv)
* Success: Exported to 'wordpress_dbase.sql'.
* Success: Exported to 'wordpress_dbase-db72bb5.sql'.
*
* # Skip certain tables from the exported database
* $ wp db export --exclude_tables=wp_options,wp_users
* Success: Exported to 'wordpress_dbase.sql'.
* Success: Exported to 'wordpress_dbase-db72bb5.sql'.
*
* # Skip all tables matching a wildcard from the exported database
* $ wp db export --exclude_tables=$(wp db tables 'wp_user*' --format=csv)
* Success: Exported to 'wordpress_dbase.sql'.
* Success: Exported to 'wordpress_dbase-db72bb5.sql'.
*
* # Skip all tables matching prefix from the exported database
* $ wp db export --exclude_tables=$(wp db tables --all-tables-with-prefix --format=csv)
* Success: Exported to 'wordpress_dbase.sql'.
* Success: Exported to 'wordpress_dbase-db72bb5.sql'.
*
* @alias dump
*/
Expand All @@ -308,7 +309,7 @@ public function export( $args, $assoc_args ) {
$result_file = $args[0];
} else {
$hash = substr( md5( mt_rand() ), 0, 7 );
$result_file = sprintf( '%s-%s.sql', DB_NAME, $hash );;
$result_file = sprintf( '%s-%s-%s.sql', DB_NAME, date( 'Y-m-d' ), $hash );;
}
$stdout = ( '-' === $result_file );
$porcelain = \WP_CLI\Utils\get_flag_value( $assoc_args, 'porcelain' );
Expand Down

0 comments on commit 5159191

Please sign in to comment.