change backup.sh to be more general

This commit is contained in:
Andrew Hurley 2022-12-26 14:20:25 +11:00
parent a746f94e41
commit bde62426ae
2 changed files with 48 additions and 8 deletions

View File

@ -1 +1 @@
14 4 * * * root /srv/backup/backup.sh 2>&1 |tee /root/cron-backup.log
14 4 * * * root /srv/backup/backup.sh -r "/srv/fsback" docker 2>&1 |tee /srv/fsback/$(date +%^a).log

View File

@ -1,9 +1,49 @@
#!/bin/bash
pushd /srv/backup && \
printf "Backup start: $(date)\n" && \
./vvv.sh docker && \
nice ./v2b.sh -u backup && \
rsync -av --mkpath ./_vols_/ "/srv/fsback/docker/$(date +%^a)/" && \
usage () {
printf "Usage: backup.sh <options> <project> [<project>]\n"
printf " project = Compose project folder(s).\n"
printf " Option r <location>: rsync to another location - will make path (rsync mkpath option used)\n"
}
pexit () {
printf "${1}\n"
exit 1
}
RSYNC=""
while getopts ':r:' OPT; do
case $OPT in
r) RSYNC="${OPTARG}";;
\?) usage; exit;;
esac
done
shift $((OPTIND -1))
if [[ $# -lt 1 ]]; then
pexit "Error: missing project(s)"
fi
HN=$(hostname -f)
if [[ ! $HN =~ "." ]]; then
pexit "Error: fully quaififed hostname required (add to /etc/hosts - 127.0.0.11)"
fi
printf "Hostname: ${HN}\n"
pushd /srv/backup || pexit "Error: changing to backup directory"
printf "Backup start: $(date)\n"
for PROJECT in $@; do
./vvv.sh "${PROJECT}" || pexit "Error: using vvv.sh ${PROJECT}"
done
nice ./v2b.sh -u backup || pexit "Error: using v2b.sh -u backup"
if [[ -n $RSYNC ]]; then
RSYNC="${RSYNC}/${HN}/$(date +%^a)"
rsync -av --mkpath ./_vols_/ "${RSYNC}/" || pexit "Error: using rsync -av --mkpath ./_vols_/ ${RSYNC}/"
fi
printf "Backup end: $(date)\n" && \
popd
popd || pexit "Error: using popd"
# e.g. rsync -av --mkpath ./_vols_/ "/srv/fsback/${HN}/$(date +%^a)/"