1
0
mirror of https://github.com/bitwarden/help synced 2025-12-31 07:33:36 +00:00
Files
help/_articles/hosting/backup-on-premise.md
fred_the_tech_writer 906e2ca0dd Promote to Master (#748)
* initial commit

* adding quotes for the array error

* Create Gemfile

* Create Gemfile.lock

* add .nvmrc and .node-version

* removed /article from URL

* update links to work with netlify

* more fixed links

* link fixes

* update bad links

* Update netlify.toml

toml test for redirects

* article redirect

* link fixes

* Update index.html

* Update netlify.toml

* Update _config.yml

* Update netlify.toml

* Update netlify.toml

* Update netlify.toml

* Update netlify.toml

* Update netlify.toml

* add article back into URL for launch

* Update netlify.toml

* Update netlify.toml

* add order to categories front matter

* Update netlify.toml

* update

* sidemenu update

* Revert "sidemenu update"

This reverts commit 5441c3d35c.

* update order prop

* Navbar updates per Gary and compiler warnings

* font/style tweaks

* Update sidebar.html

* Stage Release Documentation (#739)

* initial drafts

* rewrite Custom Fields article to prioritize new context-menu option & better organize ancillary information

* edit

* edit

* Custom Field Context Menu & CAPTCHA item in release notes

* SSO relink event

* update rn

* small edits

* improve release notes titles

* fix side menu

* Edits courtest of mportune!

* update order

* link fixes

* link cleanup

* image updates and a link

* fix trailing slash

Co-authored-by: DanHillesheim <79476558+DanHillesheim@users.noreply.github.com>
2021-09-21 13:21:11 -04:00

89 lines
3.7 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
layout: article
title: Backup your Hosted Data
categories: [hosting]
featured: false
popular: false
tags: [hosting, docker, backup]
order: "07"
---
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]({{site.baseurl}}/article/install-on-premise/#install-bitwarden).
## 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 `mssql` database 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.
1. Retrieve your database password from the `globalSettings__sqlServer__connectionString=...Password=` value found in `global.override.env`.
2. Identify the Container ID of the `mssql` container using the `docker ps` command.
3. Run the following commmand to open a bash session for your `mssql` docker container:
```
docker exec -it bitwarden-mssql /bin/bash
```
Your command prompt should now match the identified Container ID of the `bitwarden-mssql` container.
4. 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/backups` on the host machine maps to `etc/bitwarden/mssql/backups` in the container.
{% endcallout %}
For example, a file `/etc/bitwarden/mssql/backups/vault_FULL_20201208_003243.BAK` is a backup taken on December 08, 2020 at 12:32am.
5. Start the `sqlcmd` Utility with the following command:
```
/opt/mssql-tools/bin/sqlcmd -S localhost -U <sa> -P <sa-password>
```
where `<sa>` and `<sa-password>` match the `User=` and `Password=` values found in `global.override.env`.
6. Once in the `sqlcmd` Utility, you have 2 options for backup:
1. **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> exit
```
Restart your Bitwarden instance to finish restoring.
2. **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> GO
```
Restart your Bitwarden instance to finish restoring.