Skip to content

Commit 8a5d647

Browse files
committed
Merge branch 'master' of github.com:tiredofit/docker-db-backup into bugfix/s3_backup_prefixes
# Conflicts: # install/assets/functions/10-db-backup
2 parents 4f5c04a + 494f742 commit 8a5d647

File tree

12 files changed

+388
-152
lines changed

12 files changed

+388
-152
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Declare files that will always have LF line endings on checkout.
2+
*.* text eol=lf

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
## 3.5.4 2022-10-13 <dave at tiredofit dot ca>
2+
3+
### Changed
4+
- Fix for Influx DB 1 backups when compression enabled
5+
6+
7+
## 3.5.3 2022-10-12 <dave at tiredofit dot ca>
8+
9+
### Changed
10+
- Remove build dependencies for blobxfer making image size smaller
11+
- Remove silencing commands limiting Postgres backups from working without DEBUG_MODE=TRUE
12+
13+
14+
## 3.5.2 2022-10-11 <dave at tiredofit dot ca>
15+
16+
### Added
17+
- Update Influxdb client to 2.4.0 (jauderho@github)
18+
19+
20+
## 3.5.1 2022-10-11 <dave at tiredofit dot ca>
21+
22+
### Changed
23+
- Tighten up cleanup routines to not call blobxfer unless absolutely necessary
24+
25+
26+
## 3.5.0 2022-10-10 <dave at tiredofit dot ca>
27+
28+
### Added
29+
- Blobxfer / Microsoft Azure Support (credit: eoehen@github)
30+
- Introduce MONGO_CUSTOM_URI environment variable for those not wanting to use DB_* variables
31+
32+
### Changed
33+
- Force filenames to be in lowercase
34+
- Fix S3 Database cleanups (credit greenatwork@github)
35+
- Remove MONGO_DB_TYPE variable as MONGO_CUSTOM_URI overrides
36+
- Fix MSSQL Backups (credit eoehen@github)
37+
- Seperate examples for MySQL and MSSQL
38+
39+
140
## 3.4.2 2022-09-19 <dave at tiredofit dot ca>
241

342
### Changed

Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ LABEL maintainer="Dave Conroy (github.com/tiredofit)"
33

44
### Set Environment Variables
55

6-
ENV INFLUX2_VERSION=2.2.1 \
6+
ENV INFLUX2_VERSION=2.4.0 \
77
MSSQL_VERSION=18.0.1.1-1 \
88
CONTAINER_ENABLE_MESSAGING=FALSE \
99
CONTAINER_ENABLE_MONITORING=TRUE \
@@ -20,6 +20,10 @@ RUN set -ex && \
2020
bzip2-dev \
2121
git \
2222
libarchive-dev \
23+
libressl-dev \
24+
libffi-dev \
25+
python3-dev \
26+
py3-pip \
2327
xz-dev \
2428
&& \
2529
\
@@ -36,6 +40,7 @@ RUN set -ex && \
3640
postgresql \
3741
postgresql-client \
3842
pv \
43+
py3-cryptography \
3944
redis \
4045
sqlite \
4146
xz \
@@ -68,6 +73,8 @@ RUN set -ex && \
6873
make && \
6974
make install && \
7075
\
76+
pip3 install blobxfer && \
77+
\
7178
### Cleanup
7279
apk del .db-backup-build-deps && \
7380
rm -rf /usr/src/* && \

README.md

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This will build a container for backing up multiple types of DB Servers
1414

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

17-
* dump to local filesystem or backup to S3 Compatible services
17+
* dump to local filesystem or backup to S3 Compatible services, and Azure.
1818
* select database user and password
1919
* backup all databases, single, or multiple databases
2020
* backup all to seperate files or one singular file
@@ -37,15 +37,14 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers.
3737
- [About](#about)
3838
- [Maintainer](#maintainer)
3939
- [Table of Contents](#table-of-contents)
40-
- [Persistent Storage](#persistent-storage)
4140
- [Prerequisites and Assumptions](#prerequisites-and-assumptions)
4241
- [Installation](#installation)
4342
- [Build from Source](#build-from-source)
4443
- [Prebuilt Images](#prebuilt-images)
4544
- [Multi Architecture](#multi-architecture)
4645
- [Configuration](#configuration)
4746
- [Quick Start](#quick-start)
48-
- [Persistent Storage](#persistent-storage-1)
47+
- [Persistent Storage](#persistent-storage)
4948
- [Environment Variables](#environment-variables)
5049
- [Base Images used](#base-images-used)
5150
- [Container Options](#container-options)
@@ -70,7 +69,6 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers.
7069
- [License](#license)
7170

7271
> **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.
73-
### Persistent Storage
7472
7573
## Prerequisites and Assumptions
7674
* You must have a working connection to one of the supported DB Servers and appropriate credentials
@@ -104,6 +102,7 @@ Images are built primarily for `amd64` architecture, and may also include builds
104102
* Set various [environment variables](#environment-variables) to understand the capabilities of this image.
105103
* Map [persistent storage](#data-volumes) for access to configuration and data files for backup.
106104
* Make [networking ports](#networking) available for public access if necessary
105+
107106
### Persistent Storage
108107

109108
The following directories are used for configuration and can be mapped for persistent storage.
@@ -139,32 +138,32 @@ Be sure to view the following repositories to understand all the customizable op
139138
| `SPLIT_DB` | For each backup, create a new archive. `TRUE` or `FALSE` (MySQL and Postgresql Only) | `TRUE` |
140139

141140
### Database Specific Options
142-
| Parameter | Description | Default |
143-
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
144-
| `DB_AUTH` | (Mongo Only - Optional) Authentication Database | |
145-
| `DB_TYPE` | Type of DB Server to backup `couch` `influx` `mysql` `pgsql` `mongo` `redis` `sqlite3` | |
146-
| `DB_HOST` | Server Hostname e.g. `mariadb`. For `sqlite3`, full path to DB file e.g. `/backup/db.sqlite3` | |
147-
| `DB_NAME` | Schema Name e.g. `database` or `ALL` to backup all databases the user has access to. Backup multiple by seperating with commas eg `db1,db2` | |
148-
| `DB_NAME_EXCLUDE` | If using `ALL` - use this as to exclude databases seperated via commas from being backed up | |
149-
| `DB_USER` | username for the database(s) - Can use `root` for MySQL | |
150-
| `DB_PASS` | (optional if DB doesn't require it) password for the database | |
151-
| `DB_PORT` | (optional) Set port to connect to DB_HOST. Defaults are provided | varies |
152-
| `INFLUX_VERSION` | What Version of Influx are you backing up from `1`.x or `2` series - AMD64 and ARM64 only for `2` | |
153-
| `MONGO_HOST_TYPE` | Connect to regular `mongodb` or `atlas` | `mongodb` |
154-
| | You can also skip this and override the uri prefix with `MONGO_URI_PREFIX=mongodb+srv://` or whatever you would like | |
141+
| Parameter | Description | Default |
142+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------- |
143+
| `DB_AUTH` | (Mongo Only - Optional) Authentication Database | |
144+
| `DB_TYPE` | Type of DB Server to backup `couch` `influx` `mysql` `pgsql` `mongo` `redis` `sqlite3` | |
145+
| `DB_HOST` | Server Hostname e.g. `mariadb`. For `sqlite3`, full path to DB file e.g. `/backup/db.sqlite3` | |
146+
| `DB_NAME` | Schema Name e.g. `database` or `ALL` to backup all databases the user has access to. Backup multiple by seperating with commas eg `db1,db2` | |
147+
| `DB_NAME_EXCLUDE` | If using `ALL` - use this as to exclude databases seperated via commas from being backed up | |
148+
| `DB_USER` | username for the database(s) - Can use `root` for MySQL | |
149+
| `DB_PASS` | (optional if DB doesn't require it) password for the database | |
150+
| `DB_PORT` | (optional) Set port to connect to DB_HOST. Defaults are provided | varies |
151+
| `INFLUX_VERSION` | What Version of Influx are you backing up from `1`.x or `2` series - AMD64 and ARM64 only for `2` | |
152+
| `MONGO_CUSTOM_URI` | If you wish to override the MongoDB Connection string enter it here e.g. `mongodb+srv://username:[email protected]` | |
153+
| | This environment variable will be parsed and populate the `DB_NAME` and `DB_HOST` variables to properly build your backup filenames. You can overrde them by making your own entries |
155154

156155
#### For Influx DB2:
157156
Your Organization will be mapped to `DB_USER` and your root token will need to be mapped to `DB_PASS`. You may use `DB_NAME=ALL` to backup the entire set of databases. For `DB_HOST` use syntax of `http(s)://db-name`
158157

159158
### Scheduling Options
160-
| Parameter | Description | Default |
161-
|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|
162-
| `DB_DUMP_FREQ` | How often to do a dump, in minutes after the first backup. Defaults to 1440 minutes, or once per day. | `1440` |
163-
| `DB_DUMP_BEGIN` | What time to do the first dump. Defaults to immediate. Must be in one of two formats | |
164-
| | Absolute HHMM, e.g. `2330` or `0415` | |
165-
| | 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 | |
166-
| `DB_DUMP_TARGET` | Directory where the database dumps are kept. | `/backup` |
167-
| `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. | `FALSE` |
159+
| Parameter | Description | Default |
160+
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
161+
| `DB_DUMP_FREQ` | How often to do a dump, in minutes after the first backup. Defaults to 1440 minutes, or once per day. | `1440` |
162+
| `DB_DUMP_BEGIN` | What time to do the first dump. Defaults to immediate. Must be in one of two formats | |
163+
| | Absolute HHMM, e.g. `2330` or `0415` | |
164+
| | 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 | |
165+
| `DB_DUMP_TARGET` | Directory where the database dumps are kept. | `/backup` |
166+
| `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. | `FALSE` |
168167

169168

170169
- You may need to wrap your `DB_DUMP_BEGIN` value in quotes for it to properly parse. There have been reports of backups that start with a `0` get converted into a different format which will not allow the timer to start at the correct time.
@@ -204,6 +203,22 @@ If `BACKUP_LOCATION` = `S3` then the following options are used.
204203
| _*OR*_ | | |
205204
| `S3_CERT_SKIP_VERIFY` | Skip verifying self signed certificates when connecting | `TRUE` |
206205

206+
#### Upload to a Azure storage account by `blobxfer`
207+
208+
Support to upload backup files with [blobxfer](https://github.com/Azure/blobxfer) to the Azure fileshare storage.
209+
210+
211+
If `BACKUP_LOCATION` = `blobxfer` then the following options are used.
212+
213+
| Parameter | Description | Default |
214+
| ------------------------------- | ------------------------------------------------------------------------ | -------------------- |
215+
| `BLOBXFER_STORAGE_ACCOUNT` | Microsoft Azure Cloud storage account name. | |
216+
| `BLOBXFER_STORAGE_ACCOUNT_KEY` | Microsoft Azure Cloud storage account key. | |
217+
| `BLOBXFER_REMOTE_PATH` | Remote Azure path | `/docker-db-backup` |
218+
219+
> This service uploads files from backup targed directory `DB_DUMP_TARGET`.
220+
> If the a cleanup configuration in `DB_CLEANUP_TIME` is defined, the remote directory on Azure storage will also be cleaned automatically.
221+
207222
## Maintenance
208223

209224
### Shell Access

examples/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# Example container mounted folders
4+
**/backups/
5+
**/db/
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#
2+
# Example for Microsoft SQL Server
3+
# upload with blobxfer to azure storage
4+
#
5+
6+
version: '2'
7+
8+
networks:
9+
example-mssql-blobxfer-net:
10+
name: example-mssql-blobxfer-net
11+
12+
services:
13+
example-mssql-s3-db:
14+
hostname: example-db-host
15+
image: mcr.microsoft.com/mssql/server:2019-latest
16+
container_name: example-mssql-s3-db
17+
restart: unless-stopped
18+
ports:
19+
- "127.0.0.1:11433:1433"
20+
networks:
21+
example-mssql-blobxfer-net:
22+
volumes:
23+
- ./tmp/backups:/tmp/backups # shared tmp backup directory
24+
environment:
25+
ACCEPT_EULA: Y
26+
MSSQL_SA_PASSWORD: 5hQa0utRFBpIY3yhoIyE
27+
MSSQL_PID: Express
28+
29+
example-mssql-blobxfer-db-backup:
30+
container_name: example-mssql-blobxfer-db-backup
31+
# if you want to build and use image from current source
32+
# execute in terminal --> docker build -t tiredofit/db-backup-mssql-blobxfer .
33+
# replace --> image: tiredofit/db-backup-mssql
34+
# image: tiredofit/db-backup
35+
image: tiredofit/db-backup-mssql-blobxfer
36+
links:
37+
- example-mssql-s3-db
38+
volumes:
39+
- ./backups:/backup
40+
- ./tmp/backups:/tmp/backups # shared tmp backup directory
41+
#- ./post-script.sh:/assets/custom-scripts/post-script.sh
42+
environment:
43+
# - DEBUG_MODE=TRUE
44+
- DB_TYPE=mssql
45+
- DB_HOST=example-db-host
46+
# - DB_PORT=1488
47+
# - DB_NAME=ALL # [ALL] not working on sql server.
48+
# create database with name `test1` manually first
49+
- DB_NAME=test1 # Create this database
50+
- DB_USER=sa
51+
- DB_PASS=5hQa0utRFBpIY3yhoIyE
52+
- DB_DUMP_FREQ=1 # backup every 5 minute
53+
# - DB_DUMP_BEGIN=0000 # backup starts immediately
54+
- DB_CLEANUP_TIME=3 # clean backups they are older than 60 minutes
55+
- ENABLE_CHECKSUM=TRUE
56+
- CHECKSUM=SHA1
57+
- COMPRESSION=GZ
58+
- SPLIT_DB=FALSE
59+
- CONTAINER_ENABLE_MONITORING=FALSE
60+
# === S3 Blobxfer ===
61+
- BACKUP_LOCATION=blobxfer
62+
# Add here azure storage account
63+
- BLOBXFER_STORAGE_ACCOUNT={TODO Add Storage Name}
64+
# Add here azure storage account key
65+
- BLOBXFER_STORAGE_ACCOUNT_KEY={TODO Add Key}
66+
- BLOBXFER_REMOTE_PATH=docker-db-backup
67+
restart: always
68+
networks:
69+
example-mssql-blobxfer-net:

examples/mssql/docker-compose.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#
2+
# Example for Microsoft SQL Server
3+
#
4+
5+
version: '2'
6+
7+
networks:
8+
example-mssql-net:
9+
name: example-mssql-net
10+
11+
services:
12+
example-mssql-db:
13+
hostname: example-db-host
14+
image: mcr.microsoft.com/mssql/server:2019-latest
15+
container_name: example-mssql-db
16+
restart: unless-stopped
17+
ports:
18+
- "127.0.0.1:11433:1433"
19+
networks:
20+
example-mssql-net:
21+
volumes:
22+
- ./tmp/backups:/tmp/backups # shared tmp backup directory
23+
environment:
24+
ACCEPT_EULA: Y
25+
MSSQL_SA_PASSWORD: 5hQa0utRFBpIY3yhoIyE
26+
MSSQL_PID: Express
27+
28+
example-mssql-db-backup:
29+
container_name: example-mssql-db-backup
30+
# if you want to build and use image from current source
31+
# execute in terminal --> docker build -t tiredofit/db-backup-mssql .
32+
# replace --> image: tiredofit/db-backup-mssql
33+
# image: tiredofit/db-backup
34+
image: tiredofit/db-backup-mssql
35+
links:
36+
- example-mssql-db
37+
volumes:
38+
- ./backups:/backup
39+
- ./tmp/backups:/tmp/backups # shared tmp backup directory
40+
#- ./post-script.sh:/assets/custom-scripts/post-script.sh
41+
environment:
42+
# - DEBUG_MODE=TRUE
43+
- DB_TYPE=mssql
44+
- DB_HOST=example-db-host
45+
# - DB_PORT=1488
46+
# - DB_NAME=ALL # [ALL] not working on sql server.
47+
# create database with name `test1` manually first
48+
- DB_NAME=test1
49+
- DB_USER=sa
50+
- DB_PASS=5hQa0utRFBpIY3yhoIyE
51+
- DB_DUMP_FREQ=1 # backup every minute
52+
# - DB_DUMP_BEGIN=0000 # backup starts immediately
53+
- DB_CLEANUP_TIME=5 # clean backups they are older than 5 minute
54+
- ENABLE_CHECKSUM=FALSE
55+
- CHECKSUM=SHA1
56+
- COMPRESSION=GZ
57+
- SPLIT_DB=FALSE
58+
- CONTAINER_ENABLE_MONITORING=FALSE
59+
restart: always
60+
networks:
61+
example-mssql-net:

0 commit comments

Comments
 (0)