#!/bin/bash if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4 set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?. PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR # need root for rsync pull of file ownership/perms [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" host=bk.b8.nz ret=0 source /a/bin/bash_unpublished/source-state restore=false case $1 in restore) restore=true ;; esac if $restore; then set -x for ncdir in /var/www/ncexpertpath /var/www/ncninja; do ncbase=${ncdir##*/} ssh root@$host sudo -u www-data php $ncdir/occ -q maintenance:mode --on ||: # might not be running rsync -ra /p/bkbackup/$ncbase/ root@$host:$ncdir || ret=$? # https://docs.nextcloud.com/server/20/admin_manual/configuration_server/occ_command.html#maintenance-commands-label ssh root@$host sudo -u www-data php $ncdir/occ -q maintenance:data-fingerprint ssh root@$host sudo -u www-data php $ncdir/occ -q maintenance:mode --on done rsync -ravi /p/bkbackup/m root@$host:/ exit 0 fi ret=0 if [[ $HOSTNAME == $MAIL_HOST ]]; then mkdir -p /p/bkbackup for ncdir in /var/www/ncexpertpath /var/www/ncninja; do ncbase=${ncdir##*/} mkdir -p /p/bkbackup/$ncbase ssh root@$host sudo -u www-data php $ncdir/occ -q maintenance:mode --on rsync -ra --exclude=testignore --delete root@$host:$ncdir/{config,data,themes} /p/bkbackup/$ncbase || ret=$? ssh root@$host sudo -u www-data php $ncdir/occ -q maintenance:mode --off if (( ret )); then echo "$0: error: failed rsync $ncdir" ret=1 fi done rsync -ra --delete root@$host:/m /p/bkbackup fi exit $ret