Skip to content

Commit a8d9a01

Browse files
authored
Merge pull request #165 from eoehen/feature/Improve-mssql-support
Improve MSSQL Support
2 parents 7bda69b + 4d7f5e9 commit a8d9a01

File tree

5 files changed

+86
-7
lines changed

5 files changed

+86
-7
lines changed

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/

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/functions/10-db-backup

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)