-
Notifications
You must be signed in to change notification settings - Fork 3
/
docker-entrypoint-initdb.sh
38 lines (33 loc) · 1.34 KB
/
docker-entrypoint-initdb.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# wait for database to start...
for i in {30..0}; do
if sqlcmd -U SA -P $MSSQL_SA_PASSWORD -Q 'SELECT 1;' &> /dev/null; then
echo "$0: SQL Server started"
break
fi
echo "$0: SQL Server startup in progress..."
sleep 1
done
echo "$0: inicializando dump da estrutura"
for entry in $(ls schemas/*.bak)
do
echo importando $entry
shortname=$(echo $entry | cut -f 1 -d '.' | cut -f 2 -d '/')
echo executing $shortname
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "salic@123456" -Q 'RESTORE FILELISTONLY FROM DISK = "/tmp/schemas/'$shortname'.bak"' | tr -s ' ' | cut -d ' ' -f 1-2
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "salic@123456" -Q 'RESTORE DATABASE '$shortname' FROM DISK = "/tmp/schemas/'$shortname'.bak" WITH MOVE "'$shortname'_Est" TO "/var/opt/mssql/data/'$shortname'_Est.mdf", MOVE "'$shortname'_Est_log" TO "/var/opt/mssql/data/'$shortname'_Est_log.ldf"'
done
echo "$0: inicializando dump da base"
for f in docker-entrypoint-initdb.d/*; do
echo "teste $f";
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; /opt/mssql-tools/bin/sqlcmd -U SA -P "salic@123456" -X -i "$f"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
echo "$0: SQL Server Database ready"
# echo "$0: Loads initial data..."
# cd /tmp/migrate
# ./main.py migrate 0-initial