Commit 000b42f5 authored by pasden's avatar pasden 💬
Browse files

Update restore_db.sh

parent 887dda7c
#!/bin/sh
container_name="itinvent"
path_docker_containers="/volume1/docker"
backup_path_inside_container="/var/opt/mssql/backup"
sql_user="sa"
sql_password="yourStrong(!)Password"
sql_database="ITINVENT"
sql_port="1433"
CONTAINER_NAME="itinvent"
PATH_DOCKER_CONTAINERS="/volume1/docker"
BACKUP_PATH_INSIDE_CONTAINER="/var/opt/mssql/backup"
SQL_USER="sa"
SQL_PASSWORD="yourStrong(!)Password"
SQL_DATABASE="ITINVENT"
SQL_PORT="1433"
backup_file=$(find ${path_docker_containers}/${container_name}/backup -type f -name "*.bak" | sort -V | tail -1 | awk -F'/' '{print $NF}')
backup_file=$(find ${PATH_DOCKER_CONTAINERS}/${CONTAINER_NAME}/backup -type f -name "*.bak" | sort -V | tail -1 | awk -F'/' '{print $NF}')
docker exec -d $container_name /opt/mssql-tools/bin/sqlcmd \
-S "localhost,${sql_port}" \
-U "${sql_user}" \
-P "${sql_password}" \
docker exec -d $CONTAINER_NAME /opt/mssql-tools/bin/sqlcmd \
-S "localhost,${SQL_PORT}" \
-U "${SQL_USER}" \
-P "${SQL_PASSWORD}" \
-Q "
USE [master]
RESTORE DATABASE [${sql_database}] FROM DISK = N'${backup_path_inside_container}/${backup_file}' WITH FILE = 1, MOVE N'${sql_database}_Data' TO N'/var/opt/mssql/data/${sql_database}.mdf', MOVE N'${sql_database}_Log' TO N'/var/opt/mssql/data/${sql_database}.ldf', NOUNLOAD, STATS = 5
RESTORE DATABASE [${SQL_DATABASE}] FROM DISK = N'${BACKUP_PATH_INSIDE_CONTAINER}/${backup_file}' WITH FILE = 1, MOVE N'${SQL_DATABASE}_Data' TO N'/var/opt/mssql/data/${SQL_DATABASE}.mdf', MOVE N'${SQL_DATABASE}_Log' TO N'/var/opt/mssql/data/${SQL_DATABASE}.ldf', NOUNLOAD, STATS = 5
GO
"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment