Compare commits
3 commits
82d3b7fccb
...
ccbfd96242
| Author | SHA1 | Date | |
|---|---|---|---|
| ccbfd96242 | |||
| 0ef6396933 | |||
| 3feac1663d |
3 changed files with 58 additions and 25 deletions
4
drop-caches
Executable file
4
drop-caches
Executable file
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Used by the mirroring user to refresh the nfs cache before doing a mirroring run.
|
||||||
|
|
||||||
|
echo 3 >/proc/sys/vm/drop_caches
|
||||||
26
mirror
26
mirror
|
|
@ -17,7 +17,7 @@ MAX_RUNS="3" # Maximum number of runs
|
||||||
IPV4="5.101.171.215"
|
IPV4="5.101.171.215"
|
||||||
DATADIR="/data/depository"
|
DATADIR="/data/depository"
|
||||||
RSYNC_COMMAND="/usr/bin/rsync"
|
RSYNC_COMMAND="/usr/bin/rsync"
|
||||||
RSYNC_REMOTE_OPTIONS=('-4' "--address=$IPV4" '--no-motd' '--contimeout=30' '--timeout=60' '-aH' '--chmod=go-w,+rX' '--partial' '--partial-dir=.rsync-tmp' '--delete-delay' '--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_LOCAL_OPTIONS=('-aH' '--chmod=go-w,+rX' '--partial' '--partial-dir=.rsync-tmp' '--delay-updates')
|
||||||
# RSYNC_VERBOSE=('--verbose' '--human-readable')
|
# RSYNC_VERBOSE=('--verbose' '--human-readable')
|
||||||
# RSYNC_VERBOSE=('--progress' '--verbose' '--stats' '--human-readable')
|
# RSYNC_VERBOSE=('--progress' '--verbose' '--stats' '--human-readable')
|
||||||
|
|
@ -163,6 +163,24 @@ SLACKARCHIVE_FILTER=('--exclude=source/' '--include=/slackware-15.0' '--include=
|
||||||
|
|
||||||
#######################################################################################################################################
|
#######################################################################################################################################
|
||||||
|
|
||||||
|
# Only allow the script to be run from the wrapper.
|
||||||
|
[[ ! -v MIRRORING_USER ]] && {
|
||||||
|
echo "ERROR: this script should only be run by mirror-wrapper" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Make sure the users match.
|
||||||
|
[[ "$(whoami)" != "$MIRRORING_USER" ]] && {
|
||||||
|
echo "ERROR: this script should be run by the '$MIRRORING_USER' only - use su to run manually" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Move to the depository directory.
|
||||||
|
cd "$DATADIR" >/dev/null 2>&1 || {
|
||||||
|
echo "ERROR: $DATADIR does not exist." >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
# Only allow one copy of the script to run at any time.
|
# Only allow one copy of the script to run at any time.
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
if [[ "$FLOCK" != "$0" ]]; then
|
if [[ "$FLOCK" != "$0" ]]; then
|
||||||
|
|
@ -178,12 +196,6 @@ if [[ "$FLOCK" != "$0" ]]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Move to the depository directory.
|
|
||||||
cd "$DATADIR" >/dev/null 2>&1 || {
|
|
||||||
echo "ERROR: $DATADIR does not exist." >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
declare -a LFTP_LIST RSYNC_LIST
|
declare -a LFTP_LIST RSYNC_LIST
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@
|
||||||
|
|
||||||
# Configuration.
|
# Configuration.
|
||||||
COMMAND="/opt/bin/mirror"
|
COMMAND="/opt/bin/mirror"
|
||||||
|
DEPOSITORY="/data/depository"
|
||||||
|
MIRRORING_USER="mirroring"
|
||||||
|
SBOSRCARCH_USER="sbosrcarch"
|
||||||
|
DEPOSITORY_GROUP="depository"
|
||||||
LOGSDIR="/var/log/duplication/mirroring/$(printf "%(%Y/%m)T")"
|
LOGSDIR="/var/log/duplication/mirroring/$(printf "%(%Y/%m)T")"
|
||||||
LOGFILE="$(printf "%(%Y%m%d-%H%M%S)T")-$$"
|
LOGFILE="$(printf "%(%Y%m%d-%H%M%S)T")-$$"
|
||||||
MIN_LOGFILE_SIZE="650" # 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.
|
||||||
|
|
@ -22,9 +26,22 @@ notify() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Don't run as root!
|
# Only run for the configured mirroring user.
|
||||||
(( $(id -u) == 0 )) && {
|
[[ "$(whoami)" != "$MIRRORING_USER" ]] && {
|
||||||
printf "%s: %s\\n" "${0##*/}" "don't run me as root - it messes up permissions!" >&2
|
printf "%s: %s\\n" "${0##*/}" "must be run by the '$MIRRORING_USER' user - use su to run manually" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Make sure the logs directory exists.
|
||||||
|
# shellcheck disable=SC2174
|
||||||
|
mkdir -p -m 750 "$LOGSDIR" 2>/dev/null || {
|
||||||
|
printf "%s: %s\\n" "${0##*/}" "Failed to create logs directory '$LOGSDIR'" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Make sure the command to do the work is runnable.
|
||||||
|
[[ ! -x "$COMMAND" ]] && {
|
||||||
|
printf "%s: %s\\n" "${0##*/}" "'$COMMAND' is not executable" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,22 +63,22 @@ fi
|
||||||
# Logs are only for root.
|
# Logs are only for root.
|
||||||
umask 027
|
umask 027
|
||||||
|
|
||||||
# Make sure the logs directory exists.
|
# Drop the caches as sometimes old user/groups are cached.
|
||||||
# shellcheck disable=SC2174
|
sudo /opt/sbin/drop-caches
|
||||||
mkdir -p -m 750 "$LOGSDIR" 2>/dev/null || {
|
|
||||||
printf "%s: %s\\n" "${0##*/}" "Failed to create logs directory '$LOGSDIR'" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Make sure the command to do the work is runnable.
|
# Make sure there's no errant ownerships.
|
||||||
[[ ! -x "$COMMAND" ]] && {
|
WRONG_PERMS="$(find "$DEPOSITORY" \( \( \! -user "$MIRRORING_USER" -a \! -user "$SBOSRCARCH_USER" \) -o \( \! -group "$DEPOSITORY_GROUP" \) \) -a \! -path "$DEPOSITORY" -printf "%u:%g\t%P\n")"
|
||||||
printf "%s: %s\\n" "${0##*/}" "'$COMMAND' is not executable" >&2
|
if [[ -n "$WRONG_PERMS" ]]; then
|
||||||
exit 1
|
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"
|
||||||
# Do the mirroring work.
|
ERR=-1
|
||||||
"$COMMAND" "$@" >"$LOGSDIR/$LOGFILE" 2>&1
|
else
|
||||||
ERR="$?"
|
# Do the mirroring work.
|
||||||
|
export MIRRORING_USER
|
||||||
|
sg "$DEPOSITORY_GROUP" -c "$COMMAND" "$@" >"$LOGSDIR/$LOGFILE" 2>&1
|
||||||
|
ERR="$?"
|
||||||
|
fi
|
||||||
|
|
||||||
# Tell the sysadmin what went on.
|
# Tell the sysadmin what went on.
|
||||||
if (( "$ERR" == 0 )); then
|
if (( "$ERR" == 0 )); then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue