1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

Allow users to specify BACKUP_DB_FILENAME for MSSQL DB backups

Rename variables to match the rest. Also:

Allow users to specify both $BACKUP_DB_FILENAME and $BACKUP_DB_FILENAME_SUFFIX

backup-db.sh minor syntax fix
This commit is contained in:
Haneef 2021-11-17 23:50:02 +00:00
parent c4a6c1801f
commit da349a7b4f
No known key found for this signature in database
GPG Key ID: CBCCCDB9AEC067E4
2 changed files with 6 additions and 5 deletions

View File

@ -13,18 +13,19 @@ do
# Backup timestamp
export now=$(date +%Y%m%d_%H%M%S)
export BACKUP_FILENAME="${now}${BACKUP_FILENAME_SUFFIX}"
BACKUP_DB_FILENAME=${BACKUP_DB_FILENAME:-"${now}"}
export BACKUP_DB_FILENAME="${BACKUP_DB_FILENAME}${BACKUP_DB_FILENAME_SUFFIX}"
# 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 _${BACKUP_FILENAME}.BAK &&
grep -B1 "BACKUP DATABASE successfully" /var/opt/mssql/log/errorlog | grep -q _${BACKUP_DB_FILENAME}.BAK &&
find $BACKUP_DB_DIR -mindepth 1 -type f -name '*.BAK' -mtime +32 -delete
# Common variables used in the next two if blocks.
DATABASE=${DATABASE:-'vault'}
BACKUP_DB_LATEST_FILENAME="${DATABASE}_FULL_${BACKUP_FILENAME}.BAK"
BACKUP_DB_LATEST_FILENAME="${DATABASE}_FULL_${BACKUP_DB_FILENAME}.BAK"
# Make a copy (overwrite) with a consistent filename.
# Helps when taking snapshots with deduplication algorithms e.g. restic

View File

@ -7,10 +7,10 @@ DECLARE @DatabaseNameSafe varchar(100)
SET @DatabaseNameSafe = 'vault'
DECLARE @BackupFile varchar(100)
SET @BackupFile = '$(BACKUP_DB_DIR)' + @DatabaseNameSafe + '_FULL_$(BACKUP_FILENAME).BAK'
SET @BackupFile = '$(BACKUP_DB_DIR)' + @DatabaseNameSafe + '_FULL_$(BACKUP_DB_FILENAME).BAK'
DECLARE @BackupName varchar(100)
SET @BackupName = @DatabaseName + ' full backup for $(BACKUP_FILENAME)'
SET @BackupName = @DatabaseName + ' full backup for $(BACKUP_DB_FILENAME)'
DECLARE @BackupCommand NVARCHAR(1000)
SET @BackupCommand = 'BACKUP DATABASE [' + @DatabaseName + '] TO DISK = ''' + @BackupFile + ''' WITH INIT, NAME= ''' + @BackupName + ''', NOSKIP, NOFORMAT'