This morning I rewrote BuDb (Backs-up Databases). BuDb is a bash script for backing up MySQL databases using mysqldump and gzip. It's primary benefit is that it names and stores the files such that it is easy to determine their history.
BuDb runs mysqldump --all-databases and pipes the output to gzip. The resulting file is stored as follows: ~/budb/YYYY/MM/DD/HOSTNAME-mysql-all-databases.YYYYMMDDmmSS.sql.gz.
Options
Options can be set or declared via flag/argument pairings when calling the script from a bash terminal, or they can be set using one or more config files. BuDb will first attempt load the file /etc/budb.conf. It will then try to load the file ~/.budb/profile, overloading any arguments from /etc/budb.conf in the event of a conflict. Values set via option flags override any configuration file values.
- -u
- budbDBUser
- Database username (required).
- -p
- budbDBPass
- Database user's password.
- -d
- budbBackupDir
- Directory in which to store the backup files.
- -v
- Verbose mode enable mysqldump.
- -h
- Help information display.
Example Config
At this time there is no installer or process to automate the generation of config files. If there were, a config file would look something like this
# The name of the database user. budbDBUser=someuser # Database user's password. #budbDBPass=password # Full path to the backup directory (no trailing slash). budbBackupDir=/mysqlbackups # Enable verbose mode. #budbVerbose=TRUE
Exercise caution if you choose to store the database password in a config file. On a production server it might be best to create a budb database user with very limited privileges, or at least set the config file to be unreadable to anyone but the owner.
Installation
Download budb, remove the ".txt" extension, place the file somewhere in your PATH, and make it executable. This script should work on most *nix systems. If you decide to use it, drop me a line and let me know how it worked out.
| Attachment | Size |
|---|---|
| budb.txt | 4.07 KB |
