Compare commits

..

No commits in common. "774978026d8b108e2db88fac5c2db6dbb1132e7e" and "75704845e438f1a9f6cef93ca0b511f5db0a53b1" have entirely different histories.

5 changed files with 30 additions and 55 deletions

View file

@ -3,12 +3,11 @@
# Default configuration.
SCANDIR="/data/depository"
DBFILE="/data/sites/slackware.uk/files/repository-search/search.db"
RUNAS_GROUP="depository"
DBFILE="/data/sites/slackware.uk/files/search.db"
RAND="$$$RANDOM"
if ionice -c3 nice -n 19 sg "$RUNAS_GROUP" -c "/opt/bin/updatedb -l no -o \"$DBFILE.$RAND\" -U \"$SCANDIR\" >/dev/null 2>&1"; then
if ionice -c3 nice -n 19 /opt/bin/updatedb -l no -o "$DBFILE.$RAND" -U "$SCANDIR" >/dev/null 2>&1; then
mv "$DBFILE.$RAND" "$DBFILE" 2>/dev/null || {
printf "%s: %s\\n" "${0##*/}" "failed to move mirrors search database into place" >&2
rm -f "$DBFILE.$RAND"

6
mirror
View file

@ -17,8 +17,8 @@ MAX_RUNS="3" # Maximum number of runs
IPV4="5.101.171.215"
DATADIR="/data/depository"
RSYNC_COMMAND="/usr/bin/rsync"
RSYNC_REMOTE_OPTIONS=('-4' "--address=$IPV4" '--no-motd' '--contimeout=30' '--timeout=60' '-aH' '--no-owner' '--no-group' '--no-perms' '--chmod=u+w,go-w,Dugo+rx,Fugo+rX' '--partial' '--partial-dir=.rsync-tmp' '--delete-delay' '--delay-updates')
RSYNC_LOCAL_OPTIONS=('-aH' '--chmod=u+w,go-w,Dugo+rx,Fugo+rX' '--partial' '--partial-dir=.rsync-tmp' '--delay-updates')
RSYNC_REMOTE_OPTIONS=('-4' "--address=$IPV4" '--no-motd' '--contimeout=30' '--timeout=60' '-aH' '--no-owner' '--no-group' '--chmod=go-w,+rX' '--partial' '--partial-dir=.rsync-tmp' '--delete-delay' '--delay-updates')
RSYNC_LOCAL_OPTIONS=('-aH' '--chmod=go-w,+rX' '--partial' '--partial-dir=.rsync-tmp' '--delay-updates')
# RSYNC_VERBOSE=('--verbose' '--human-readable')
# RSYNC_VERBOSE=('--progress' '--verbose' '--stats' '--human-readable')
LFTP_COMMAND="/usr/bin/lftp"
@ -207,7 +207,7 @@ while [[ -n "$1" ]]; do
exit 0
;;
*)
if [[ "$1" == "ALL" ]]; then
if [[ "$1" == "*" ]]; then
SYNC_ALL=1
shift
break

View file

@ -4,11 +4,12 @@
# Configuration.
COMMAND="/opt/bin/mirror"
DEPOSITORY="/data/depository"
MIRRORING_USER='SLACKWAREUKINT\mirroring'
DEPOSITORY_GROUP='SLACKWAREUKINT\depository'
MIRRORING_USER="mirroring"
SBOSRCARCH_USER="sbosrcarch"
DEPOSITORY_GROUP="depository"
LOGSDIR="/var/log/duplication/mirroring/$(printf "%(%Y/%m)T")"
LOGFILE="$(printf "%(%Y%m%d-%H%M%S)T")-$$"
MIN_LOGFILE_SIZE="845" # Used to prevent unnecessary emails - only messages over this size are sent.
MIN_LOGFILE_SIZE="650" # Used to prevent unnecessary emails - only messages over this size are sent.
# Where from/to to send emails. Comment for no emailing.
EMAIL_FROM="\"Server: ${HOSTNAME%%.*}\" <noreply@slackware.uk.net>"
EMAIL_TO=("Systems' Administrator <sysadmin@slackware.uk>")
@ -16,7 +17,7 @@ EMAIL_TO=("Systems' Administrator <sysadmin@slackware.uk>")
# Functions
notify() {
[[ -n "$EMAIL_FROM" ]] && (( "${#EMAIL_TO[@]}" != 0 )) && {
printf "%s: %s\\n%s: %s\\n%s:\\n%s\\n" "Exit code" "$ERR" "Logfile" "$LOGSDIR/$LOGFILE.xz" "Output" "$(cat "$LOGSDIR/$LOGFILE" | sed -re 's/^/ /g')" | mail -r "$EMAIL_FROM" -s "Mirroring $1" "${EMAIL_TO[@]}" >/dev/null 2>&1 || {
printf "%s: %s\\n%s: %s\\n%s:\\n%s\\n" "Exit code" "$ERR" "Logfile" "$LOGSDIR/$LOGFILE.xz" "Output" "$(<"$LOGSDIR/$LOGFILE")" | mail -r "$EMAIL_FROM" -s "Mirroring $1" "${EMAIL_TO[@]}" >/dev/null 2>&1 || {
printf "%s: %s\\n" "${0##*/}" "mail command failed" >&2
return 1
}
@ -30,8 +31,7 @@ umask 027
# Only run for the configured mirroring user.
[[ "$(whoami)" != "$MIRRORING_USER" ]] && {
printf "%s: %s\\n" "${0##*/}" "must be run by the '$MIRRORING_USER' user" >&2
printf "%s: %s: %s\\n" "${0##*/}" "to run manually:" "su '$MIRRORING_USER' $0 $@" >&2
printf "%s: %s\\n" "${0##*/}" "must be run by the '$MIRRORING_USER' user - use su to run manually" >&2
exit 1
}
@ -67,28 +67,16 @@ fi
sudo /opt/sbin/drop-caches
# Make sure there's no errant ownerships.
printf "%s: %s\\n" "INFO" "Scanning depository directory for correct ownerships/permissions" | tee "$LOGSDIR/$LOGFILE"
GLOBIGNORE="$DEPOSITORY/sbosrcarch"
WRONG="$(find "$DEPOSITORY/"* \( \
\( \( -type b -o -type c -o -type p -o -type s \) -a \! -path "$DEPOSITORY/slackware/slackware-3.0/disk1/live/dev/*" \) -o \
\( -type l -a \! -perm 777 \) -o \
\( -type d -a \! -perm 755 -a \! -perm 2755 \) -o \
\( -type f -a \! -perm 644 -a \! -perm 755 \) -o \
\( \! -user "$MIRRORING_USER" \) -o \
\( \! -group "$DEPOSITORY_GROUP" \) \
\) -a -printf "%u:%g\t%M\t%p\n")"
if [[ -n "$WRONG" ]]; then
printf "%s: %s\\n" "ERROR" "This sync has been aborted!" | tee -a "$LOGSDIR/$LOGFILE"
printf "%s: %s\\n" "WARNING" "The following paths have erronious ownerships/permissions:" | tee -a "$LOGSDIR/$LOGFILE"
printf "%s\\n" "$WRONG" | sed -re 's/^/ /g' | tee -a "$LOGSDIR/$LOGFILE"
WRONG_PERMS="$(find "$DEPOSITORY" \( \( \! -user "$MIRRORING_USER" -a \! -user "$SBOSRCARCH_USER" \) -o \( \! -group "$DEPOSITORY_GROUP" \) \) -a \! -path "$DEPOSITORY" -printf "%u:%g\t%P\n")"
if [[ -n "$WRONG_PERMS" ]]; then
printf "%s\\n" "This sync has been aborted!" >"$LOGSDIR/$LOGFILE"
printf "%s\\n" "The following files in have errant permissions:" >>"$LOGSDIR/$LOGFILE"
printf "%s\\n" "$WRONG_PERMS" >>"$LOGSDIR/$LOGFILE"
ERR=-1
else
printf "%s: %s\\n" "INFO" "No ownership/permission issues found" | tee -a "$LOGSDIR/$LOGFILE"
# Do the mirroring work.
umask 022
export MIRRORING_USER
printf "%s: %s: %s\\n" "INFO" "Beginning sync command" "sg \"$DEPOSITORY_GROUP\" -c \"$COMMAND $@\"" | tee -a "$LOGSDIR/$LOGFILE"
sg "$DEPOSITORY_GROUP" -c "$COMMAND $@" 2>&1 | tee -a "$LOGSDIR/$LOGFILE"
sg "$DEPOSITORY_GROUP" -c "$COMMAND $@" >"$LOGSDIR/$LOGFILE" 2>&1
ERR="$?"
fi

View file

@ -23,7 +23,7 @@ mkdir -p "$LOGSDIR" 2>/dev/null || {
}
# Update the log with this upload date/time.
printf "%s - %s\\n" "$(printf "%(%c)T")" "${RSYNC_USER_NAME:-(none)}@${RSYNC_HOST_NAME:-$RSYNC_HOST_ADDR}" >>"$LOGSDIR/${RSYNC_MODULE_NAME%%-upload}"
printf "%s - %s\\n" "$(printf "%(%c)T")" "{RSYNC_USER_NAME:-(none)}@${RSYNC_HOST_NAME:-$RSYNC_HOST_ADDR}" >>"$LOGSDIR/${RSYNC_MODULE_NAME%%-upload}"
# Determine the subject of the message.
if (( RSYNC_EXIT_STATUS == 0 )); then

View file

@ -4,8 +4,8 @@
# Configuration.
COMMAND="/opt/bin/sbosrcarch"
DEPOSITORY="/data/depository/sbosrcarch"
SBOSRCARCH_USER='SLACKWAREUKINT\sbosrcarch'
DEPOSITORY_GROUP='SLACKWAREUKINT\depository'
SBOSRCARCH_USER="sbosrcarch"
DEPOSITORY_GROUP="depository"
LOGSDIR="/var/log/duplication/sbosrcarch/$(printf "%(%Y/%m)T")"
LOGFILE="$(printf "%(%Y%m%d-%H%M%S)T")-$$"
# Where from/to to send emails. Comment for no emailing.
@ -16,7 +16,7 @@ EMAIL_CC=("Urchlay <urchlay@slackware.uk>")
# Functions
notify() {
[[ -n "$EMAIL_FROM" ]] && (( "${#EMAIL_TO[@]}" != 0 )) && {
printf "%s: %s\\n%s: %s\\n%s:\\n%s\\n" "Exit code" "$ERR" "Logfile" "$LOGSDIR/$LOGFILE.xz" "Output" "$(cat "$LOGSDIR/$LOGFILE" | sed -re 's/^/ /g')" | mail -r "$EMAIL_FROM" -s "SboSrcArch $1" "$(for i in $(seq -s ' ' 0 $(( ${#EMAIL_CC[@]} -1 ))); do echo ${EMAIL_CC[$i]:+-c "${EMAIL_CC[$i]}"}; done)" "${EMAIL_TO[@]}" >/dev/null 2>&1 || {
printf "%s: %s\\n%s: %s\\n%s:\\n%s\\n" "Exit code" "$ERR" "Logfile" "$LOGSDIR/$LOGFILE.xz" "Output" "$(<"$LOGSDIR/$LOGFILE")" | mail -r "$EMAIL_FROM" -s "SboSrcArch $1" "$(for i in $(seq -s ' ' 0 $(( ${#EMAIL_CC[@]} -1 ))); do echo ${EMAIL_CC[$i]:+-c "${EMAIL_CC[$i]}"}; done)" "${EMAIL_TO[@]}" >/dev/null 2>&1 || {
printf "%s: %s\\n" "${0##*/}" "mail command failed" >&2
return 1
}
@ -30,8 +30,7 @@ umask 027
# Only run for the configured sbosrcarch user.
[[ "$(whoami)" != "$SBOSRCARCH_USER" ]] && {
printf "%s: %s\\n" "${0##*/}" "must be run by the '$SBOSRCARCH_USER' user" >&2
printf "%s: %s: %s\\n" "${0##*/}" "to run manually:" "su '$SBOSRCARCH_USER' $0 $@" >&2
printf "%s: %s\\n" "${0##*/}" "must be run by the '$SBOSRCARCH_USER' user - use su to run manually" >&2
exit 1
}
@ -67,29 +66,18 @@ fi
sudo /opt/sbin/drop-caches
# Make sure there's no errant ownerships.
printf "%s: %s\\n" "INFO" "Scanning sbosrcarch directory for correct ownerships/permissions" | tee "$LOGSDIR/$LOGFILE"
WRONG="$(find "$DEPOSITORY/" \( \
\( -type b -o -type c -o -type p -o -type s \) -o \
\( -type l -a \! -perm 777 \) -o \
\( -type d -a \! -perm 755 -a \! -perm 2755 \) -o \
\( -type f -a \! -perm 644 -a \! -perm 755 \) -o \
\( \! -user "$SBOSRCARCH_USER" \) -o \
\( \! -group "$DEPOSITORY_GROUP" \) \
\) -a -printf "%u:%g\t%M\t%p\n")"
if [[ -n "$WRONG" ]]; then
printf "%s: %s\\n" "ERROR" "This run has been aborted!" | tee -a "$LOGSDIR/$LOGFILE"
printf "%s: %s\\n" "WARNING" "The following paths have erronious ownerships/permissions:" | tee -a "$LOGSDIR/$LOGFILE"
printf "%s\\n" "$WRONG" | sed -re 's/^/ /g' | tee -a "$LOGSDIR/$LOGFILE"
#WRONG_PERMS="$(find "$DEPOSITORY" \( \! -user "$SBOSRCARCH_USER" -o \! -group "$DEPOSITORY_GROUP" \) -a \! -path "$DEPOSITORY" -printf "%u:%g\t%P\n")"
if [[ -n "$WRONG_PERMS" ]]; then
printf "%s\\n" "This run has been aborted!" >"$LOGSDIR/$LOGFILE"
printf "%s\\n" "The following files in have errant permissions:" >>"$LOGSDIR/$LOGFILE"
printf "%s\\n" "$WRONG_PERMS" >>"$LOGSDIR/$LOGFILE"
ERR=-1
else
printf "%s: %s\\n" "INFO" "No ownership/permission issues found" | tee -a "$LOGSDIR/$LOGFILE"
# Do the sbosrcarch work.
umask 022
printf "%s: %s: %s\\n" "INFO" "Beginning sbosrcarch run" "sg \"$DEPOSITORY_GROUP\" -c \"$COMMAND ${1:-update}\"" | tee -a "$LOGSDIR/$LOGFILE"
TMP_OUTPUT="$(sg "$DEPOSITORY_GROUP" -c "$COMMAND ${1:-update} 2>&1")"
sg "$DEPOSITORY_GROUP" -c "$COMMAND ${1:-update}" >"$LOGSDIR/$LOGFILE" 2>&1
ERR="$?"
sg "$DEPOSITORY_GROUP" -c "$COMMAND status 2>&1" | tee -a "$LOGSDIR/$LOGFILE"
printf "\\n%s\\n" "$TMP_OUTPUT" | tee -a "$LOGSDIR/$LOGFILE"
printf "\\n" >>"$LOGSDIR/$LOGFILE"
sg "$DEPOSITORY_GROUP" -c "$COMMAND status" >>"$LOGSDIR/$LOGFILE" 2>&1
(( ERR += $? ))
fi