sillelien/docker-mysql-backup

By sillelien

Updated over 9 years ago

Backup mysql to S3

Image

3.8K

mysql-backup

Container that backs up MySQL databases to S3. The container overwrites the same S3 object every time it is run, it is recommended you turn versioning on to retain access to previous copies.

There is an existing image available on the public registry at sillelien/mysql-backup.

Using on Tutum

See the tutum.yml for more details.

Backing up

To backup run:

$ docker run -e AWS_ACCESS_KEY_ID=key -e AWS_SECRET_ACCESS_KEY=secret -e AWS_DEFAULT_REGION=eu-west-1 -e MYSQL_HOST=127.0.0.1 -e MYSQL_USER=root -e MYSQL_PASSWORD=password sillelien/mysql-backup backup

You can provide an extra argument with a specific database to backup.

Restoring

To restore an existing backup run:

$ docker run -e AWS_ACCESS_KEY_ID="key" -e AWS_SECRET_ACCESS_KEY="secret" -e AWS_DEFAULT_REGION="eu-west-1" -e MYSQL_HOST=127.0.0.1 -e MYSQL_USER=root -e MYSQL_PASSWORD=password sillelien/mysql-backup restore

It is important to note that if this database already exists on your server, this process will drop it first. You can also provide an extra argument with a specific database to restore.

Excluding Databases

You can exclude databases from backup/restore by using --exclude.

For example:

$ docker run -e AWS_ACCESS_KEY_ID="key" -e AWS_SECRET_ACCESS_KEY="secret" -e AWS_DEFAULT_REGION="eu-west-1" -e MYSQL_HOST=127.0.0.1 -e MYSQL_USER=root -e MYSQL_PASSWORD=password sillelien/mysql-backup --exclude=some_database,another_database restore

Configuration

The container can be customized with these environment variables:

NameDefault ValueDescription
AWS_ACCESS_KEY_IDblankYour AWS access key with access to the desired bucket
AWS_SECRET_ACCESS_KEYblankYour AWS secret access key with access to the desired bucket
AWS_DEFAULT_REGIONblankThe AWS region your bucket is in
MYSQL_HOSTfrom linkAddress the MySQL server is accessible at
MYSQL_PORTfrom linkPort the MySQL server is accessible on
MYSQL_USERfrom linkUser to connect as
MYSQL_PASSWORDfrom linkPassword to use when connecting
RESTORE_DB_CHARSETutf8Which charset to recreate the database with
RESTORE_DB_COLLATIONutf8_binWhich collation to recreate the database with
S3_BUCKETblankThe bucket to write the backup to
S3_PATHmysqlThe path to write the backups to

Docker Pull Command

docker pull sillelien/docker-mysql-backup