diff --git a/do-backup b/do-backup index 6e8de5a..5db1835 100755 --- a/do-backup +++ b/do-backup @@ -7,7 +7,6 @@ # Perform backup tasks in a generic way. # Base configuration. -BACKUP_MOUNTPOINT="/localdata" RSYNC_OPTIONS=( '-a' '-H' '-A' '--timeout=300' '--partial' '--partial-dir=.rsync-tmp' '--delete-delay' '--delay-updates' ) RSYNC_OPTIONS_VERBOSE=( '--verbose' '--stats' '--human-readable' ) RSYNC_LOG="/tmp/${0##*/}-$$.log" @@ -21,11 +20,13 @@ RSYNC_LOG="/tmp/${0##*/}-$$.log" # Get backup definition specific configuration. case "$1" in 'gv0') + BACKUP_MOUNTPOINT="/localdata" BACKUP_DESTDIR="$BACKUP_MOUNTPOINT/backups/gv0" RSYNC_SOURCE="/storage/gv0/" # The / on the end is required. RSYNC_FILTER=() ;; 'mirrors') + BACKUP_MOUNTPOINT="/localdata" BACKUP_DESTDIR="$BACKUP_MOUNTPOINT/backups/mirrors" RSYNC_SOURCE="slackware.uk::mirrors/" # The / on the end is required. RSYNC_FILTER=( \ @@ -51,6 +52,19 @@ case "$1" in '--exclude=*' ) 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 exit 1 @@ -80,9 +94,9 @@ source /etc/mail.conf "backups" 2>/dev/null || { # Make sure BACKUP_MOUNTPOINT is a mountpoint. 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 - 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 '$BACKUP_MOUNTPOINT' is not a mountpoint. EOF @@ -93,15 +107,32 @@ mountpoint "$BACKUP_MOUNTPOINT" >/dev/null 2>&1 || { 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. rsync "${RSYNC_OPTIONS[@]}" "${RSYNC_OPTIONS_VERBOSE[@]}" "${RSYNC_FILTER[@]}" "$RSYNC_SOURCE" "$BACKUP_DESTDIR" >"$RSYNC_LOG" 2>&1 ERR="$?" # Send a notification and mail a log if there were errors. (( 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 - 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 Exit code: $ERR Output: diff --git a/do-mirroring b/do-mirroring index 944466b..98a291b 100755 --- a/do-mirroring +++ b/do-mirroring @@ -55,7 +55,7 @@ if (( "$ERR" == 0 )); then # The size of the log file determines if it gets emailed. (( $(stat --printf="%s" "$LOGSDIR/$LOGFILE") > MIN_LOGFILE_SIZE )) && { 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; } Exit code: $ERR Logfile: $LOGSDIR/$LOGFILE.gz @@ -71,7 +71,7 @@ else # Mirroring failed, tell the admin. [[ -x "/opt/bin/pushover" ]] && CONFIG_FILE="mirroring" /opt/bin/pushover -T "Mirroring" -p '-1' -m "Mirroring failed" 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; } Exit code: $ERR Logfile: $LOGSDIR/$LOGFILE.gz diff --git a/do-sbosrcarch b/do-sbosrcarch index e762b39..32cb460 100755 --- a/do-sbosrcarch +++ b/do-sbosrcarch @@ -53,7 +53,7 @@ printf "\\n" >>"$LOGSDIR/$LOGFILE" # Tell the sysadmin what went on. if (( "$ERR" == 0 )); 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; } Exit code: $ERR Logfile: $LOGSDIR/$LOGFILE.gz @@ -68,7 +68,7 @@ else # Updating failed, tell the admin. [[ -x "/opt/bin/pushover" ]] && CONFIG_FILE="mirroring" /opt/bin/pushover -T "SBosrcarch" -p '-1' -m "SBosrcarch failed" 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; } Exit code: $ERR Logfile: $LOGSDIR/$LOGFILE.gz diff --git a/rsync-notify-upload b/rsync-notify-upload index df30cf4..31c536f 100755 --- a/rsync-notify-upload +++ b/rsync-notify-upload @@ -36,7 +36,7 @@ fi # Send the message. 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; } Auth'd User: $RSYNC_USER_NAME@$RSYNC_HOST_NAME [$RSYNC_HOST_ADDR] Module: $RSYNC_MODULE_NAME ($RSYNC_MODULE_PATH)