diff --git a/docker/docker-compose.linux.yml b/docker/docker-compose.linux.yml index 5120a49e2..76c9a5dee 100644 --- a/docker/docker-compose.linux.yml +++ b/docker/docker-compose.linux.yml @@ -3,7 +3,8 @@ version: '3' services: mssql: volumes: - - ../mssql_data:/var/opt/mssql/data + - ../mssql/data:/var/opt/mssql/data + - ../mssql/backups:/etc/bitwarden/mssql/backups env_file: - mssql.env - ../env/mssql.override.env diff --git a/docker/docker-compose.macwin.yml b/docker/docker-compose.macwin.yml index 1b761cb35..669941415 100644 --- a/docker/docker-compose.macwin.yml +++ b/docker/docker-compose.macwin.yml @@ -4,6 +4,7 @@ services: mssql: volumes: - mssql_data:/var/opt/mssql/data + - ../mssql/backups:/etc/bitwarden/mssql/backups env_file: - mssql.env - ../env/mssql.override.env diff --git a/scripts/bitwarden.ps1 b/scripts/bitwarden.ps1 index cf493451c..67ce0d549 100644 --- a/scripts/bitwarden.ps1 +++ b/scripts/bitwarden.ps1 @@ -8,6 +8,8 @@ param ( [string] $output = "" ) +$year = (Get-Date).year + Write-Host @' _ _ _ _ | |__ (_) |___ ____ _ _ __ __| | ___ _ __ @@ -18,7 +20,7 @@ Write-Host @' Write-Host " Open source password management solutions -Copyright 2015-${(Get-Date).year}, 8bit Solutions LLC +Copyright 2015-${year}, 8bit Solutions LLC https://bitwarden.com, https://github.com/bitwarden " diff --git a/util/MsSql/.dockerignore b/util/MsSql/.dockerignore index e46e7fae1..259542331 100644 --- a/util/MsSql/.dockerignore +++ b/util/MsSql/.dockerignore @@ -1,4 +1,5 @@ * !entrypoint.sh -!setup.sql -!setup.sh +!backup-db.sh +!backup-db.sql +!crontab diff --git a/util/MsSql/Dockerfile b/util/MsSql/Dockerfile index aebc5f597..b365b2c32 100644 --- a/util/MsSql/Dockerfile +++ b/util/MsSql/Dockerfile @@ -1,8 +1,17 @@ FROM microsoft/mssql-server-linux -COPY setup.sql / -COPY setup.sh / -RUN chmod +x /setup.sh +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + cron \ + && rm -rf /var/lib/apt/lists/* + +COPY crontab /etc/cron.d/bitwarden-cron +RUN chmod 0644 /etc/cron.d/bitwarden-cron \ + && touch /var/log/cron.log + +COPY backup-db.sql / +COPY backup-db.sh / +RUN chmod +x /backup-db.sh COPY entrypoint.sh / RUN chmod +x /entrypoint.sh diff --git a/util/MsSql/setup.sh b/util/MsSql/backup-db.sh similarity index 75% rename from util/MsSql/setup.sh rename to util/MsSql/backup-db.sh index 447abfbf0..cef5e22a2 100644 --- a/util/MsSql/setup.sh +++ b/util/MsSql/backup-db.sh @@ -1,4 +1,3 @@ #!/bin/sh -sleep 60s -/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ${SA_PASSWORD} -i /setup.sql +/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ${SA_PASSWORD} -i /backup-db.sql diff --git a/util/MsSql/backup-db.sql b/util/MsSql/backup-db.sql new file mode 100644 index 000000000..8da3041ca --- /dev/null +++ b/util/MsSql/backup-db.sql @@ -0,0 +1,13 @@ +DECLARE @TheDate NVARCHAR(20) +SET @TheDate = REPLACE(CONVERT(VARCHAR, GETDATE(),101),'/','') + '_' + REPLACE(CONVERT(VARCHAR, GETDATE(),108),':','') + +DECLARE @BackupFile varchar(100) +SET @BackupFile = '/etc/bitwarden/mssql/backups/vault_FULL_'+ @TheDate + '.BAK' + +DECLARE @BackupName varchar(100) +SET @BackupName = 'vault full backup for '+ @TheDate + +DECLARE @BackupCommand NVARCHAR(1000) +SET @BackupCommand = 'BACKUP DATABASE [vault] TO DISK = ''' + @BackupFile + ''' WITH INIT, NAME= ''' + @BackupName + ''', NOSKIP, NOFORMAT' + +EXEC(@BackupCommand) diff --git a/util/MsSql/crontab b/util/MsSql/crontab new file mode 100644 index 000000000..9b37cd04d --- /dev/null +++ b/util/MsSql/crontab @@ -0,0 +1,3 @@ +0 0 * * * root /backup-db.sh >> /var/log/cron.log 2>&1 + +# An empty line is required at the end of this file for a valid cron file. \ No newline at end of file diff --git a/util/MsSql/entrypoint.sh b/util/MsSql/entrypoint.sh index 31c85e404..564aa82b3 100644 --- a/util/MsSql/entrypoint.sh +++ b/util/MsSql/entrypoint.sh @@ -1,4 +1,5 @@ #!/bin/sh -/setup.sh & +env >> /etc/environment +cron /opt/mssql/bin/sqlservr diff --git a/util/MsSql/setup.sql b/util/MsSql/setup.sql deleted file mode 100644 index 659504758..000000000 --- a/util/MsSql/setup.sql +++ /dev/null @@ -1,6 +0,0 @@ -USE [master] -IF ((SELECT COUNT(1) FROM sys.databases WHERE [name] = 'vault') = 0) -BEGIN - CREATE DATABASE [vault] -END -GO