Bash docker image that exports your Bitwarden or Vaultwarden vault contents for backup.
50K+
Your vault holds every password you have. Bitwarden_Export keeps an encrypted copy of it on your own disk — passwords, organizations and attachments — day after day, without you having to remember. Set it up once, and it tells you if a backup ever fails.
ENCRYPT_ATTACHMENTS (details).ps (details).KEEP_LAST_BACKUPS, or daily/weekly/monthly with KEEP_GFS (details).CRON (details).restart: on-failure, cron and orchestrators see a failed backup as a failure.Failed to unlock vault with BW_PASSWORD even though the password is right (vaultwarden#7693). bitwarden.com is not affected.Copy docker-compose.yml from this repository, fill in the three credentials and the export password, and run it:
services:
bw-export:
container_name: bw-export
image: 0netx/bw-export:latest
volumes:
- ./export/data:/var/data
- ./export/attachments:/var/attachments
environment:
- BW_CLIENTID=<CLIENT ID FROM BITWARDEN API>
- BW_CLIENTSECRET=<CLIENT SECRET FROM BITWARDEN API>
- BW_PASSWORD=<BITWARDEN PASSWORD>
- EXPORT_PASSWORD=<EXPORT PASSWORD>
# Server: leave commented out for bitwarden.com.
# - BW_URL_SERVER=https://vault.example.com
The file lists every other option, commented out.
docker compose up
The container performs one export and exits with the export's status code.
If you want the container to stay running and run backups on a schedule (for example daily at 03:00), use docker-compose.cron.sample.yml:
services:
bw-export:
container_name: bw-export
image: 0netx/bw-export:latest
restart: unless-stopped
volumes:
- ./export/data:/var/data
- ./export/attachments:/var/attachments
environment:
- BW_CLIENTID=<CLIENT ID FROM BITWARDEN API>
- BW_CLIENTSECRET=<CLIENT SECRET FROM BITWARDEN API>
- BW_PASSWORD=<BITWARDEN PASSWORD>
- EXPORT_PASSWORD=<EXPORT PASSWORD>
# Server: leave commented out for bitwarden.com.
# - BW_URL_SERVER=https://vault.example.com
- CRON=0 3 * * *
- TZ=Europe/Madrid
- KEEP_LAST_BACKUPS=5
- FILE_LOG=/var/data/bw-export-logfile.log
docker compose -f docker-compose.cron.sample.yml up -d
The container validates the CRON expression, runs an initial backup immediately on startup, and keeps running to execute scheduled backups.
docker rundocker run --name bw-export \
-v ./export/data:/var/data \
-v ./export/attachments:/var/attachments \
-e BW_CLIENTID=<CLIENT ID FROM BITWARDEN API> \
-e BW_CLIENTSECRET=<CLIENT SECRET FROM BITWARDEN API> \
-e BW_PASSWORD=<BITWARDEN PASSWORD> \
-e EXPORT_PASSWORD=<EXPORT PASSWORD> \
0netx/bw-export:latest
The script can also be run directly from a terminal, which prompts for what it needs:
bash bw_export.sh
Each example is a complete compose file. They go from the simplest to the most complete; start with the first and move on when you need what the next one adds.
| File | What it adds | Start with |
|---|---|---|
docker-compose.yml | One backup, then exit. Lists every option, commented out. | docker compose up |
docker-compose.cron.sample.yml | Backups on a schedule, with retention. See Scheduling. | docker compose -f docker-compose.cron.sample.yml up -d |
docker-compose.secrets.sample.yml | Credentials as Docker secrets. See Option A. | docker compose -f docker-compose.secrets.sample.yml up |
docker-compose.multi.sample.yml | Several accounts, on bitwarden.com or self-hosted servers, each into a subfolder. See Several vaults. | docker compose -f docker-compose.multi.sample.yml up |
docker-compose.infisical.sample.yml | Credentials from Infisical. See Option B. | docker compose -f docker-compose.infisical.sample.yml up |
docker-compose.hardened.sample.yml | Schedule and secrets, without root, capabilities or a writable image. See Hardened setup. | docker compose -f docker-compose.hardened.sample.yml up -d |
docker-compose.offsite.sample.yml | A second copy off the host with an rclone sidecar. See Off-site copy. | docker compose -f docker-compose.offsite.sample.yml up -d |
compose.podman.yml | Not standalone: an override for rootless Podman, added to any of the above. See Rootless Podman. | podman compose -f docker-compose.yml -f compose.podman.yml up |
All of them write the exports to ./export/data and the attachments to ./export/attachments, next to the compose file, and leave BW_URL_SERVER commented out, which means bitwarden.com.
Every run writes a dated folder, <DateTime>-bw-export, into the output path:
EXPORT_PASSWORD is set — recommended),attachments.tar.gz.gpg when ENCRYPT_ATTACHMENTS is on.
Each subfolder is named after its item. Items that share a name get their short ID appended, Passport (1a2b3c4d), and so do attachments that share a name within an item, scan (9f8e7d6c).pdf, so that none overwrites another. Names are compared ignoring case, as on Windows and macOS.The log ends with a summary of the run, which is also what the notification carries:
----- Summary -----
Duration: 41s
Personal vault: exported (encrypted)
Organizations: 1 exported, 1 skipped, 0 failed
Attachments: 14 saved, 0 failed (encrypted archive)
Backup size: 3.2MiB
Old backups deleted: 1
-------------------
The Bitwarden CLI cannot export items in your Trash or your password history, so neither is included.
Everything is set through environment variables. Only the three credentials are required; every other variable has a default that works, and the tables below give it.
Any variable that carries a secret (BW_CLIENTID, BW_CLIENTSECRET, BW_PASSWORD, EXPORT_PASSWORD, NOTIFICATION_URL, PING_URL, INFISICAL_TOKEN) can be given instead as NAME_FILE, the path of a file holding it, so that docker inspect does not show it. Set only one of the two: for the credentials, both set stops the run. See Option A: Docker secrets.
| Variable | Description |
|---|---|
BW_CLIENTID | The client_id of your personal API key. |
BW_CLIENTSECRET | The client_secret of that API key. |
BW_PASSWORD | Your Bitwarden/Vaultwarden master password. |
With several vaults, these go in each vault's own variables (VAULT_<NAME>_BW_CLIENTID, …) instead.
| Variable | Description |
|---|---|
EXPORT_PASSWORD | Encrypts the export files. Use a strong password you can remember, and do not store it only inside Bitwarden: if you get locked out of your account you could not decrypt your own backups. Left unset, the exports are written in plain text. |
PUID / PGID | The host user and group the export runs as and the files belong to. Without them the export runs as root. See PUID and PGID. |
| Variable | Default | Description |
|---|---|---|
BW_URL_SERVER | bitwarden.com | URL of your self-hosted Vaultwarden/Bitwarden server. Must be HTTPS. |
BW_ORGANIZATIONS_LIST | every organization you own or administer | Comma-separated organization IDs to export, or none to export no organization. |
BW_VAULTS | — (one vault) | Comma-separated names of several vaults to export in one run, each configured with VAULT_<NAME>_… variables. See Several vaults. |
| Variable | Default | Description |
|---|---|---|
OUTPUT_PATH | /var/data/ | Where the vault exports are written. The path must exist in the container, normally as a mounted volume. |
ATTACHMENTS_PATH | /var/attachments/ | Where the attachments are written, same condition. |
KEEP_LAST_BACKUPS | keep everything | Keep only the N newest export folders, delete the rest. See Retention. |
KEEP_GFS | — | Keep the newest export of each recent day, week, month and year, e.g. 7d:4w:6m. Can be combined with KEEP_LAST_BACKUPS. See Retention. |
| Variable | Default | Description |
|---|---|---|
ENCRYPT_ATTACHMENTS | false | true packs the attachments into one archive encrypted with EXPORT_PASSWORD, which must then be set. See Encrypted attachments. |
BACKUP_PERMISSIONS | default | private makes each run's folders 700 and its files 600, so only their owner can read them. See Permissions of the backups. |
| Variable | Default | Description |
|---|---|---|
CRON | — (one backup, then exit) | When to back up: a standard 5-field expression such as 0 3 * * * (supercronic's extended 6- and 7-field forms work too) or a macro: @hourly, @daily, @midnight, @weekly, @monthly, @yearly, @annually. Anything else stops the container at start. The container then stays up, backs up once at start and at every scheduled time, and skips a run while the previous one is still going. Set restart: unless-stopped. See Scheduling. |
TZ | UTC | Timezone for the log and for CRON, e.g. Europe/Madrid. |
FILE_LOG | inside the container only | Path of a log file, e.g. /var/data/bw-export-logfile.log. Put it in a mounted volume or it is lost with the container. Each run overwrites it; with CRON, runs are appended instead and the file is rotated to <FILE_LOG>.1 once it reaches FILE_LOG_MAX_BYTES. |
FILE_LOG_MAX_BYTES | 104857600 (100 MiB) | Size at which the CRON log is rotated. |
| Variable | Default | Description |
|---|---|---|
NOTIFICATION_URL | — | Shoutrrr URL for the start, success and failure messages. See Notifications. |
NOTIFICATION_LEVEL | all | failure sends a message only when a run fails. |
PING_URL | — | Watchdog endpoint (healthchecks, uptime-kuma, …) pinged at start and on completion. See Monitoring. |
| Variable | Default | Description |
|---|---|---|
INFISICAL_TOKEN | — | Infisical service token: the credentials and EXPORT_PASSWORD are then read from Infisical. See Option B. |
INFISICAL_PATH | the token's own path | Secrets Path to read. A service token always applies its own scope, so this rarely needs setting. |
Rarely needed; the defaults suit almost every setup.
| Variable | Default | Description |
|---|---|---|
NODE_EXTRA_CA_CERTS | — | Path of a PEM file with an extra certificate authority to trust, for a self-hosted server whose certificate is signed by your own CA. Mount the file and point this at it, e.g. /certs/ca.crt. |
BITWARDENCLI_APPDATA_DIR | /app/data, or $TMPDIR/bitwarden-cli without root | Where the Bitwarden CLI keeps its session while a run is logged in. With BW_VAULTS, each vault uses <this>/vaults/<name>. |
TMPDIR | /tmp | Temporary folder. Without root it also holds the CLI's session and the default log, and with ENCRYPT_ATTACHMENTS one run's attachments before they are encrypted, so it must fit them. |
Other variables you may find in the scripts (ADDUSER_BIN, APP_DIR, LOG_LIB and the other *_LIB, SHOUTRRR_BIN, …) exist so the test suites can run the scripts outside the image. They are not settings and may change without notice.
| Path | Contents |
|---|---|
/var/data | Vault exports. |
/var/attachments | Attachments. |
One container can back up several accounts, on bitwarden.com or on different self-hosted servers. List them in BW_VAULTS and give each one its settings with its name in capitals after VAULT_:
environment:
- BW_VAULTS=personal,work
- VAULT_PERSONAL_BW_CLIENTID=<client id>
- VAULT_PERSONAL_BW_CLIENTSECRET=<client secret>
- VAULT_PERSONAL_BW_PASSWORD=<master password>
- VAULT_WORK_BW_URL_SERVER=https://vault.example.com
- VAULT_WORK_BW_CLIENTID=<client id>
- VAULT_WORK_BW_CLIENTSECRET=<client secret>
- VAULT_WORK_BW_PASSWORD_FILE=/run/secrets/work_password
- EXPORT_PASSWORD=<export password> # for every vault without its own
See docker-compose.multi.sample.yml.
Names may use letters, digits and _, because they become part of variable names. Each vault writes into a subfolder named after it in lower case: /var/data/personal/<DateTime>-bw-export and /var/attachments/personal/….
Credentials and server belong to each vault and are never shared: BW_CLIENTID, BW_CLIENTSECRET, BW_PASSWORD (or their _FILE forms) and BW_URL_SERVER. Without a server, a vault uses bitwarden.com.
These options apply to every vault unless a vault sets its own: EXPORT_PASSWORD (or EXPORT_PASSWORD_FILE), BW_ORGANIZATIONS_LIST, ENCRYPT_ATTACHMENTS, BACKUP_PERMISSIONS, KEEP_LAST_BACKUPS and KEEP_GFS. An empty value turns an option off for that vault, e.g. VAULT_WORK_KEEP_GFS=.
Everything else is shared by the whole run: CRON, TZ, FILE_LOG, the notification, PING_URL, PUID/PGID and Infisical.
One mode or the other. With BW_VAULTS, setting BW_CLIENTID, BW_CLIENTSECRET, BW_PASSWORD or BW_URL_SERVER without a prefix is an error and nothing is exported. A VAULT_ variable that matches no vault, such as a typo, is reported as a warning.
The vaults are exported one after another, each with its own CLI session. A vault that fails does not stop the others, and the run then exits 1.
One notification and one ping cover the whole run. The summary has a line per vault with its duration and size, and leaves out counts that are 0:
Vaults: 1 of 2 failed, 1 exported, in 19s
✅ personal (7s, 772KiB)
Personal vault: exported (encrypted)
Organizations: 1 exported
Attachments: none
❌ work (failed with exit 1, 12s, 0B)
Personal vault: FAILED
Organizations: 2 failed
Attachments: none
Without BW_VAULTS nothing changes: the single vault is configured as before and writes straight into /var/data.
This container automates the official Bitwarden CLI. It does not save, trace or store any information of its own, and the CLI session is closed once the backup is done.
Any user on the host can read the command line of any process with ps, including processes inside a container, under Docker as under Podman. So the script never passes a password as an argument:
BW_PASSWORD) reaches bw unlock through an environment variable (--passwordenv), which only the process owner and root can read;EXPORT_PASSWORD) reaches bw export through stdin, answering the CLI's own prompt. That prompt is kept out of the log, since it is redrawn once per character and would give away the password's length.Nothing has to be configured for this. Each of the six secret-carrying variables (BW_CLIENTID, BW_CLIENTSECRET, BW_PASSWORD, EXPORT_PASSWORD, NOTIFICATION_URL and PING_URL) also has a _FILE variant, such as BW_PASSWORD_FILE, that holds the path of a file with the value: the convention of the official Docker images (POSTGRES_PASSWORD_FILE and the like). With files, the container's configuration holds only paths, so docker inspect shows no secret. A value is read only when it is used, and handed only to the program that needs it.
NAME_FILE is always a path. A file that does not exist, cannot be read or is empty is reported: for a credential the run stops, and a notification or ping URL is skipped with a warning. Setting both NAME and NAME_FILE is the same kind of error.NAME keeps working as before: the value itself, or the path of a file holding it. A path under /run/secrets that does not exist is treated as a secret that was not mounted, never as a literal value.EXPORT_PASSWORD or EXPORT_PASSWORD_FILE is set but no password can be read from it, the run fails: the vault is never exported unencrypted in its place.mkdir -p ./.secrets && chmod 700 ./.secrets
echo '<client id>' > ./.secrets/.bwclientid
echo '<client secret>' > ./.secrets/.bwsecret
echo '<master password>' > ./.secrets/.bwpassword
echo '<export password>' > ./.secrets/.exportpassword
# Optional, only if you use them:
echo '<shoutrrr url>' > ./.secrets/.notificationurl
echo '<ping url>' > ./.secrets/.pingurl
chmod 400 ./.secrets/.*
The notification and ping secrets are optional. Leave their lines commented out unless you created their files: Compose refuses to start with a secret whose file does not exist.
services:
bw-export:
container_name: bw-export
image: 0netx/bw-export:latest
volumes:
- ./export/data:/var/data
- ./export/attachments:/var/attachments
environment:
- BW_CLIENTID_FILE=/run/secrets/bwclientid
- BW_CLIENTSECRET_FILE=/run/secrets/bwsecret
- BW_PASSWORD_FILE=/run/secrets/bwpassword
- EXPORT_PASSWORD_FILE=/run/secrets/exportpassword
# Optional:
# - NOTIFICATION_URL_FILE=/run/secrets/notificationurl
# - PING_URL_FILE=/run/secrets/pingurl
secrets:
- bwclientid
- bwsecret
- bwpassword
- exportpassword
# - notificationurl
# - pingurl
secrets:
bwclientid:
file: ./.secrets/.bwclientid
bwsecret:
file: ./.secrets/.bwsecret
bwpassword:
file: ./.secrets/.bwpassword
exportpassword:
file: ./.secrets/.exportpassword
# notificationurl:
# file: ./.secrets/.notificationurl
# pingurl:
# file: ./.secrets/.pingurl
Mount /var/data and /var/attachments separately, never a parent such as /var: the image declares both as volumes, so Docker would put anonymous volumes over them and the exports would never reach your folder.
See docker-compose.secrets.sample.yml. Reference: Docker secrets in Compose.
Create a free Infisical account and a project.
Add the secrets BW_CLIENTID, BW_CLIENTSECRET, BW_PASSWORD and, optionally, EXPORT_PASSWORD.

Create a service token under Project → Access Control → Service Tokens, with the name and Secrets Path you need.

Set INFISICAL_TOKEN to that token, then start the container as usual. INFISICAL_PATH is optional: the token's own Secrets Path always applies (see below).

See also docker-compose.infisical.sample.yml.
Important
A service token carries its own environment and *Secrets Path*, and Infisical always applies them: `INFISICAL_PATH` cannot point a token anywhere else, and a wrong value is not reported as an error. If a run uses the wrong secrets, check the token's scope in Infisical, not `INFISICAL_PATH`.When a variable is set both in the compose file and in Infisical, the Infisical value wins.
If the secrets cannot be fetched, the container exits with code 1 and, when notifications are on, sends a message carrying Infisical's own error.
Set NOTIFICATION_URL to any Shoutrrr service URL and you get a message when the run starts, succeeds or fails. Both outcomes carry the run summary (duration, what was exported, organizations skipped, attachments saved, size), so a drop in the numbers shows without opening the log; a failure also carries the last lines of the log. The
Content type
Image
Digest
sha256:6d792f12d…
Size
166.5 MB
Last updated
7 days ago
docker pull 0netx/bw-export