Update at each release

Hello,

Considering the fact that releases are often published and that I deployed my instance by compiling binaries, I wonder what is the best method to update as soon as a new version is released while saving user data (vault) and configuration data. I’m not looking for a ready-made script (I’ll take care of that) but more some tips and a list of files to keep in order to avoid losing data.

In advance, thank’s!

Well if you build the code yourself, I’d just clone the git repository, that way when a new release gets built, you can do something like:

git fetch --tags
git checkout 1.16.1 # Or another version
cargo build --release --features sqlite
./target/release/bitwarden_rs

It’s a little more complicated…

I installed Rust with rustup so I only have access to cargo and rustc with my normal user (different from the one who runs Bitwarden RS. My installation is located at /etc/bitwardenrs, so I can’t run sudo cargo build --features sqlite --release because cargo was not installed with root. The simplest solution I see would be to check if the currently installed version is lower or higher than the latest release:

#! /usr/bin/env bash
# Version 0.1 - 2020-09-10 by ap
# This script checks if the vault and the server are up to date.

# server part
server_path=/etc/bitwardenrs
vault_path=/var/www/html/vault

cd $server_path
/usr/bin/git fetch --tags
server_release=$(/usr/bin/git describe --tags)
latest_release=$(/usr/bin/git tag | /usr/bin/sort -V | /usr/bin/tail -1)

# with this `if`, I simply compare if `$latest_release` is equal to `$server_release`
if [ "$(/usr/bin/printf '%s\n' "$latest_release" "$server_release" | /usr/bin/sort -V | /usr/bin/head -n1)" = "$latest_release" ]; then
        /usr/bin/echo "Bitwarden RS is up to date! (version: $server_release)"
else
	/usr/bin/echo "Bitwarden RS is not up to date! (latest version available: $latest_release)"
	/usr/bin/git clone --branch "$latest_release" https://github.com/dani-garcia/bitwarden_rs.git /home/ap/bitwardenrs
	# /usr/bin/git checkout $latest_release
	cd /home/ap/bitwardenrs/
	sudo -u ap /home/ap/.cargo/bin/cargo build --features sqlite --release
	sudo /usr/bin/mv /home/ap/bitwardenrs/target/release/bitwarden_rs /usr/local/bin/bitwardenrs
	# maybe I should move others directories (migrations, src...)? Which directories are essential?
fi

As I wrote in comment, which folders must or can be modified when a new release is released. Knowing this, I can do an rsync for example…

Please note that this script isn’t great at the moment but I’m in the testing phase so it will be improved. Feel free to improve it by the way!

From the git repo you only need the executable file, then you need the web vault, either compiled separately or downloading a precompiled version.

If you just replace the binary and keep the data folder where it is, everything should update fine.