commit a51e957105b4b7d53efd8e254f9d9d3c4c2ba834 Author: Thomas Constans Date: Sat Oct 3 22:41:19 2020 +0200 initial commit diff --git a/borg.conf b/borg.conf new file mode 100644 index 0000000..1650104 --- /dev/null +++ b/borg.conf @@ -0,0 +1,5 @@ +REPOSITORY={{borg_account}}@{{ borg_server }}:{{ borg_remote_dir }}/{{ ansible_hostname }} +export BORG_PASSPHRASE={{ borg_passphrase }} +borg=/usr/bin/borg +rotate={{ borg_rotate }} +src="{{ borg_dirs }}" \ No newline at end of file diff --git a/borg.sh b/borg.sh new file mode 100644 index 0000000..92633ff --- /dev/null +++ b/borg.sh @@ -0,0 +1,56 @@ +#! /bin/bash + +# wrapper around borgbackup +# need a borg.conf file - see example file +# need passwordless ssh access if using remote repo +conf=$(dirname $0)/borg.conf +if [ ! -f $conf ] ; then + echo config file not found + exit 5 +fi + +source $conf + +TODAY=$(date "+%Y%m%d") + +case $1 in + ("list") + if [ ! -z $2 ] ; then + ${borg} list $options ${REPOSITORY}::${2} + ret=$? + else + ${borg} list $options $REPOSITORY + ret=$? + fi + ;; + ("check") + shift +# if arg: check archive, if not: check whole repo + if [ $# -eq 1 ] ; then + target=${REPOSITORY}::${1} + else + target=${REPOSITORY} + fi + ${borg} check -v ${target} + ret=$? + ;; + ("extract") + ${borg} extract ${REPOSITORY}::${2} ${3} + ret=$? + ;; + + (info) + yesterday=$(date -d "yesterday 13:00 " '+%Y%m%d') + yesterday_archive=${REPOSITORY}::$(hostname)_${yesterday} + $borg check -v $yesterday_archive + ret=$? + ;; + (*) + ${borg} create $options --compression lzma,5 $REPOSITORY::$(hostname)_${TODAY} ${src} + ret=$? + if [ $ret -eq 0 ] ; then + ${borg} prune $options $REPOSITORY --prefix $(hostname)_ --keep-daily=${rotate} + fi + ;; +esac +exit $ret \ No newline at end of file