Skip to content

Instantly share code, notes, and snippets.

@athphane
Created June 12, 2022 17:08
Show Gist options
  • Save athphane/d2d9538e674e43675fecc9f107d9d998 to your computer and use it in GitHub Desktop.
Save athphane/d2d9538e674e43675fecc9f107d9d998 to your computer and use it in GitHub Desktop.
Bash script to zip up Vaultwarden data directory and upload to Cloud storage.
#!/bin/bash
#edit these to your config
BWDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
DATETIME="$(date +'%Y-%m-%d_%H-%M-%S')"
FOLDERPATH="$(date +'%Y-%m-%d')"
GZFILE=bitwarden-${DATETIME}.tar.gz
#change working dir to /tmp
cd /tmp/
# Compress Vaultwarden directory to gzfile
tar -Pczf $GZFILE $BWDIR
# Copy the file to an Rclone storage endpoint
rclone copy $GZFILE MyGoogleDrive:/bitwarden_backups/${FOLDERPATH}/
#remove temp file
rm $GZFILE
@athphane
Copy link
Author

Above is the script. And to automate this, just add the following line to your Crontab.

0 */3 * * * ~/docker/bitwarden_rs/backup-script.sh

You can adjust your crontab timings as necessary.

In the process of publishing this script I found out that my script had not been backing up since January 2022. Well dang. Had to update the rclone config for the Google Drive mount.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment