Sign inSign up

rusxakep/db-backup

By rusxakep

•Updated about 5 years ago
Archived

Docker Backup various DB Services with customizable options based on Alpine

Image
0

242

rusxakep/db-backup repository overview

⁠hub.docker.com/r/rusxakep/db-backup

Build Status Docker Pulls Docker Stars Docker Layers

⁠Introduction

This will build a container for backing up multiple type of DB Servers

Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers.

  • dump to local filesystem or backup to S3 Compatible services

  • select database user and password

  • backup all databases

  • choose to have an MD5 sum after backup for verification

  • delete old backups after specific amount of time

  • choose compression type (none, gz, bz, xz, zstd)

  • connect to any container running on the same system

  • select how often to run a dump

  • select when to start the first dump, whether time of day or relative to container start time

  • Execute script after backup for monitoring/alerting purposes

  • This Container uses a customized Alpine Linux base⁠ which includes s6 overlay⁠ enabled for PID 1 Init capabilities, zabbix-agent⁠ for individual container monitoring, Cron also installed along with other tools (bash,curl, less, logrotate, nano, vim) for easier management. It also supports sending to external SMTP servers.

Changelog⁠

⁠Authors

⁠Table of Contents

⁠Prerequisites

You must have a working DB server or container available for this to work properly, it does not provide server functionality!

⁠Installation

Automated builds of the image are available on Docker Hub⁠ and is the recommended method of installation.

docker pull rusxakep/db-backup:latest

⁠Quick Start

NOTE: If you are using this with a docker-compose file along with a seperate SQL container, take care not to set the variables to backup immediately, more so have it delay execution for a minute, otherwise you will get a failed first backup.

⁠Configuration

⁠Data-Volumes

The following directories are used for configuration and can be mapped for persistent storage.

DirectoryDescription
/backupBackups
/assets/custom-scriptsOptional Put custom scripts in this directory to execute after backup operations

⁠Environment Variables

If you are trying to backup a database that doesn't have a user or a password (you should!) make sure you set CONTAINER_ENABLE_DOCKER_SECRETS=FALSE

Along with the Environment Variables from the Base image⁠, below is the complete list of available options that can be used to customize your installation.

ParameterDescription
BACKUP_LOCATIONBackup to FILESYSTEM or S3 compatible services like S3, Minio, Wasabi - Default FILESYSTEM
COMPRESSIONUse either Gzip GZ, Bzip2 BZ, XZip XZ, ZSTD ZSTD or none NONE - Default GZ
COMPRESSION_LEVELNumerical value of what level of compression to use, most allow 1 to 9 except for ZSTD which allows for 1 to 19 - Default 3
DB_TYPEType of DB Server to backup couch influx mysql pgsql mongo redis
DB_HOSTServer Hostname e.g. mariadb
DB_NAMESchema Name e.g. database
DB_USERusername for the database - use root to backup all MySQL of them.
DB_PASS(optional if DB doesn't require it) password for the database
DB_PORT(optional) Set port to connect to DB_HOST. Defaults are provided
DB_DUMP_FREQHow often to do a dump, in minutes. Defaults to 1440 minutes, or once per day.
DB_DUMP_BEGINWhat time to do the first dump. Defaults to immediate. Must be in one of two formats
Absolute HHMM, e.g. 2330 or 0415
Relative +MM, i.e. how many minutes after starting the container, e.g. +0 (immediate), +10 (in 10 minutes), or +90 in an hour and a half
DB_CLEANUP_TIMEValue in minutes to delete old backups (only fired when dump freqency fires). 1440 would delete anything above 1 day old. You don't need to set this variable if you want to hold onto everything.
DEBUG_MODEIf set to true, print copious shell script messages to the container log. Otherwise only basic messages are printed.
EXTRA_OPTSIf you need to pass extra arguments to the backup command, add them here e.g. "--extra-command"
MD5Generate MD5 Sum in Directory, TRUE or FALSE - Default TRUE
PARALLEL_COMPRESSIONUse multiple cores when compressing backups TRUE or FALSE - Default TRUE
SPLIT_DBIf using root as username and multiple DBs on system, set to TRUE to create Seperate DB Backups instead of all in one. - Default FALSE

When using compression with MongoDB, only GZ compression is possible.

Backing Up to S3 Compatible Services

If BACKUP_LOCATION = S3 then the following options are used.

ParameterDescription
S3_BUCKETS3 Bucket name e.g. 'mybucket'
S3_HOSTNAMEHostname of S3 Server e.g "s3.amazonaws.com" - You can also include a port if necessary
S3_KEY_IDS3 Key ID
S3_KEY_SECRETS3 Key Secret
S3_PATHS3 Pathname to save to e.g. 'backup'
S3_PROTOCOLUse either http or https to access service - Default https
S3_URI_STYLEChoose either VIRTUALHOST or PATH style - Default VIRTUALHOST

⁠Maintenance

Manual Backups can be performed by entering the container and typing backup-now

⁠Shell Access

For debugging and maintenance purposes you may want access the containers shell.

docker exec -it (whatever your container name is e.g.) db-backup bash
⁠Custom Scripts

If you want to execute a custom script at the end of backup, you can drop bash scripts with the extension of .sh in this directory. See the following example to utilize:

$ cat post-script.sh 
##!/bin/bash

## Example Post Script
## $1=DB_TYPE (Type of Backup)
## $2=DB_HOST (Backup Host)
## #3=DB_NAME (Name of Database backed up
## $4=DATE (Date of Backup)
## $5=TIME (Time of Backup)
## $6=BACKUP_FILENAME (Filename of Backup)
## $7=FILESIZE (Filesize of backup)
## $8=MD5_RESULT (MD5Sum if enabled)

echo "${1} Backup Completed on ${2} for ${3} on ${4} ${5}. Filename: ${6} Size: ${7} bytes MD5: ${8}"

Outputs the following on the console:

mysql Backup Completed on example-db for example on 2020-04-22 05:19:10. Filename: mysql_example_example-db_20200422-051910.sql.bz2 Size: 7795 bytes MD5: 952fbaafa30437494fdf3989a662cd40

If you wish to change the size value from bytes to megabytes set environment variable SIZE_VALUE=megabytes

Tag summary

Content type

Image

Digest

Size

171.8 MB

Last updated

about 5 years ago

docker pull rusxakep/db-backup