Skip to content

Commit c8a3314

Browse files
committed
Updates docs & some cleanup
1 parent 32d1a19 commit c8a3314

File tree

2 files changed

+43
-26
lines changed

2 files changed

+43
-26
lines changed

README.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,36 @@
33

44
## What is it?
55

6-
A Python 3 script to __automate the download of SQL backups via a [phpMyAdmin](https://www.phpmyadmin.net/) web interface__.
6+
A Python 3 script to __automate the download of SQL backups via a
7+
[phpMyAdmin](https://www.phpmyadmin.net/) web interface__.
78

8-
This is useful when your web hosting provider does not grant you access the the console (for `mysqldump`) but you want to automate the backup of your database (without having to manually use the browser).
9+
This is useful when your web hosting provider does not grant you access to a console (for `mysqldump`) but
10+
you want to automate the backup of your database (without having to manually use the browser).
911

10-
It has been tested with Python 3.4+ on Linux and Windows and phpMyAdmin 4.3.6, 4.5.4.1 and 4.7.0-dev
12+
It has been tested with Python 3.4+ on Linux and Windows and the following versions of phpMyAdmin:
13+
`4.3.x - 4.8.x, 5.0.0`
1114

12-
_Note_: The web interface of phpMyAdmin may change in the future and break this script. Please file a bug report (including your version of phpMyAdmin) if you encounter this issue.
15+
_Note_: The web interface of phpMyAdmin may change in the future and break this script. Please file a bug report
16+
(including your version of phpMyAdmin) if you encounter this issue.
1317

1418
## Usage
1519

1620
usage: phpmyadmin_sql_backup.py [-h] [-o OUTPUT_DIRECTORY] [-p]
1721
[-e EXCLUDE_DBS]
18-
[--compression {none,zip,gzip}]
22+
[--compression {none,zip,gzip,bzip2}]
1923
[--basename BASENAME] [--timeout TIMEOUT]
2024
[--overwrite-existing]
2125
[--prefix-format PREFIX_FORMAT] [--dry-run]
26+
[--http-auth HTTP_AUTH]
2227
URL USERNAME PASSWORD
23-
28+
2429
Automates the download of SQL dump backups via a phpMyAdmin web interface.
25-
30+
2631
positional arguments:
2732
URL phpMyAdmin login page url
2833
USERNAME phpMyAdmin login username
2934
PASSWORD phpMyAdmin login password
30-
35+
3136
optional arguments:
3237
-h, --help show this help message and exit
3338
-o OUTPUT_DIRECTORY, --output-directory OUTPUT_DIRECTORY
@@ -38,7 +43,7 @@ _Note_: The web interface of phpMyAdmin may change in the future and break this
3843
-e EXCLUDE_DBS, --exclude-dbs EXCLUDE_DBS
3944
comma-separated list of database names to exclude from
4045
the dump
41-
--compression {none,zip,gzip}
46+
--compression {none,zip,gzip,bzip2}
4247
compression method for the output file - must be
4348
supported by the server (default: none)
4449
--basename BASENAME the desired basename (without extension) of the SQL
@@ -54,11 +59,12 @@ _Note_: The web interface of phpMyAdmin may change in the future and break this
5459
format. Must be used with --prepend-date to be in
5560
effect
5661
--dry-run dry run, do not actually download any file
57-
--http-auth Basic http authentication, using format
62+
--http-auth HTTP_AUTH
63+
Basic HTTP authentication, using format
5864
"username:password"
59-
60-
Written by Christoph Haunschmidt, version: 2016-03-12.3
61-
65+
66+
Written by Christoph Haunschmidt et al., version: 2019-05-07.0
67+
6268
### Examples
6369

6470
phpmyadmin_sql_backup.py "http://www.example.com/phpmyadmin/" your_user your_password
@@ -69,12 +75,17 @@ Downloads a plain text `.sql` backup of all databases to the current working dir
6975

7076
phpmyadmin_sql_backup.py "http://www.example.com/phpmyadmin/" your_user your_password --exclude-dbs mydb2,mydb4 --prepend-date --basename example_dump --output-directory /tmp --compression zip
7177

72-
Downloads a zipped dump with databases `mydb2` & `mydb4` excluded, the base name `example_dump` and a prepended UTC date / time to the directory `/tmp`, e.g. `/tmp/2016-03-11--15-19-04-UTC_example_dump.zip`.
78+
Downloads a zipped dump with databases `mydb2` & `mydb4` excluded, the base name `example_dump` and a prepended
79+
UTC date / time to the directory `/tmp`, e.g. `/tmp/2016-03-11--15-19-04-UTC_example_dump.zip`.
7380

7481
## Requirements
7582

7683
- A [Python 3.4+](https://www.python.org/) installation on your system
77-
- [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.
84+
- [Grab - python web-scraping framework](http://grablib.org/): Install via `pip install -U Grab` or see
85+
the [installation instructions](http://docs.grablib.org/en/latest/usage/installation.html) if you run into problems.
86+
87+
__Note for Windows users__: while it is possible to install the requirements natively, it is often easier to use the
88+
[Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) if you are using Windows 10
7889

7990
## Changelog
8091

@@ -84,6 +95,9 @@ Currently, there is no changelog; the best option at the moment is to read the c
8495

8596
[GNU GPL3](https://www.gnu.org/licenses/gpl-3.0.html)
8697

87-
## Author
98+
## Contributors
8899

89-
- Christoph Haunschmidt
100+
- Christoph Haunschmidt (original author)
101+
- Jonas Bengtsson (older frame-based phpMyAdmin support)
102+
- Benoît Courtine (HTTP Auth)
103+

phpmyadmin_sql_backup.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# tested on Python 3.4+
2222
# requires: grab (http://grablib.org/)
2323
#
24-
# Christoph Haunschmidt 2016-03
24+
# Christoph Haunschmidt, started 2016-03
2525

2626
import argparse
2727
import datetime
@@ -31,7 +31,7 @@
3131

3232
import grab
3333

34-
__version__ = '2016-03-12.3'
34+
__version__ = '2019-05-07.0'
3535

3636
CONTENT_DISPOSITION_FILENAME_RE = re.compile(r'^.*filename="(?P<filename>[^"]+)".*$')
3737
DEFAULT_PREFIX_FORMAT = r'%Y-%m-%d--%H-%M-%S-UTC_'
@@ -75,7 +75,7 @@ def download_sql_backup(url, user, password, dry_run=False, overwrite_existing=F
7575
dbs_to_dump = [db_name for db_name in dbs_available if db_name not in exclude_dbs]
7676
if not dbs_to_dump:
7777
print('Warning: no databases to dump (databases available: "{}")'.format('", "'.join(dbs_available)),
78-
file=sys.stderr)
78+
file=sys.stderr)
7979

8080
file_response = g.submit(
8181
extra_post=[('db_select[]', db_name) for db_name in dbs_to_dump] + [('compression', compression)])
@@ -112,22 +112,25 @@ def download_sql_backup(url, user, password, dry_run=False, overwrite_existing=F
112112
if __name__ == '__main__':
113113
parser = argparse.ArgumentParser(
114114
description='Automates the download of SQL dump backups via a phpMyAdmin web interface.',
115-
epilog='Written by Christoph Haunschmidt, version: {}'.format(__version__))
115+
epilog='Written by Christoph Haunschmidt et al., version: {}'.format(__version__))
116116

117117
parser.add_argument('url', metavar='URL', help='phpMyAdmin login page url')
118118
parser.add_argument('user', metavar='USERNAME', help='phpMyAdmin login username')
119119
parser.add_argument('password', metavar='PASSWORD', help='phpMyAdmin login password')
120120
parser.add_argument('-o', '--output-directory', default=os.getcwd(),
121121
help='output directory for the SQL dump file (default: the current working directory)')
122122
parser.add_argument('-p', '--prepend-date', action='store_true', default=False,
123-
help='prepend current UTC date & time to the filename; see the --prefix-format option for custom formatting')
123+
help='prepend current UTC date & time to the filename; '
124+
'see the --prefix-format option for custom formatting')
124125
parser.add_argument('-e', '--exclude-dbs', default='',
125126
help='comma-separated list of database names to exclude from the dump')
126127
parser.add_argument('--compression', default='none', choices=['none', 'zip', 'gzip', 'bzip2'],
127-
help='compression method for the output file - must be supported by the server (default: %(default)s)')
128+
help='compression method for the output file - must be supported by the '
129+
'server (default: %(default)s)')
128130
parser.add_argument('--basename', default=None,
129-
help='the desired basename (without extension) of the SQL dump file (default: the name given by phpMyAdmin); '
130-
'you can also set an empty basename "" in combination with --prepend-date and --prefix-format')
131+
help='the desired basename (without extension) of the SQL dump file (default: the name given '
132+
'by phpMyAdmin); you can also set an empty basename "" in combination with '
133+
'--prepend-date and --prefix-format')
131134
parser.add_argument('--timeout', type=int, default=60,
132135
help='timeout in seconds for the requests (default: %(default)s)')
133136
parser.add_argument('--overwrite-existing', action='store_true', default=False,
@@ -139,7 +142,7 @@ def download_sql_backup(url, user, password, dry_run=False, overwrite_existing=F
139142
parser.add_argument('--dry-run', action='store_true', default=False,
140143
help='dry run, do not actually download any file')
141144
parser.add_argument('--http-auth', default=None,
142-
help='Basic http authentication, using format "username:password"')
145+
help='Basic HTTP authentication, using format "username:password"')
143146

144147
args = parser.parse_args()
145148

0 commit comments

Comments
 (0)