Skip to content

Commit b9edbf6

Browse files
committed
2 parents b956bd8 + 532a6b4 commit b9edbf6

File tree

9 files changed

+177
-8
lines changed

9 files changed

+177
-8
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

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ RUN set -ex && \
6868
make && \
6969
make install && \
7070
\
71+
apk add gcc build-base libressl-dev libffi-dev python3-dev py3-pip && \
72+
pip3 install blobxfer && \
73+
\
7174
### Cleanup
7275
apk del .db-backup-build-deps && \
7376
rm -rf /usr/src/* && \

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:
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
version: '2'
22

3+
networks:
4+
example-db-network:
5+
name: example-db-network
6+
37
services:
48
example-db:
9+
hostname: example-db-host
510
container_name: example-db
611
image: mariadb:latest
12+
ports:
13+
- 13306:3306
714
volumes:
815
- ./db:/var/lib/mysql
916
environment:
@@ -12,6 +19,8 @@ services:
1219
- MYSQL_USER=example
1320
- MYSQL_PASSWORD=examplepassword
1421
restart: always
22+
networks:
23+
- example-db-network
1524

1625
example-db-backup:
1726
container_name: example-db-backup
@@ -22,17 +31,21 @@ services:
2231
- ./backups:/backup
2332
#- ./post-script.sh:/assets/custom-scripts/post-script.sh
2433
environment:
34+
# - DEBUG_MODE=TRUE
2535
- DB_TYPE=mariadb
26-
- DB_HOST=example-db
36+
- DB_HOST=example-db-host
2737
- DB_NAME=example
2838
- DB_USER=example
29-
- DB_PASS="examplepassword"
30-
- DB_DUMP_FREQ=1440
31-
- DB_DUMP_BEGIN=0000
32-
- DB_CLEANUP_TIME=8640
39+
- DB_PASS=examplepassword
40+
- DB_DUMP_FREQ=1 # backup every minute
41+
# - DB_DUMP_BEGIN=0000 # backup starts immediately
42+
- DB_CLEANUP_TIME=5 # clean backups they are older than 5 minute
3343
- CHECKSUM=SHA1
34-
- COMPRESSION=ZSTD
44+
- COMPRESSION=GZ
3545
- SPLIT_DB=FALSE
46+
- CONTAINER_ENABLE_MONITORING=FALSE
3647
restart: always
48+
networks:
49+
- example-db-network
3750

3851

install/assets/defaults/10-db-backup

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ SCRIPT_LOCATION_POST=${SCRIPT_LOCATION_POST:-"/assets/scripts/post/"}
2222
SIZE_VALUE=${SIZE_VALUE:-"bytes"}
2323
SPLIT_DB=${SPLIT_DB:-"TRUE"}
2424
TEMP_LOCATION=${TEMP_LOCATION:-"/tmp/backups"}
25+
BLOBXFER_REMOTE_PATH=${BLOBXFER_REMOTE_PATH:-"/docker-db-backup"}

install/assets/functions/10-db-backup

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ backup_mssql() {
173173
compression
174174
pre_dbbackup "${DB_NAME}"
175175
print_notice "Dumping MSSQL database: '${DB_NAME}'"
176-
/opt/mssql-tools/bin/sqlcmd -E -C -S ${DB_HOST}\,${DB_PORT} -U ${DB_USER} -P ${DB_PASS} Q "BACKUP DATABASE \[${DB_NAME}\] TO DISK = N'${TEMP_LOCATION}/${target}' WITH NOFORMAT, NOINIT, NAME = '${DB_NAME}-full', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
176+
/opt/mssql-tools18/bin/sqlcmd -C -S ${DB_HOST}\,${DB_PORT} -U ${DB_USER} -P ${DB_PASS} -Q "BACKUP DATABASE [${DB_NAME}] TO DISK = N'${TEMP_LOCATION}/${target}' WITH NOFORMAT, NOINIT, NAME = '${DB_NAME}-full', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
177177
exit_code=$?
178178
check_exit_code $target
179179
generate_checksum
@@ -454,10 +454,13 @@ cleanup_old_data() {
454454
if [ -n "${DB_CLEANUP_TIME}" ]; then
455455
if [ "${master_exit_code}" != 1 ]; then
456456
case "${BACKUP_LOCATION,,}" in
457-
"file" | "filesystem" )
457+
"file" | "filesystem" | "blobxfer" )
458458
print_info "Cleaning up old backups"
459459
mkdir -p "${DB_DUMP_TARGET}"
460460
find "${DB_DUMP_TARGET}"/ -mmin +"${DB_CLEANUP_TIME}" -iname "*" -exec rm {} \;
461+
462+
print_info "Cleaning up old backups on S3 storage with blobxfer"
463+
blobxfer upload --mode file --remote-path ${BLOBXFER_REMOTE_PATH} --local-path ${DB_DUMP_TARGET} --delete --delete-only
461464
;;
462465
"s3" | "minio" )
463466
print_info "Cleaning up old backups"
@@ -633,6 +636,18 @@ move_dbbackup() {
633636
silent aws ${PARAM_AWS_ENDPOINT_URL} s3 cp ${TEMP_LOCATION}/*.${checksum_extension} s3://${S3_BUCKET}/${S3_PATH}/ ${s3_ssl} ${s3_ca_cert} ${S3_EXTRA_OPTS}
634637
fi
635638

639+
rm -rf "${TEMP_LOCATION}"/*."${checksum_extension}"
640+
rm -rf "${TEMP_LOCATION}"/"${target}"
641+
;;
642+
"blobxfer" )
643+
print_info "Moving backup to S3 Bucket with blobxfer"
644+
645+
mkdir -p "${DB_DUMP_TARGET}"
646+
mv "${TEMP_LOCATION}"/*."${checksum_extension}" "${DB_DUMP_TARGET}"/
647+
mv "${TEMP_LOCATION}"/"${target}" "${DB_DUMP_TARGET}"/"${target}"
648+
649+
blobxfer upload --mode file --remote-path ${BLOBXFER_REMOTE_PATH} --local-path ${DB_DUMP_TARGET}
650+
636651
rm -rf "${TEMP_LOCATION}"/*."${checksum_extension}"
637652
rm -rf "${TEMP_LOCATION}"/"${target}"
638653
;;

0 commit comments

Comments
 (0)