Last active
February 14, 2026 17:01
-
-
Save fsmv/af6bfc336898e010e0e2957cafa3667c to your computer and use it in GitHub Desktop.
Auto update and backup scripts for Vaultwarden without docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # You probably want to change the killall and running ./vaultwarden & | |
| # commands to run the service in this script. Most people prefer systemd. | |
| # I run this with cron as the vaultwarden user so I get unix mail with the | |
| # prints (e.g. if it crashed from broken dependencies or something). | |
| # | |
| # before you run this you need to: | |
| # | |
| # git clone https://github.com/dani-garcia/bw_web_builds | |
| # git clone https://github.com/dani-garcia/vaultwarden vaultwarden.git | |
| cd bw_web_builds | |
| git fetch --tags | |
| LATEST=`git tag --sort=version:refname | tail -1` | |
| CURRENT=`git describe --exact-match --tags` | |
| cd .. | |
| if [ "$LATEST" != "$CURRENT" -o "$1" == "-f" ]; then | |
| rm bw_web_*.tar.gz | |
| wget https://github.com/dani-garcia/bw_web_builds/releases/download/$LATEST/bw_web_$LATEST.tar.gz | |
| rm -rf web-vault.old | |
| mv web-vault web-vault.old | |
| tar -xvf bw_web_$LATEST.tar.gz | |
| fi | |
| cd vaultwarden.git | |
| git fetch --tags | |
| LATEST=`git tag --sort=version:refname | tail -1` | |
| CURRENT=`git describe --exact-match --tags` | |
| #echo "Latest: $LATEST Current: $CURRENT" | |
| if [ "$LATEST" != "$CURRENT" -o "$1" == "-f" ]; then | |
| echo "Update from $CURRENT to $LATEST available." | |
| git checkout $LATEST | |
| cd .. | |
| OUTPUT=`./recompile` | |
| ERR=$? | |
| if [ $ERR -ne 0 ]; then | |
| printf "Attempted to compile version $LATEST.\n\n$OUTPUT" | mail -s "Vaultwarden compile failed!" root | |
| echo "Failed to compile vaultwarden." | |
| exit 1 | |
| fi | |
| echo "Restarting vaultwarden with the new version." | |
| killall vaultwarden | |
| sleep 1s | |
| ./vaultwarden & | |
| echo "Waiting to make sure it doesn't crash." | |
| sleep 30s | |
| ps | grep -q '[v]aultwarden' | |
| WORKING=$? | |
| if [ $WORKING -eq 0 ]; then | |
| printf "Updated from version %s to %s.\n\nhttps://github.com/dani-garcia/vaultwarden/releases/tag/%s" $CURRENT $LATEST $LATEST | mail -s "Vaultwarden updated." root | |
| echo "Success!" | |
| else | |
| printf "Updated from version %s to %s.\n\nhttps://github.com/dani-garcia/vaultwarden/releases/tag/%s" $CURRENT $LATEST $LATEST | mail -s "Vaultwarden updated crashed!" root | |
| echo "Vaultwarden crashed." | |
| fi | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function backup { | |
| rsync --archive --mkpath \ | |
| --xattrs --atimes \ | |
| "$@" | |
| } | |
| ENVFILE=/home/vaultwarden/.env | |
| DATA_DIR=/home/vaultwarden/data/ | |
| SQLITE=/home/vaultwarden/sqldb/db.sqlite3 | |
| OUTPUT=/storage/vaultwarden-backup | |
| backup --exclude=tmp --exclude=icon_cache "$DATA_DIR" "$OUTPUT/data" | |
| backup "$ENVFILE" "$OUTPUT/.env" | |
| mkdir -p "$OUTPUT/sqldb" && sqlite3 "$SQLITE" ".backup $OUTPUT/sqldb/db.sqlite3" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cd vaultwarden.git | |
| cargo build --features sqlite --release | |
| cd .. | |
| mv vaultwarden vaultwarden.old | |
| cp vaultwarden.git/target/release/vaultwarden ./ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment