Skip to content

Instantly share code, notes, and snippets.

@cblte
Last active January 30, 2022 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cblte/9fee56eee54181573b6367bea64190dc to your computer and use it in GitHub Desktop.
Save cblte/9fee56eee54181573b6367bea64190dc to your computer and use it in GitHub Desktop.
#!/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