Skip to content

Commit f08b713

Browse files
committed
Added possibility to provide an empty basename: --basename ""
1 parent 007c706 commit f08b713

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ _Note_: The web interface of phpMyAdmin may change in the future and break this
4242
compression method for the output file - must be
4343
supported by the server (default: none)
4444
--basename BASENAME the desired basename (without extension) of the SQL
45-
dump file (default: the name given by phpMyAdmin)
45+
dump file (default: the name given by phpMyAdmin); you
46+
can also set an empty basename "" in combination with
47+
--prepend-date and --prefix-format
4648
--timeout TIMEOUT timeout in seconds for the requests (default: 60)
4749
--overwrite-existing overwrite existing SQL dump files (instead of
4850
appending a number to the name)
@@ -53,7 +55,7 @@ _Note_: The web interface of phpMyAdmin may change in the future and break this
5355
effect
5456
--dry-run dry run, do not actually download any file
5557

56-
Written by Christoph Haunschmidt, version: 2016-03-12.0
58+
Written by Christoph Haunschmidt, version: 2016-03-12.3
5759

5860
### Examples
5961

@@ -69,6 +71,7 @@ Downloads a zipped dump with databases `mydb2` & `mydb4` excluded, the base name
6971

7072
## Requirements
7173

74+
- A [Python 3.4+](https://www.python.org/) installation on your system
7275
- [Grab - python web-scraping framework](http://grablib.org/): Install via `pip install -U Grab` or see the [installation instructions](http://docs.grablib.org/en/latest/usage/installation.html) if you run into problems.
7376

7477
## Changelog

phpmyadmin_sql_backup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
import grab
3333

3434

35-
__version__ = '2016-03-12.2'
35+
__version__ = '2016-03-12.3'
3636

3737
CONTENT_DISPOSITION_FILENAME_RE = re.compile(r'^.*filename="(?P<filename>[^"]+)".*$')
3838
DEFAULT_PREFIX_FORMAT = r'%Y-%m-%d--%H-%M-%S-UTC_'
3939

4040

41-
def download_sql_backup(url, user, password, dry_run=False, overwrite_existing=False, prepend_date=True, basename='',
41+
def download_sql_backup(url, user, password, dry_run=False, overwrite_existing=False, prepend_date=True, basename=None,
4242
output_directory=os.getcwd(), exclude_dbs=None, compression='none', prefix_format=None,
4343
timeout=60, **kwargs):
4444
prefix_format = prefix_format or DEFAULT_PREFIX_FORMAT
@@ -74,7 +74,7 @@ def download_sql_backup(url, user, password, dry_run=False, overwrite_existing=F
7474
'Could not determine SQL backup filename from {}'.format(g.response.headers['Content-Disposition']))
7575

7676
content_filename = re_match.group('filename')
77-
filename = content_filename if not basename else basename + os.path.splitext(content_filename)[1]
77+
filename = content_filename if basename is None else basename + os.path.splitext(content_filename)[1]
7878
if prepend_date:
7979
prefix = datetime.datetime.utcnow().strftime(prefix_format)
8080
filename = prefix + filename
@@ -113,8 +113,9 @@ def download_sql_backup(url, user, password, dry_run=False, overwrite_existing=F
113113
help='comma-separated list of database names to exclude from the dump')
114114
parser.add_argument('--compression', default='none', choices=['none', 'zip', 'gzip'],
115115
help='compression method for the output file - must be supported by the server (default: %(default)s)')
116-
parser.add_argument('--basename',
117-
help='the desired basename (without extension) of the SQL dump file (default: the name given by phpMyAdmin)')
116+
parser.add_argument('--basename', default=None,
117+
help='the desired basename (without extension) of the SQL dump file (default: the name given by phpMyAdmin); '
118+
'you can also set an empty basename "" in combination with --prepend-date and --prefix-format')
118119
parser.add_argument('--timeout', type=int, default=60,
119120
help='timeout in seconds for the requests (default: %(default)s)')
120121
parser.add_argument('--overwrite-existing', action='store_true', default=False,

0 commit comments

Comments
 (0)