Skip to content

Instantly share code, notes, and snippets.

@meinside
Created February 17, 2023 00:00
Show Gist options
  • Save meinside/42b7f48be9b2aee90aec90e8d155e784 to your computer and use it in GitHub Desktop.
Save meinside/42b7f48be9b2aee90aec90e8d155e784 to your computer and use it in GitHub Desktop.
Backup script for Vaultwarden
#!/usr/bin/env bash
# backup_vaultwarden.sh
#
# Backups up `db.sqlite3` and `attachments` from vaultwarden.
#
# last update: 2023.02.16.
# XXXX: edit following values
VAULTWARDEN_WORKING_DIR="/home/me/my-files/vaultwarden"
BACKUP_DIR="/home/me/my-files/backups/vaultwarden"
function prep {
mkdir -p "$BACKUP_DIR" && cd "$VAULTWARDEN_WORKING_DIR"
}
function backup_db {
now=$1
db="${VAULTWARDEN_WORKING_DIR}/data/db.sqlite3"
echo "> backing up database: ${db}"
sqlite3 "${db}" "VACUUM INTO '${BACKUP_DIR}/db-${now}.sqlite3'"
}
function backup_attachments {
now=$1
dir="${VAULTWARDEN_WORKING_DIR}/data/attachments"
if [ -d "${dir}" ]; then
echo "> backing up attachments dir: ${dir}"
cp -R "$dir" "${BACKUP_DIR}/attachments-${now}"
fi
}
# do the actual job
(
now=$(date '+%Y-%m-%d_%H%M')
echo "> backing up vaultwarden at: ${VAULTWARDEN_WORKING_DIR}, timestamp: ${now}"
prep && backup_db $now && backup_attachments $now
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment