Restore SQL from Backup

Self-hosted Bitwarden has an automated backup feature that’s described in this help document.

However, the document doesn’t give specific details on how to restore the SQL database. Instead it just gives a link to a Microsoft document that provides generic info.

Does anybody have specific instructions on how to restore the SQL database in Docker running under Windows?

Thanks,

Rob

Hi robpur, I was working on the same thing today. Here’s what I came up with (on Docker for OS X, though I don’t think that will make a difference). You can find your SA password needed for the commands below in bwdata/env/mssql.override.env.

Use docker and the sqlcmd CLI to restore from a backup like so:

docker exec -it bitwarden-mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P '<YOUR_SA_PASSWORD>' -Q "RESTORE DATABASE vault FROM DISK = '/etc/bitwarden/mssql/backups/vault.bak' WITH REPLACE";

You can also list the files in a backup:

docker exec -it bitwarden-mssql /opt/mssql-tools/bin/sqlcmd -S localhost \
-U SA -P '<YOUR_SA_PASSWORD>' \
-Q 'RESTORE FILELISTONLY FROM DISK = "/etc/bitwarden/mssql/backups/vault_FULL_20190828_235901.BAK"' \
| tr -s ' ' | cut -d ' ' -f 1-2

Or make manual backups (haven’t yet found a way to customise the automated backups):

docker exec -it bitwarden-mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P '<YOUR_SA_PASSWORD>' -Q "BACKUP DATABASE vault TO DISK = '/etc/bitwarden/mssql/backups/vault_backup.bak' WITH STATS=10";

Hope any of this helps!

Kind regards,

Daniël

Sources:

I’m having an issue where mssql is crashing repeatedly. I want to try restoring a backup to see if that helps, but with the container not running I can’t run any such docker commands.

Any advice on how to proceed ?