141 lines
3.1 KiB
Bash
141 lines
3.1 KiB
Bash
|
#!/bin/sh
|
||
|
|
||
|
BASE="/services"
|
||
|
SERVICES=$(ls $BASE)
|
||
|
|
||
|
echo "#### STARTING NEW BACKUP OF ALL SERVICES ####"
|
||
|
echo ""
|
||
|
echo " SERVICES IN TRACKER:"
|
||
|
for SERVICE in $SERVICES; do
|
||
|
echo " - ${SERVICE}"
|
||
|
done
|
||
|
echo ""
|
||
|
echo " BACKUP STARTED ON $(date)"
|
||
|
echo ""
|
||
|
echo ""
|
||
|
echo ""
|
||
|
|
||
|
for SERVICE in $SERVICES; do
|
||
|
LOCAL="$BASE/$SERVICE"
|
||
|
|
||
|
# Skip service if it doesn't have an backup config specified
|
||
|
if [ ! -f "$LOCAL/backup.conf" ]; then
|
||
|
continue
|
||
|
fi
|
||
|
|
||
|
RETAIN="1M"
|
||
|
INCREMENT="1W"
|
||
|
INTERVAL="1H"
|
||
|
|
||
|
# Read config for extra options
|
||
|
while IFS='=' read -r key val; do
|
||
|
[ "${key##\#\#*}" ] || continue # Skip if line starts with two hash signs
|
||
|
[ ! "${key##\#*}" ] || continue # Skip if line doesn't start with a hash sign
|
||
|
key="${key##\#}" # Strip the hash sign
|
||
|
|
||
|
# Key isn't escaped so the space after the hash sign gets consumed
|
||
|
# by the assignment. This way the space is optional
|
||
|
export $key="$val" 2>/dev/null ||
|
||
|
printf ' warning %s is not a valid variable name\n' "$key"
|
||
|
done < "$LOCAL/backup.conf"
|
||
|
|
||
|
echo "==== BACKING UP $SERVICE ===="
|
||
|
echo ""
|
||
|
echo " Retaining backups for $RETAIN"
|
||
|
echo " Maxiumum incremental backup duration is $INCREMENT"
|
||
|
echo " Running every $INTERVAL"
|
||
|
echo ""
|
||
|
|
||
|
INTERVAL_INT=1
|
||
|
case $INTERVAL in
|
||
|
*M) INTERVAL_INT=$(( ${INTERVAL%%M} * 24 * 61 / 2 ));;
|
||
|
*W) INTERVAL_INT=$(( ${INTERVAL%%W} * 24 * 7 ));;
|
||
|
*D) INTERVAL_INT=$(( ${INTERVAL%%D} * 24 ));;
|
||
|
*H) INTERVAL_INT=$(( ${INTERVAL%%H} ));;
|
||
|
*) INTERVAL_INT=1;;
|
||
|
esac
|
||
|
|
||
|
if [ $(( ( $(date +%s) / 3600 ) % $INTERVAL_INT )) -ne 0 ]; then
|
||
|
echo "==== SKIPPING $SERVICE"
|
||
|
echo " Service not yet scheduled for backup."
|
||
|
echo ""
|
||
|
echo ""
|
||
|
echo ""
|
||
|
echo ""
|
||
|
echo ""
|
||
|
continue
|
||
|
fi
|
||
|
|
||
|
echo ""
|
||
|
|
||
|
while read REMOTE; do
|
||
|
# Skip if line is empty
|
||
|
[ -z "$REMOTE" ] && continue
|
||
|
|
||
|
REMOTE="$REMOTE/$SERVICE"
|
||
|
TYPE=$(echo "$REMOTE" | cut -d \: -f 1)
|
||
|
SERVER=$(echo "$REMOTE" | cut -d \: -f 3 | cut -d \@ -f 2 | cut -d \/ -f 1)
|
||
|
|
||
|
echo "==== USING REMOTE:"
|
||
|
echo " $SERVER over $TYPE"
|
||
|
echo ""
|
||
|
|
||
|
echo " > BACKUP"
|
||
|
duplicity \
|
||
|
--verbosity 2 \
|
||
|
--no-encryption \
|
||
|
--allow-source-mismatch \
|
||
|
--full-if-older-than "$INCREMENT" \
|
||
|
--include-filelist "$LOCAL/backup.conf" \
|
||
|
"$LOCAL" "$REMOTE" \
|
||
|
2>&1 | sed 's/^/ /'
|
||
|
|
||
|
echo " > DELETE OLD"
|
||
|
duplicity \
|
||
|
--verbosity 2 \
|
||
|
remove-older-than "$RETAIN" \
|
||
|
--no-encryption \
|
||
|
--allow-source-mismatch \
|
||
|
--include-filelist "$LOCAL/backup.conf" \
|
||
|
--force \
|
||
|
"$REMOTE" \
|
||
|
2>&1 | sed 's/^/ /'
|
||
|
|
||
|
echo ""
|
||
|
echo " > VERIFY"
|
||
|
duplicity \
|
||
|
verify \
|
||
|
--verbosity 2 \
|
||
|
--no-encryption \
|
||
|
--allow-source-mismatch \
|
||
|
--include-filelist "$LOCAL/backup.conf" \
|
||
|
"$REMOTE" "$LOCAL" \
|
||
|
2>&1 | sed 's/^/ /'
|
||
|
|
||
|
if [ $? -ne 0 ]; then
|
||
|
echo " [!] SOMETHING BAD HAPPENED"
|
||
|
echo " Backups where made but don't check out. Is the remote's storage full?"
|
||
|
fi
|
||
|
|
||
|
echo ""
|
||
|
echo ""
|
||
|
done < "/data/services.conf"
|
||
|
echo ""
|
||
|
echo ""
|
||
|
echo ""
|
||
|
|
||
|
done
|
||
|
|
||
|
echo "#### BACKUP FINISHED ####"
|
||
|
echo ""
|
||
|
echo " ENDED ON $(date)"
|
||
|
echo ""
|
||
|
echo ""
|
||
|
echo ""
|
||
|
echo ""
|
||
|
echo ""
|
||
|
echo ""
|
||
|
echo ""
|
||
|
echo ""
|
||
|
echo ""
|