backup-docker/backup.sh

51 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
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
if [[ -n $RSYNC ]]; then
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"
fi
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 || pexit "Error: using popd"
# e.g. rsync -av --mkpath ./_vols_/ "/srv/fsback/${HN}/$(date +%^a)/"