Home

dbbu

dbbu is a simple Python module to assist with remote database backups. It's designed to be used in conjunction with rsnapshot as a backup_script parameter, but can run standalone as well.

Supported Databases: PostgreSQL, MySQL

This has pretty limited use and is still a work in progress!

Installation and Basic Use

$ hg clone http://bitbucket.org/copelco/dbbu/
$ python dbbu/setup.py install
$ dbbu-run.py dbbu.cfg

rsnapshot Configuration

To use dbbu with rsnapshot, add a backup_script parameter like so:

backup_script    dbbu-run.py /etc/dbbu.cfg    databases/

Then setup /etc/dbbu.cfg with each host as described in "dbbu's Configuration File" below.

How Does It Work?

dbbu uses the subprocess module to ssh and execute commands on remote hosts (using Popen). It then pipes database dumps into files on the local filesystem.

Host Configuration

Create a user for backup purposes only:

$ sudo useradd -d /home/bak -m bak

Since dbbu will connect over ssh, you should add your backup machine's public key to bak's .ssh/authorized_keys file.

PostgreSQL

PostgreSQL can be setup in a few different ways. One method is to allow bak to run commands as the postgres user (PostgreSQL is installed as the postgres user by default on Debain). Edit /etc/sudoers to allow bak to run specific commands without a password:

Cmnd_Alias      POSTGRES_CMDS = /usr/bin/psql -l, /usr/bin/pg_dump, /usr/bin/pg_dumpall
bak     ALL = (postgres) NOPASSWD: POSTGRES_CMDS

MySQL

For MySQL, create a .my.cnf file in bak's home directory:

[mysqldump]
user=<user>
password=<password>

Make sure that this file is only readable by bak (chmod 600 .my.cnf)!

dbbu's Configuration File

[default]
# compress backup files (defaults to gzip)
compression: bzip2
# backup destination directory (defaults to current working directory)
# use default (leave blank) if using with rsnapshot
dest: /backup/
# chmod backup files, must start with 0 (defaults to 0600)
fmod: 0755
# logging level (defaults to INFO)
log_level: DEBUG
# uses RotatingFileHandler if defined
log_file: /var/log/dbbu.log

# host 1
# note that you need to prepend 'host_' to the domain name, so example.com becomes host_example.com.
[host_example.com]
# ssh user
user: bak
sudo_user: postgres
# database specifications
postgres: ALL
mysql: ALL

# host n
[host_myserver.example.com]

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.