mirror of
https://github.com/tiredofit/docker-db-backup.git
synced 2025-12-21 13:23:12 +01:00
Release 2.1.0 - See CHANGELOG.md
This commit is contained in:
140
README.md
140
README.md
@@ -1,12 +1,11 @@
|
||||
# hub.docker.com/r/tiredofit/db-backup
|
||||
|
||||
|
||||
[](https://hub.docker.com/r/tiredofit/db-backup)
|
||||
[](https://hub.docker.com/r/tiredofit/db-backup)
|
||||
[](https://hub.docker.com/r/tiredofit/db-backup)
|
||||
[](https://microbadger.com/images/tiredofit/db-backup)
|
||||
|
||||
# Introduction
|
||||
## Introduction
|
||||
|
||||
This will build a container for backing up multiple type of DB Servers
|
||||
|
||||
@@ -27,40 +26,49 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers.
|
||||
|
||||
[Changelog](CHANGELOG.md)
|
||||
|
||||
# Authors
|
||||
## Authors
|
||||
|
||||
- [Dave Conroy](https://github.com/tiredofit)
|
||||
|
||||
# Table of Contents
|
||||
## Table of Contents
|
||||
|
||||
- [Introduction](#introduction)
|
||||
- [Changelog](CHANGELOG.md)
|
||||
- [Authors](#authors)
|
||||
- [Table of Contents](#table-of-contents)
|
||||
- [Prerequisites](#prerequisites)
|
||||
- [Installation](#installation)
|
||||
- [Quick Start](#quick-start)
|
||||
- [Quick Start](#quick-start)
|
||||
- [Configuration](#configuration)
|
||||
- [Data Volumes](#data-volumes)
|
||||
- [Environment Variables](#environmentvariables)
|
||||
- [Data-Volumes](#data-volumes)
|
||||
- [Environment Variables](#environment-variables)
|
||||
- [Maintenance](#maintenance)
|
||||
- [Shell Access](#shell-access)
|
||||
- [Shell Access](#shell-access)
|
||||
- [Custom Scripts](#custom-scripts)
|
||||
- [Example Post Script](#example-post-script)
|
||||
- [$1=EXIT_CODE (After running backup routine)](#1exit_code-after-running-backup-routine)
|
||||
- [$2=DB_TYPE (Type of Backup)](#2db_type-type-of-backup)
|
||||
- [$3=DB_HOST (Backup Host)](#3db_host-backup-host)
|
||||
- [#4=DB_NAME (Name of Database backed up](#4db_name-name-of-database-backed-up)
|
||||
- [$5=DATE (Date of Backup)](#5date-date-of-backup)
|
||||
- [$6=TIME (Time of Backup)](#6time-time-of-backup)
|
||||
- [$7=BACKUP_FILENAME (Filename of Backup)](#7backup_filename-filename-of-backup)
|
||||
- [$8=FILESIZE (Filesize of backup)](#8filesize-filesize-of-backup)
|
||||
- [$9=MD5_RESULT (MD5Sum if enabled)](#9md5_result-md5sum-if-enabled)
|
||||
|
||||
# Prerequisites
|
||||
## Prerequisites
|
||||
|
||||
You must have a working DB server or container available for this to work properly, it does not provide server functionality!
|
||||
|
||||
|
||||
# Installation
|
||||
## Installation
|
||||
|
||||
Automated builds of the image are available on [Docker Hub](https://hub.docker.com/r/tiredofit/db-backup) and is the recommended
|
||||
method of installation.
|
||||
|
||||
|
||||
```bash
|
||||
docker pull tiredofit/db-backup:latest
|
||||
```
|
||||
|
||||
# Quick Start
|
||||
### Quick Start
|
||||
|
||||
* The quickest way to get started is using [docker-compose](https://docs.docker.com/compose/). See the examples folder for a working [docker-compose.yml](examples/docker-compose.yml) that can be modified for development or production use.
|
||||
|
||||
@@ -69,46 +77,45 @@ docker pull tiredofit/db-backup:latest
|
||||
|
||||
> **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
|
||||
## Configuration
|
||||
|
||||
## Data-Volumes
|
||||
### Data-Volumes
|
||||
|
||||
The following directories are used for configuration and can be mapped for persistent storage.
|
||||
|
||||
| Directory | Description |
|
||||
|-----------|-------------|
|
||||
| `/backup` | Backups |
|
||||
| `/assets/custom-scripts` | *Optional* Put custom scripts in this directory to execute after backup operations
|
||||
| Directory | Description |
|
||||
| ------------------------ | ---------------------------------------------------------------------------------- |
|
||||
| `/backup` | Backups |
|
||||
| `/assets/custom-scripts` | *Optional* Put custom scripts in this directory to execute after backup operations |
|
||||
|
||||
|
||||
## Environment Variables
|
||||
### 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](https://hub.docker.com/r/tiredofit/alpine), below is the complete list of available options that can be used to customize your installation.
|
||||
|
||||
|
||||
| Parameter | Description |
|
||||
|-----------|-------------|
|
||||
| `BACKUP_LOCATION` | Backup to `FILESYSTEM` or `S3` compatible services like S3, Minio, Wasabi - Default `FILESYSTEM`
|
||||
| `COMPRESSION` | Use either Gzip `GZ`, Bzip2 `BZ`, XZip `XZ`, ZSTD `ZSTD` or none `NONE` - Default `GZ`
|
||||
| `COMPRESSION_LEVEL` | Numberical 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_TYPE` | Type of DB Server to backup `couch` `influx` `mysql` `pgsql` `mongo` `redis` |
|
||||
| `DB_HOST` | Server Hostname e.g. `mariadb`
|
||||
| `DB_NAME` | Schema Name e.g. `database`
|
||||
| `DB_USER` | username 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_FREQ` | How often to do a dump, in minutes. Defaults to 1440 minutes, or once per day.
|
||||
| `DB_DUMP_BEGIN` | What 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_TIME` | Value 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_MODE` | If set to `true`, print copious shell script messages to the container log. Otherwise only basic messages are printed.
|
||||
| `EXTRA_OPTS` | If you need to pass extra arguments to the backup command, add them here e.g. "--extra-command"
|
||||
| `MD5` | Generate MD5 Sum in Directory, `TRUE` or `FALSE` - Default `TRUE`
|
||||
| `PARALLEL_COMPRESSION` | Use multiple cores when compressing backups `TRUE` or `FALSE` - Default `TRUE` |
|
||||
| `SPLIT_DB` | If using root as username and multiple DBs on system, set to TRUE to create Seperate DB Backups instead of all in one. - Default `FALSE` |
|
||||
| Parameter | Description |
|
||||
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `BACKUP_LOCATION` | Backup to `FILESYSTEM` or `S3` compatible services like S3, Minio, Wasabi - Default `FILESYSTEM` |
|
||||
| `COMPRESSION` | Use either Gzip `GZ`, Bzip2 `BZ`, XZip `XZ`, ZSTD `ZSTD` or none `NONE` - Default `GZ` |
|
||||
| `COMPRESSION_LEVEL` | Numberical 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_TYPE` | Type of DB Server to backup `couch` `influx` `mysql` `pgsql` `mongo` `redis` |
|
||||
| `DB_HOST` | Server Hostname e.g. `mariadb` |
|
||||
| `DB_NAME` | Schema Name e.g. `database` |
|
||||
| `DB_USER` | username 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_FREQ` | How often to do a dump, in minutes. Defaults to 1440 minutes, or once per day. |
|
||||
| `DB_DUMP_BEGIN` | What 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_TIME` | Value 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_MODE` | If set to `true`, print copious shell script messages to the container log. Otherwise only basic messages are printed. |
|
||||
| `EXTRA_OPTS` | If you need to pass extra arguments to the backup command, add them here e.g. "--extra-command" |
|
||||
| `MD5` | Generate MD5 Sum in Directory, `TRUE` or `FALSE` - Default `TRUE` |
|
||||
| `PARALLEL_COMPRESSION` | Use multiple cores when compressing backups `TRUE` or `FALSE` - Default `TRUE` |
|
||||
| `POST_SCRIPT` | Fill this variable in with a command to execute post the script backing up | |
|
||||
| `SPLIT_DB` | If 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.
|
||||
|
||||
@@ -116,22 +123,21 @@ When using compression with MongoDB, only `GZ` compression is possible.
|
||||
|
||||
If `BACKUP_LOCATION` = `S3` then the following options are used.
|
||||
|
||||
| Parameter | Description |
|
||||
|-----------|-------------|
|
||||
| `S3_BUCKET` | S3 Bucket name e.g. 'mybucket' |
|
||||
| `S3_HOSTNAME` | Hostname of S3 Server e.g "s3.amazonaws.com" - You can also include a port if necessary
|
||||
| `S3_KEY_ID` | S3 Key ID |
|
||||
| `S3_KEY_SECRET` | S3 Key Secret |
|
||||
| `S3_PATH` | S3 Pathname to save to e.g. '`backup`' |
|
||||
| `S3_PROTOCOL` | Use either `http` or `https` to access service - Default `https` |
|
||||
| `S3_URI_STYLE` | Choose either `VIRTUALHOST` or `PATH` style - Default `VIRTUALHOST`
|
||||
| Parameter | Description |
|
||||
| --------------- | --------------------------------------------------------------------------------------- |
|
||||
| `S3_BUCKET` | S3 Bucket name e.g. 'mybucket' |
|
||||
| `S3_HOSTNAME` | Hostname of S3 Server e.g "s3.amazonaws.com" - You can also include a port if necessary |
|
||||
| `S3_KEY_ID` | S3 Key ID |
|
||||
| `S3_KEY_SECRET` | S3 Key Secret |
|
||||
| `S3_PATH` | S3 Pathname to save to e.g. '`backup`' |
|
||||
| `S3_PROTOCOL` | Use either `http` or `https` to access service - Default `https` |
|
||||
| `S3_URI_STYLE` | Choose either `VIRTUALHOST` or `PATH` style - Default `VIRTUALHOST` |
|
||||
|
||||
## Maintenance
|
||||
|
||||
Manual Backups can be performed by entering the container and typing `backup-now`
|
||||
|
||||
|
||||
#### Shell Access
|
||||
### Shell Access
|
||||
|
||||
For debugging and maintenance purposes you may want access the containers shell.
|
||||
|
||||
@@ -144,23 +150,25 @@ docker exec -it (whatever your container name is e.g.) db-backup bash
|
||||
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:
|
||||
|
||||
````bash
|
||||
$ cat post-script.sh
|
||||
$ 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)
|
||||
## $1=EXIT_CODE (After running backup routine)
|
||||
## $2=DB_TYPE (Type of Backup)
|
||||
## $3=DB_HOST (Backup Host)
|
||||
## #4=DB_NAME (Name of Database backed up
|
||||
## $5=DATE (Date of Backup)
|
||||
## $6=TIME (Time of Backup)
|
||||
## $7=BACKUP_FILENAME (Filename of Backup)
|
||||
## $8=FILESIZE (Filesize of backup)
|
||||
## $9=MD5_RESULT (MD5Sum if enabled)
|
||||
|
||||
echo "${1} Backup Completed on ${2} for ${3} on ${4} ${5}. Filename: ${6} Size: ${7} bytes MD5: ${8}"
|
||||
echo "${1} ${2} Backup Completed on ${3} for ${4} on ${5} ${6}. Filename: ${7} Size: ${8} bytes MD5: ${9}"
|
||||
````
|
||||
|
||||
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`
|
||||
`0 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`
|
||||
|
||||
Reference in New Issue
Block a user