24
24
# Christoph Haunschmidt 2016-03
25
25
26
26
import argparse
27
+ import datetime
27
28
import os
28
29
import re
29
30
import sys
30
- import datetime
31
31
32
32
import grab
33
33
34
-
35
34
__version__ = '2016-03-12.3'
36
35
37
36
CONTENT_DISPOSITION_FILENAME_RE = re .compile (r'^.*filename="(?P<filename>[^"]+)".*$' )
40
39
41
40
def download_sql_backup (url , user , password , dry_run = False , overwrite_existing = False , prepend_date = True , basename = None ,
42
41
output_directory = os .getcwd (), exclude_dbs = None , compression = 'none' , prefix_format = None ,
43
- timeout = 60 , http_auth = None , ** kwargs ):
42
+ timeout = 60 , http_auth = None ):
44
43
prefix_format = prefix_format or DEFAULT_PREFIX_FORMAT
45
44
exclude_dbs = exclude_dbs .split (',' ) or []
46
45
encoding = '' if compression == 'gzip' else 'gzip'
@@ -65,7 +64,7 @@ def download_sql_backup(url, user, password, dry_run=False, overwrite_existing=F
65
64
dbs_to_dump = [db_name for db_name in dbs_available if db_name not in exclude_dbs ]
66
65
if not dbs_to_dump :
67
66
print ('Warning: no databases to dump (databases available: "{}")' .format ('", "' .join (dbs_available )),
68
- file = sys .stderr )
67
+ file = sys .stderr )
69
68
70
69
file_response = g .submit (
71
70
extra_post = [('db_select[]' , db_name ) for db_name in dbs_to_dump ] + [('compression' , compression )])
@@ -108,27 +107,28 @@ def download_sql_backup(url, user, password, dry_run=False, overwrite_existing=F
108
107
parser .add_argument ('user' , metavar = 'USERNAME' , help = 'phpMyAdmin login username' )
109
108
parser .add_argument ('password' , metavar = 'PASSWORD' , help = 'phpMyAdmin login password' )
110
109
parser .add_argument ('-o' , '--output-directory' , default = os .getcwd (),
111
- help = 'output directory for the SQL dump file (default: the current working directory)' )
110
+ help = 'output directory for the SQL dump file (default: the current working directory)' )
112
111
parser .add_argument ('-p' , '--prepend-date' , action = 'store_true' , default = False ,
113
- help = 'prepend current UTC date & time to the filename; see the --prefix-format option for custom formatting' )
112
+ help = 'prepend current UTC date & time to the filename; see the --prefix-format option for custom formatting' )
114
113
parser .add_argument ('-e' , '--exclude-dbs' , default = '' ,
115
- help = 'comma-separated list of database names to exclude from the dump' )
114
+ help = 'comma-separated list of database names to exclude from the dump' )
116
115
parser .add_argument ('--compression' , default = 'none' , choices = ['none' , 'zip' , 'gzip' , 'bzip2' ],
117
- help = 'compression method for the output file - must be supported by the server (default: %(default)s)' )
116
+ help = 'compression method for the output file - must be supported by the server (default: %(default)s)' )
118
117
parser .add_argument ('--basename' , default = None ,
119
- help = 'the desired basename (without extension) of the SQL dump file (default: the name given by phpMyAdmin); '
120
- 'you can also set an empty basename "" in combination with --prepend-date and --prefix-format' )
118
+ help = 'the desired basename (without extension) of the SQL dump file (default: the name given by phpMyAdmin); '
119
+ 'you can also set an empty basename "" in combination with --prepend-date and --prefix-format' )
121
120
parser .add_argument ('--timeout' , type = int , default = 60 ,
122
- help = 'timeout in seconds for the requests (default: %(default)s)' )
121
+ help = 'timeout in seconds for the requests (default: %(default)s)' )
123
122
parser .add_argument ('--overwrite-existing' , action = 'store_true' , default = False ,
124
- help = 'overwrite existing SQL dump files (instead of appending a number to the name)' )
123
+ help = 'overwrite existing SQL dump files (instead of appending a number to the name)' )
125
124
parser .add_argument ('--prefix-format' , default = '' ,
126
- help = str ('the prefix format for --prepend-date (default: "{}"); in Python\' s strftime format. '
127
- 'Must be used with --prepend-date to be in effect' .format (DEFAULT_PREFIX_FORMAT .replace ('%' , '%%' ))))
125
+ help = str ('the prefix format for --prepend-date (default: "{}"); in Python\' s strftime format. '
126
+ 'Must be used with --prepend-date to be in effect' .format (
127
+ DEFAULT_PREFIX_FORMAT .replace ('%' , '%%' ))))
128
128
parser .add_argument ('--dry-run' , action = 'store_true' , default = False ,
129
- help = 'dry run, do not actually download any file' )
129
+ help = 'dry run, do not actually download any file' )
130
130
parser .add_argument ('--http-auth' , default = None ,
131
- help = 'Basic http authentication, using format "username:password"' )
131
+ help = 'Basic http authentication, using format "username:password"' )
132
132
133
133
args = parser .parse_args ()
134
134
@@ -143,4 +143,4 @@ def download_sql_backup(url, user, password, dry_run=False, overwrite_existing=F
143
143
sys .exit (1 )
144
144
145
145
print ('{} saved SQL dump to: {}' .format (('Would have' if args .dry_run else 'Successfully' ), dump_fn ),
146
- file = sys .stdout )
146
+ file = sys .stdout )
0 commit comments