depot/third_party/nixpkgs/nixos/modules/services/security/vaultwarden/backup.sh
Default email 98eb3e9ef5 Project import generated by Copybara.
GitOrigin-RevId: 00d80d13810dbfea8ab4ed1009b09100cca86ba8
2024-07-01 15:47:52 +00:00

21 lines
620 B
Bash

#!/usr/bin/env bash
# Allow use of !() when copying to not copy certain files
shopt -s extglob
# Based on: https://github.com/dani-garcia/vaultwarden/wiki/Backing-up-your-vault
if [ ! -d "$BACKUP_FOLDER" ]; then
echo "Backup folder '$BACKUP_FOLDER' does not exist" >&2
exit 1
fi
if [[ -f "$DATA_FOLDER"/db.sqlite3 ]]; then
sqlite3 "$DATA_FOLDER"/db.sqlite3 ".backup '$BACKUP_FOLDER/db.sqlite3'"
fi
if [ ! -d "$DATA_FOLDER" ]; then
echo "No data folder (yet). This will happen on first launch if backup is triggered before vaultwarden has started."
exit 0
fi
cp -r "$DATA_FOLDER"/!(db.*) "$BACKUP_FOLDER"/