diff options
-rw-r--r-- | 70_vaultwarden_cron | 8 | ||||
-rw-r--r-- | README-bup-vw.md | 31 | ||||
-rwxr-xr-x | bup-vw-db.sh | 26 | ||||
-rwxr-xr-x | bup-vw.sh | 79 |
4 files changed, 144 insertions, 0 deletions
diff --git a/70_vaultwarden_cron b/70_vaultwarden_cron new file mode 100644 index 0000000..f033a69 --- /dev/null +++ b/70_vaultwarden_cron @@ -0,0 +1,8 @@ +# File: /etc/cron.d/70_vaultwarden_cron +# Startdate: 2023-01-02-2 22:50 +# Author: bgstack15 +# History: +# Dependencies: +# Documentation: +# vm4:/home/vaultwarden/README-bup-vw.md +30 06 * * * vaultwarden /home/vaultwarden/bup-vw.sh cron 1>/dev/null 2>&1 diff --git a/README-bup-vw.md b/README-bup-vw.md new file mode 100644 index 0000000..4208db8 --- /dev/null +++ b/README-bup-vw.md @@ -0,0 +1,31 @@ +# README for Vaultwarden Bup +This describes the Vaultwarden Bup project for Mersey network. + +## Upstream +This project's upstream is at <https://bgstack15.ddns.net/cgit/bup-vaultwarden>. + +## Alternatives +Unknown + +## Reason for existence +Vaultwarden runs in docker on vm4, it does not have its contents bupped by the main storage3 bup solutions. This project takes the appropriate backups and places them on storage3. + +## Using +Set up the cron job, and make sure these directories have these permissions. + + $ ls -ld /mnt/public/Support/Systems/vm4/vw/vaultwarden/ $( readlink -f . )/vaultwarden + drwxrwxrwx. 2 root root 4096 Jan 2 22:57 /mnt/public/Support/Systems/vm4/vw/vaultwarden + drwxr-xr-x. 2 1006 1006 4096 Jan 2 22:58 /mnt/public/Support/Systems/vm4/var/log/vaultwarden + +## Dependencies +A chart for distros, or maybe just a simple package list. + +## Building +### Related files +/etc/cron.d/70_vaultwarden_cron +/home/vaultwarden/bup-vw.sh +/home/vaultwarden/bup-vw-db.sh + +## References + +1. https://github.com/dani-garcia/vaultwarden/wiki/General-%28not-docker%29 diff --git a/bup-vw-db.sh b/bup-vw-db.sh new file mode 100755 index 0000000..904f09b --- /dev/null +++ b/bup-vw-db.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# File: vm4:/home/vaultwarden/bup-vw-db.sh +# Location: vm4 +# Author: bgstack15 +# Startdate: 2023-01-02-2 16:54 +# Title: Bup Vaultwarden database +# Project: bup-vw +# Purpose: Backup Vaultwarden database +# History: +# Usage: called by bup-vw.sh +# Reference: +# https://github.com/dani-garcia/vaultwarden/wiki/General-%28not-docker%29 +# https://stackoverflow.com/questions/25675314/how-to-backup-sqlite-database/25684912#25684912 +# Improve: +# Dependencies: +# sqlite3 +# must run as root! +# Documentation: see bup-vw.sh +INDB=/home/vaultwarden/vw/bitwarden/db.sqlite3 +test -z "${LOCALOUTDIR}" && LOCALOUTDIR=/home/vaultwarden/bup +test -z "${OUTFILE}" && OUTFILE="${LOCALOUTDIR}/vw.$( date "+%F" ).sq3" +echo ".backup ${OUTFILE}" | sqlite3 "${INDB}" +# the main script will tarball it with the relevant files +#gzip "${OUTFILE}" +chown vaultwarden:vaultwarden "${OUTFILE}" +echo "${OUTFILE}" diff --git a/bup-vw.sh b/bup-vw.sh new file mode 100755 index 0000000..a5cdcb3 --- /dev/null +++ b/bup-vw.sh @@ -0,0 +1,79 @@ +#!/bin/sh +# File: vm4:/home/vaultwarden/bup-vw.sh +# Location: vm4 +# Author: bgstack15 +# Startdate: 2023-01-02-2 16:54 +# Title: Bup Vaultwarden +# Project: bup-vw +# Purpose: Backup Vaultwarden contents +# History: +# Usage: called by cron: 70_vaultwarden_cron +# Reference: +# https://github.com/dani-garcia/vaultwarden/wiki/General-%28not-docker%29 +# photorprism/bup-pp-db.sh +# Improve: +# Dependencies: +# sudo access for user vaultwardern to run bup-vw-db.sh, /etc/sudoers.d/70_vaultwarden_bup_sudo +# Documentation: +# README-vw-bup.md + +workdir="$( dirname "$( readlink -f "${0}" 2>/dev/null )" 2>/dev/null || echo "${PWD}" )" +#echo "workdir=${workdir}" +test -z "${CONFFILE}" && CONFFILE="${workdir}/bup-vw.conf" +test -e "${CONFFILE}" && . "${CONFFILE}" +test -z "${LOGFILE}" && LOGFILE="/mnt/public/Support/Systems/vm4/var/log/vaultwarden/bup-vw.$( date "+%F" ).log" + +_return() { + return ${1} +} + +main() { + export OUTDIR=/mnt/public/Support/Systems/vm4/vw/vaultwarden + export LOCALOUTDIR=/home/vaultwarden/bup + export OUTFILE="${LOCALOUTDIR}/vw.$( date "+%F" ).sq3" + export OUTTARBALL="${OUTDIR}/vw.$( date "+%F" ).tgz" + # fail early if network mount is not there + if ! test -w "$( dirname "${OUTFILE}" )" ; + then + echo "Fatal! Unable to write to directory for ${OUTTARBALL}: Aborted." + exit 1 + fi + # run the bup-vw-db.sh script, collect other things, make a tarball + generated_file="$( sudo /home/vaultwarden/bup-vw-db.sh )" + if ! test -f "${generated_file}" ; + then + echo "Fatal! Unable to find exported database file ${OUTFILE}: Aborted." + exit 1 + fi + relative_generated_file="bup/$( basename "${generated_file}" )" + tar -zcf "${OUTTARBALL}" -C /home/vaultwarden vw/docker-compose.yml vw/.env vw/bitwarden "${relative_generated_file}" + find "${OUTTARBALL}" +} + +# Determine if this script was dot-sourced +sourced=0 +if [ -n "$ZSH_EVAL_CONTEXT" ]; then + case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac +elif [ -n "$KSH_VERSION" ]; then + [ "$(cd $(dirname -- $0) && pwd -P)/$(basename -- $0)" != "$(cd $(dirname -- ${.sh.file}) && pwd -P)/$(basename -- ${.sh.file})" ] && sourced=1 +elif [ -n "$BASH_VERSION" ]; then + (return 0 2>/dev/null) && sourced=1 +else # All other shells: examine $0 for known shell binary filenames + # Detects `sh` and `dash`; add additional shell filenames as needed. + case ${0##*/} in sh|dash) sourced=1;; esac +fi + +# So, if not dot-sourced, and this is run by cron, add logging +if test $sourced -eq 0; +then + if echo " ${@} " | grep -q cron ; + then + main 2>&1 | plecho | tee -a "${LOGFILE}" + response=$? + printf '\n' | tee -a "${LOGFILE}" + else + main + response=$? + fi +fi +_return ${response} |