From 6f4756b21e27bfa66eec03e3ee1a474a0af74498 Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Thu, 24 Feb 2022 15:50:40 -0500 Subject: [PATCH] Added vaultwarden backup agent --- scripts/vaultwarden | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scripts/vaultwarden diff --git a/scripts/vaultwarden b/scripts/vaultwarden new file mode 100644 index 0000000..edf8be6 --- /dev/null +++ b/scripts/vaultwarden @@ -0,0 +1,29 @@ +#!/bin/bash + +restoreDir=/etc/restore +vaultwardenDir="$restoreDir/vaultwarden" + + +hook_check() { + if [[ -d "$vaultwardenDir" ]]; then + rm -rf "$vaultwardenDir" || exit 1 + fi +} + +hook_pre() { + backupDate=$(date +"%Y-%m-%d") + vaultwardenHome=$(getent passwd vaultwarden | cut -f6 -d:) + + mkdir -p "$vaultwardenDir" + sqlite3 "${vaultwardenHome}/data/db.sqlite3" ".backup '${vaultwardenDir}/db-${backupDate}.sqlite3'" +} + +hook_post() { + rm -rf "$vaultwardenDir" || exit 1 +} + +case "$1" in + before_check) hook_check;; + before_backup) hook_pre;; + after_backup) hook_post;; +esac