1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-21 12:05:42 +01:00

sql backups

This commit is contained in:
Kyle Spearrin 2017-08-21 10:58:00 -04:00
parent 371942e3e2
commit 2cfea467d1
10 changed files with 40 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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
"

View File

@ -1,4 +1,5 @@
*
!entrypoint.sh
!setup.sql
!setup.sh
!backup-db.sh
!backup-db.sql
!crontab

View File

@ -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

View File

@ -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

13
util/MsSql/backup-db.sql Normal file
View File

@ -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)

3
util/MsSql/crontab Normal file
View File

@ -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.

View File

@ -1,4 +1,5 @@
#!/bin/sh
/setup.sh &
env >> /etc/environment
cron
/opt/mssql/bin/sqlservr

View File

@ -1,6 +0,0 @@
USE [master]
IF ((SELECT COUNT(1) FROM sys.databases WHERE [name] = 'vault') = 0)
BEGIN
CREATE DATABASE [vault]
END
GO