1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-03 14:03:33 +01:00
bitwarden-server/util/MsSql/backup-db.sh
Mart124 35a5dd95bb DB backups without cron (#608)
* Update backup-db.sh

* Update entrypoint.sh

* Update Dockerfile

* Delete crontab

* Update backup-db.sh

* don't bother with log files

all is already in /var/opt/mssql/log/errorlog

* Use gosu
2019-11-25 08:35:52 -05:00

21 lines
626 B
Bash

#!/bin/sh
while true
do
# Sleep until next day
[ "$1" == "loop" ] && sleep $((24 * 3600 - (`date +%H` * 3600 + `date +%M` * 60 + `date +%S`)))
# Backup timestamp
export now=$(date +%Y%m%d_%H%M%S)
# Do a new backup
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ${SA_PASSWORD} -i /backup-db.sql
# Delete backup files older than 30 days
grep -B1 "BACKUP DATABASE successfully" /var/opt/mssql/log/errorlog | grep -q _$now.BAK &&
find /etc/bitwarden/mssql/backups/ -mindepth 1 -type f -name '*.BAK' -mtime +32 -delete
# Break if called manually (without loop option)
[ "$1" != "loop" ] && break
done