2017-08-19 00:22:25 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2019-11-25 14:35:52 +01:00
|
|
|
while true
|
|
|
|
do
|
|
|
|
# Sleep until next day
|
2019-11-25 16:36:06 +01:00
|
|
|
[ "$1" = "loop" ] && sleep $((24 * 3600 - (`date +%H` * 3600 + `date +%M` * 60 + `date +%S`)))
|
2017-08-30 05:05:52 +02:00
|
|
|
|
2019-11-25 14:35:52 +01:00
|
|
|
# Backup timestamp
|
|
|
|
export now=$(date +%Y%m%d_%H%M%S)
|
2018-05-29 14:17:43 +02:00
|
|
|
|
2019-11-25 14:35:52 +01:00
|
|
|
# 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
|