Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
# This script will stop the service, backup the data folder including
# the database, the attachments and keys of your vaultwarden installation.
# Only the last 14 backups will be kept. If you want to keep more or less, please
# adjust the time on the last line of the script
# for this script to work to work adjust the following 4 folders to your environment
# timestamp added to the backup filename e.g. 20220130-1325
NOW=$(date +'%Y%m%d-%H%M')
# the backup dir where you want to store the backups
BACKUP_DIR="$HOME/backups/vaultwarden-backups"
# name of the backup file
BACKUP_ZIP="vw-backup-$NOW.tgz"
# folder of your vaultwarden installation
VW_DIR="$HOME/vaultwarden/output"
# the name of the vaultwarden service
VW_SERVICE="vaultwarden"
#-----------------------------------------------
# stop the service
supervisorctl stop ${VW_SERVICE}
# create an archive in the backup folder
cd ${VW_DIR}
tar -czf ${BACKUP_DIR}/${BACKUP_ZIP} .env data
cd -
# start service again
supervisorctl start ${VW_SERVICE}
# Delete files older than 14 days
find $BACKUP_DIR -type f -mtime +13 -name \*.tgz -exec rm {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment