Skip to content

Instantly share code, notes, and snippets.

@janlay
Last active April 7, 2021 08:52
Show Gist options
  • Save janlay/540dd5da1f914cce763af90981fa1ba7 to your computer and use it in GitHub Desktop.
Save janlay/540dd5da1f914cce763af90981fa1ba7 to your computer and use it in GitHub Desktop.
Backup Bitwarden Data
#!/bin/bash
set -e
# Backup db and certs in $BITWARDEN_DIR into $TARGET_DIR/$FILENAME_PREFIX$DATE.tar.gz
BITWARDEN_DIR='/volume1/docker/Bitwarden'
TARGET_DIR='/var/services/dropbox/Backup/Bitwarden'
FILENAME_PREFIX='bw-backup_'
FILENAME_DATE_PATTERN='%m-%d'
TEMP_DIR=$(mktemp -d)
cleanup() {
rm -rf "$TEMP_DIR"
}
main() {
# backup db
sqlite3 "$BITWARDEN_DIR/db.sqlite3" ".backup '$TEMP_DIR/db.sqlite3'"
# backup certs
cp "$BITWARDEN_DIR"/rsa_* "$TEMP_DIR"
# pack files
local backup_file="$TARGET_DIR/$FILENAME_PREFIX$(date +"$FILENAME_DATE_PATTERN").tar.gz"
tar -czf "$backup_file" -C "$TEMP_DIR" .
}
trap cleanup EXIT
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment