Update do-backup for userdirs. Remove ''s around from= for mailx.
This commit is contained in:
parent
2e2e666797
commit
25394932fb
4 changed files with 41 additions and 10 deletions
41
do-backup
41
do-backup
|
|
@ -7,7 +7,6 @@
|
||||||
# Perform backup tasks in a generic way.
|
# Perform backup tasks in a generic way.
|
||||||
|
|
||||||
# Base configuration.
|
# Base configuration.
|
||||||
BACKUP_MOUNTPOINT="/localdata"
|
|
||||||
RSYNC_OPTIONS=( '-a' '-H' '-A' '--timeout=300' '--partial' '--partial-dir=.rsync-tmp' '--delete-delay' '--delay-updates' )
|
RSYNC_OPTIONS=( '-a' '-H' '-A' '--timeout=300' '--partial' '--partial-dir=.rsync-tmp' '--delete-delay' '--delay-updates' )
|
||||||
RSYNC_OPTIONS_VERBOSE=( '--verbose' '--stats' '--human-readable' )
|
RSYNC_OPTIONS_VERBOSE=( '--verbose' '--stats' '--human-readable' )
|
||||||
RSYNC_LOG="/tmp/${0##*/}-$$.log"
|
RSYNC_LOG="/tmp/${0##*/}-$$.log"
|
||||||
|
|
@ -21,11 +20,13 @@ RSYNC_LOG="/tmp/${0##*/}-$$.log"
|
||||||
# Get backup definition specific configuration.
|
# Get backup definition specific configuration.
|
||||||
case "$1" in
|
case "$1" in
|
||||||
'gv0')
|
'gv0')
|
||||||
|
BACKUP_MOUNTPOINT="/localdata"
|
||||||
BACKUP_DESTDIR="$BACKUP_MOUNTPOINT/backups/gv0"
|
BACKUP_DESTDIR="$BACKUP_MOUNTPOINT/backups/gv0"
|
||||||
RSYNC_SOURCE="/storage/gv0/" # The / on the end is required.
|
RSYNC_SOURCE="/storage/gv0/" # The / on the end is required.
|
||||||
RSYNC_FILTER=()
|
RSYNC_FILTER=()
|
||||||
;;
|
;;
|
||||||
'mirrors')
|
'mirrors')
|
||||||
|
BACKUP_MOUNTPOINT="/localdata"
|
||||||
BACKUP_DESTDIR="$BACKUP_MOUNTPOINT/backups/mirrors"
|
BACKUP_DESTDIR="$BACKUP_MOUNTPOINT/backups/mirrors"
|
||||||
RSYNC_SOURCE="slackware.uk::mirrors/" # The / on the end is required.
|
RSYNC_SOURCE="slackware.uk::mirrors/" # The / on the end is required.
|
||||||
RSYNC_FILTER=( \
|
RSYNC_FILTER=( \
|
||||||
|
|
@ -51,6 +52,19 @@ case "$1" in
|
||||||
'--exclude=*' )
|
'--exclude=*' )
|
||||||
RSYNC_OPTIONS+=( '--contimeout=30' )
|
RSYNC_OPTIONS+=( '--contimeout=30' )
|
||||||
;;
|
;;
|
||||||
|
'userdir')
|
||||||
|
BACKUP_MOUNTPOINT="/data/home"
|
||||||
|
BACKUP_DESTDIR="$BACKUP_MOUNTPOINT/tadgy/UserDirs/${HOSTNAME%%.*}-$USER"
|
||||||
|
RSYNC_SOURCE="/home/$USER/" # The / on the end is required.
|
||||||
|
RSYNC_FILTER=( \
|
||||||
|
'--exclude=/.cache/mozilla/firefox/*/cache2/***' \
|
||||||
|
'--exclude=/.gnupg/private-keys-v1.d/*.key' \
|
||||||
|
'--exclude=/.gnupg/openpgp-revocs.d/*.rev' \
|
||||||
|
'--exclude=/.irssi/config' \
|
||||||
|
'--exclude=/.ssh/id_ed25519' \
|
||||||
|
'--exclude=/.ssh/id_rsa' )
|
||||||
|
ERRORS_SOURCE="userdir: ${HOSTNAME%%.*}-$USER"
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
printf "%s: %s: %s\\n" "${0##*/}" "$1" "unknown backup definition" >&2
|
printf "%s: %s: %s\\n" "${0##*/}" "$1" "unknown backup definition" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|
@ -80,9 +94,9 @@ source /etc/mail.conf "backups" 2>/dev/null || {
|
||||||
|
|
||||||
# Make sure BACKUP_MOUNTPOINT is a mountpoint.
|
# Make sure BACKUP_MOUNTPOINT is a mountpoint.
|
||||||
mountpoint "$BACKUP_MOUNTPOINT" >/dev/null 2>&1 || {
|
mountpoint "$BACKUP_MOUNTPOINT" >/dev/null 2>&1 || {
|
||||||
[[ -x "/opt/bin/pushover" ]] && CONFIG_FILE="backups" /opt/bin/pushover -T "Backup" -p '-1' -m "Failure: $RSYNC_SOURCE"
|
[[ -x /opt/bin/pushover-client ]] && /opt/bin/pushover-client "backups" -p -1 -m "Backup failure: ${ERRORS_SOURCE:-$RSYNC_SOURCE}"
|
||||||
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
||||||
mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
mailx "${MAILX_ARGS[@]}" -S "from=$EMAIL_FROM" -s "Backup failure: ${ERRORS_SOURCE:-$RSYNC_SOURCE}" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
||||||
printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2
|
printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2
|
||||||
'$BACKUP_MOUNTPOINT' is not a mountpoint.
|
'$BACKUP_MOUNTPOINT' is not a mountpoint.
|
||||||
EOF
|
EOF
|
||||||
|
|
@ -93,15 +107,32 @@ mountpoint "$BACKUP_MOUNTPOINT" >/dev/null 2>&1 || {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Create the BACKUP_DESTDIR if required.
|
||||||
|
[[ ! -e "$BACKUP_DESTDIR" ]] && {
|
||||||
|
mkdir -p "$BACKUP_DESTDIR" || {
|
||||||
|
[[ -x /opt/bin/pushover-client ]] && /opt/bin/pushover-client "backups" -p -1 -m "Backup failure: ${ERRORS_SOURCE:-$RSYNC_SOURCE}"
|
||||||
|
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
||||||
|
mailx "${MAILX_ARGS[@]}" -S "from=$EMAIL_FROM" -s "Backup failure: ${ERRORS_SOURCE:-$RSYNC_SOURCE}" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
||||||
|
printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2
|
||||||
|
Failed to mkdir '$BACKUP_DESTDIR'.
|
||||||
|
EOF
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
printf "%s: %s\\n" "${0##*/}" "no recipient configured for mail delivery" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Do the backup.
|
# Do the backup.
|
||||||
rsync "${RSYNC_OPTIONS[@]}" "${RSYNC_OPTIONS_VERBOSE[@]}" "${RSYNC_FILTER[@]}" "$RSYNC_SOURCE" "$BACKUP_DESTDIR" >"$RSYNC_LOG" 2>&1
|
rsync "${RSYNC_OPTIONS[@]}" "${RSYNC_OPTIONS_VERBOSE[@]}" "${RSYNC_FILTER[@]}" "$RSYNC_SOURCE" "$BACKUP_DESTDIR" >"$RSYNC_LOG" 2>&1
|
||||||
ERR="$?"
|
ERR="$?"
|
||||||
|
|
||||||
# Send a notification and mail a log if there were errors.
|
# Send a notification and mail a log if there were errors.
|
||||||
(( ERR != 0 )) && (( ERR != 10 )) && (( ERR != 24 )) && {
|
(( ERR != 0 )) && (( ERR != 10 )) && (( ERR != 24 )) && {
|
||||||
[[ -x "/opt/bin/pushover" ]] && CONFIG_FILE="backups" /opt/bin/pushover -T "Backup" -p '-1' -m "Failure: $RSYNC_SOURCE"
|
[[ -x /opt/bin/pushover-client ]] && /opt/bin/pushover-client "backups" -p -1 -m "Backup failure: ${ERRORS_SOURCE:-$RSYNC_SOURCE}"
|
||||||
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
||||||
mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
mailx "${MAILX_ARGS[@]}" -S "from=$EMAIL_FROM" -s "Backup failure: ${ERRORS_SOURCE:-$RSYNC_SOURCE}" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
||||||
printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2
|
printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2
|
||||||
Exit code: $ERR
|
Exit code: $ERR
|
||||||
Output:
|
Output:
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ if (( "$ERR" == 0 )); then
|
||||||
# The size of the log file determines if it gets emailed.
|
# The size of the log file determines if it gets emailed.
|
||||||
(( $(stat --printf="%s" "$LOGSDIR/$LOGFILE") > MIN_LOGFILE_SIZE )) && {
|
(( $(stat --printf="%s" "$LOGSDIR/$LOGFILE") > MIN_LOGFILE_SIZE )) && {
|
||||||
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
||||||
mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Mirroring report" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
mailx "${MAILX_ARGS[@]}" -S "from=$EMAIL_FROM" -s "Mirroring report" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
||||||
{ printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2; RET=1; }
|
{ printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2; RET=1; }
|
||||||
Exit code: $ERR
|
Exit code: $ERR
|
||||||
Logfile: $LOGSDIR/$LOGFILE.gz
|
Logfile: $LOGSDIR/$LOGFILE.gz
|
||||||
|
|
@ -71,7 +71,7 @@ else
|
||||||
# Mirroring failed, tell the admin.
|
# Mirroring failed, tell the admin.
|
||||||
[[ -x "/opt/bin/pushover" ]] && CONFIG_FILE="mirroring" /opt/bin/pushover -T "Mirroring" -p '-1' -m "Mirroring failed"
|
[[ -x "/opt/bin/pushover" ]] && CONFIG_FILE="mirroring" /opt/bin/pushover -T "Mirroring" -p '-1' -m "Mirroring failed"
|
||||||
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
||||||
mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Mirroring failure" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
mailx "${MAILX_ARGS[@]}" -S "from=$EMAIL_FROM" -s "Mirroring failure" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
||||||
{ printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2; RET=1; }
|
{ printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2; RET=1; }
|
||||||
Exit code: $ERR
|
Exit code: $ERR
|
||||||
Logfile: $LOGSDIR/$LOGFILE.gz
|
Logfile: $LOGSDIR/$LOGFILE.gz
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ printf "\\n" >>"$LOGSDIR/$LOGFILE"
|
||||||
# Tell the sysadmin what went on.
|
# Tell the sysadmin what went on.
|
||||||
if (( "$ERR" == 0 )); then
|
if (( "$ERR" == 0 )); then
|
||||||
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
||||||
mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "SBosrcarch report" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
mailx "${MAILX_ARGS[@]}" -S "from=$EMAIL_FROM" -s "SBosrcarch report" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
||||||
{ printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2; RET=1; }
|
{ printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2; RET=1; }
|
||||||
Exit code: $ERR
|
Exit code: $ERR
|
||||||
Logfile: $LOGSDIR/$LOGFILE.gz
|
Logfile: $LOGSDIR/$LOGFILE.gz
|
||||||
|
|
@ -68,7 +68,7 @@ else
|
||||||
# Updating failed, tell the admin.
|
# Updating failed, tell the admin.
|
||||||
[[ -x "/opt/bin/pushover" ]] && CONFIG_FILE="mirroring" /opt/bin/pushover -T "SBosrcarch" -p '-1' -m "SBosrcarch failed"
|
[[ -x "/opt/bin/pushover" ]] && CONFIG_FILE="mirroring" /opt/bin/pushover -T "SBosrcarch" -p '-1' -m "SBosrcarch failed"
|
||||||
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
||||||
mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "SBosrcarch failure" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
mailx "${MAILX_ARGS[@]}" -S "from=$EMAIL_FROM" -s "SBosrcarch failure" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
||||||
{ printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2; RET=1; }
|
{ printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2; RET=1; }
|
||||||
Exit code: $ERR
|
Exit code: $ERR
|
||||||
Logfile: $LOGSDIR/$LOGFILE.gz
|
Logfile: $LOGSDIR/$LOGFILE.gz
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ fi
|
||||||
|
|
||||||
# Send the message.
|
# Send the message.
|
||||||
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
if [[ -n "${EMAIL_TO[*]}" ]]; then
|
||||||
mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "$EMAIL_SUBJECT" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
mailx "${MAILX_ARGS[@]}" -S "from=$EMAIL_FROM" -s "$EMAIL_SUBJECT" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
|
||||||
{ printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2; RET=1; }
|
{ printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2; RET=1; }
|
||||||
Auth'd User: $RSYNC_USER_NAME@$RSYNC_HOST_NAME [$RSYNC_HOST_ADDR]
|
Auth'd User: $RSYNC_USER_NAME@$RSYNC_HOST_NAME [$RSYNC_HOST_ADDR]
|
||||||
Module: $RSYNC_MODULE_NAME ($RSYNC_MODULE_PATH)
|
Module: $RSYNC_MODULE_NAME ($RSYNC_MODULE_PATH)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue