Skip to content

Commit 532a6b4

Browse files
authored
Merge pull request #166 from eoehen/feature/Add-support-for-blobxfer
Add support for blobxfer
2 parents a8d9a01 + 9569040 commit 532a6b4

File tree

5 files changed

+91
-1
lines changed

5 files changed

+91
-1
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/* && \
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:

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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,13 @@ cleanup_old_data() {
452452
if [ -n "${DB_CLEANUP_TIME}" ]; then
453453
if [ "${master_exit_code}" != 1 ]; then
454454
case "${BACKUP_LOCATION,,}" in
455-
"file" | "filesystem" )
455+
"file" | "filesystem" | "blobxfer" )
456456
print_info "Cleaning up old backups"
457457
mkdir -p "${DB_DUMP_TARGET}"
458458
find "${DB_DUMP_TARGET}"/ -mmin +"${DB_CLEANUP_TIME}" -iname "*" -exec rm {} \;
459+
460+
print_info "Cleaning up old backups on S3 storage with blobxfer"
461+
blobxfer upload --mode file --remote-path ${BLOBXFER_REMOTE_PATH} --local-path ${DB_DUMP_TARGET} --delete --delete-only
459462
;;
460463
"s3" | "minio" )
461464
print_info "Cleaning up old backups"
@@ -631,6 +634,18 @@ move_dbbackup() {
631634
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}
632635
fi
633636

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

0 commit comments

Comments
 (0)