X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=bk-backup;h=e47576669945141456d3600853ffd5410c2f7a78;hb=refs%2Fheads%2Fmaster;hp=cc25cecd3ac1bdc233614459b9f3c10f3bc2a9a0;hpb=40dd151ec6ba75633c74568da59e35a45351f194;p=distro-setup diff --git a/bk-backup b/bk-backup index cc25cec..e475766 100755 --- a/bk-backup +++ b/bk-backup @@ -1,4 +1,27 @@ #!/bin/bash +# I, Ian Kelling, follow the GNU license recommendations at +# https://www.gnu.org/licenses/license-recommendations.en.html. They +# recommend that small programs, < 300 lines, be licensed under the +# Apache License 2.0. This file contains or is part of one or more small +# programs. If a small program grows beyond 300 lines, I plan to switch +# its license to GPL. + +# Copyright 2024 Ian Kelling + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# usage: $0 [restore] 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 @@ -19,37 +42,42 @@ case $1 in ;; esac +# last checked 2022-03 version 23 +# https://docs.nextcloud.com/server/latest/admin_manual/maintenance/restore.html 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=$? + rsync -ravhi --numeric-ids /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 + ssh root@$host sudo -u www-data php $ncdir/occ -q maintenance:mode --off done - rsync -ravi /p/bkbackup/m root@$host:/ + # the dovecot thing is not needed afaik, just a good practice. + ssh root@$host systemctl stop dovecot + rsync -ravi --numeric-ids /p/bkbackup/m root@$host:/ + ssh root@$host systemctl start dovecot exit 0 fi ret=0 -if [[ $HOSTNAME == $MAIL_HOST ]]; then +if [[ $HOSTNAME == "$MAIL_HOST" ]]; then mkdir -p /p/bkbackup for ncdir in /var/www/ncexpertpath /var/www/ncninja; do - if [[ ! -d $ncdir ]]; then - continue - fi 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=$? + rsync --numeric-ids -ra --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 + rsync --numeric-ids -ra --delete \ + --exclude md/expertpathologyreview.com/testignore \ + --exclude md/amnimal.ninja/testignore \ + root@$host:/m /p/bkbackup fi exit $ret