MySQL database backup script

Using the scripts

In another post i wrote two scripts which allow you comfortable to save and restore your disk under ubuntu (other linux probably will work too 😉 ). Now i give you similar scripts for your MySQL databases. I use the plain scripts from the WordPress Backups page and use python 3.1 again for shortness and readability of code.

Again the warning:
Don’t use them mindless, you could damage all your recent work or worse! I don’t take responsibility for the effects of this scripts, you use them on your own response!

You have to give the “db2file.py” a string with a description like this:

./db2file.py 'before installing the newest updates'

and it will create a packed file called:

001__17_5_2011__before_installing_the_newest_updates.bak.sql.bz2

with an automatic incremented number and the date.

To decompress the file use:

./file2db.py 001__17_5_2011__before_installing_the_newest_updates.bak.sql.bz2

You can define another database name and user by the -u and -d options, here are the help outputs:

Usage: db2file.py description_string

Options:
  -h, --help            show this help message and exit
  -u USER, --user=USER  database user name
  -d DATABASE, --database=DATABASE
                        database name
Usage: file2db.py filename

Options:
  -h, --help            show this help message and exit
  -u USER, --user=USER  database user name
  -d DATABASE, --database=DATABASE
                        database name

If you have ideas or hints on the scripts or even find them usefull, let me know it and write a comment.

Download

You can download them here:
db2file.py
file2db.py

If you have ideas or hints on the scripts or even find them usefull, let me know it and write a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *