3.7 KiB
layout, title, categories, featured, popular, tags, order
| layout | title | categories | featured | popular | tags | order | ||||
|---|---|---|---|---|---|---|---|---|---|---|
| article | Backup your Hosted Data |
|
false | false |
|
08 |
When self-hosting Bitwarden, you are responsible for implementing your own backup procedures in order to keep data safe.
About Hosted Data
Bitwarden's Docker containers use volume mapping to persist all important data on the host machine, meaning stopping your containers will not delete any data. Docker containers, on the other hand, are to be considered ephemeral and do not persist data or state.
All Bitwarden data is stored on the host machine in the ./bwdata directory, relative to the location in which you installed Bitwarden. For more information, see Install and Deploy.
Backup Hosted Data
It's recommended that you backup and keep safe the entire ./bwdata directory. In the event of data loss, you will need all or parts of the data contained in this directory to restore your instance.
Particularly important pieces of ./bwdata to backup regularly include:
-
./bwdata/env- Instance's environment variables, including database and certificate passwords. -
./bwdata/core/attachments- Instance's Vault item attachments. -
./bwdata/mssql/data- Instance's database data.Bitwarden will automatically take nightly backups of the
mssqldatabase container, when running.
Nightly Database Backups
Bitwarden will automatically take nightly backups of the mssql container database. These backups are kept in the ./bwdata/mssql/backups directory for 30 days.
In the event of data loss, you can use ./bwdata/mssql/backups to restore a nightly backup.
Restore a Nightly Backup
In the event of data loss, complete the following steps to restore a nightly backup.
-
Retrieve your database password from the
globalSettings__sqlServer__connectionString=...Password=value found inglobal.override.env. -
Identify the Container ID of the
mssqlcontainer using thedocker pscommand. -
Run the following commmand to open a bash session for your
mssqldocker container:docker exec -it bitwarden-mssql /bin/bashYour command prompt should now match the identified Container ID of the
bitwarden-mssqlcontainer. -
In the container, locate the backup file you wish to restore.
{% callout info %}The backup directory in the container is volume-mapped from the host directory.
./bwdata/mssql/backupson the host machine maps toetc/bitwarden/mssql/backupsin the container. {% endcallout %}For example, a file
/etc/bitwarden/mssql/backups/vault_FULL_20201208_003243.BAKis a backup taken on December 08, 2020 at 12:32am. -
Start the
sqlcmdUtility with the following command:/opt/mssql-tools/bin/sqlcmd -S localhost -U <sa> -P <sa-password>where
<sa>and<sa-password>match theUser=andPassword=values found inglobal.override.env. -
Once in the
sqlcmdUtility, you have 2 options for backup:-
Offline Restore (Preferred)
Run the following SQL commands:
1> use master 2> GO 1> alter database vault set offline with rollback immediate 2> GO 1> restore database vault from disk='/etc/bitwarden/mssql/backups/vault_FULL_{Backup File Name}.BAK' with replace 2> GO 1> alter database vault set online 2> GO 1> exitRestart your Bitwarden instance to finish restoring.
-
Online Restore
Execute the following SQL commands:
1> RESTORE DATABASE vault FROM DISK = '/etc/bitwarden/mssql/backups/vault_FULL_20200302_235901.BAK' WITH REPLACE 2> GORestart your Bitwarden instance to finish restoring.
-