Skip to content

Instantly share code, notes, and snippets.

@josefandersson
Last active September 16, 2020 11:39
Show Gist options
  • Save josefandersson/ad00ee55285d5ef458ab678fb2a9a37d to your computer and use it in GitHub Desktop.
Save josefandersson/ad00ee55285d5ef458ab678fb2a9a37d to your computer and use it in GitHub Desktop.
Script to backup Bitwarden data folder to another server using ssh and gpg encryption
#!/bin/bash
# Usage: script <bitwarden data directory> <gpg recipient> <ssh login@server>:<target folder>
# Example: script /home/alice/bwdata [email protected] [email protected]:~/backups/
# Note: Requires elevated permissions to read all files in bitwarden data folder
[ -z "$1" ] && echo "No data directory" && exit
[ -z "$2" ] && echo "No recipient" && exit
[ -z "$3" ] && echo "No backup server" && exit
output="/tmp/bwdata-$(date +"%Y%m%d-%H%M%S").tar.zip.gpg"
echo "Compressing data directory"
tar czfP /tmp/bwdata.tar.zip "$1"
echo "Encrypting tarball to recipient $2"
gpg --encrypt --recipient "$2" --output "$output" /tmp/bwdata.tar.zip
echo "Sending encrypted backup to $3"
scp "$output" "$3"
echo "Cleanup"
rm /tmp/bwdata.tar.zip
rm "$output"
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment