Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Y-m-d in default export file #36

Merged
merged 3 commits into from Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions README.md
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
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