sync.sh: remove FILTER variable

This commit is contained in:
2022-05-27 21:54:51 +02:00
parent f55e565aac
commit 71ea8e5881
2 changed files with 50 additions and 46 deletions

View File

@@ -14,51 +14,51 @@
# USAGE: # USAGE:
# sync.sh -rfu /path/to/sync-conf-example.sh # sync.sh -rfu /path/to/sync-conf-example.sh
# full source path # below, default values are just below the lines starting with '######'.
# The only mandatory ones are SOURCEDIR, SERVER, and DESTDIR.
###### source directory full path, destination server and path.
###### SERVER could user@host, or "local" if local machine
# SOURCEDIR=""
# SERVER=""
# DESTDIR=""
SOURCEDIR=/example-srcdir SOURCEDIR=/example-srcdir
# server name. Could also be user@hostname SERVER=root@backuphost
SERVER=backuphost DESTDIR=/mnt/nas1/example-destdir
# full destination path on target machine (or relative to home directory)
DESTDIR=/mnt/array3+4/example-destdir
# backups to keep ###### backups to keep
NYEARS=2 # NYEARS=3
NMONTHS=12 # NMONTHS=12
NWEEKS=4 # NWEEKS=6
NDAYS=7 # NDAYS=10
# FILTER can be used to filter directories to include/exclude. See rsync(1) for ###### other rsync options. It must be an array.
# details. # RSYNCOPTS=()
FILTER="--filter=dir-merge .rsync-filter-br" FILTERNAME=".rsync-filter-system"
FILTER=--filter="dir-merge ${FILTERNAME}"
RSYNCOPTS+=("$FILTER")
# other rsync options. It must be an array. For example, the following line ###### functions run immediately before and after the rsync. Can be used
# is equivalent to the FILTER line above: ###### to create database dumps, etc...
# RSYNCOPTS=( "--filter=dir-merge .rsync-filter-br" ) ###### Warning: avoid using "cd", or be sure to come back to current dir
RSYNCOPTS=() ###### before returning from functions
# beforesync() { log "calling default beforesync..."; }
# aftersync() { log "calling default aftersync..."; }
# functions run just before and after the rsync. Could be useful to create # example below will create a mysql/mariadb dump. At same time we create
# database dumps, etc... # a FILTERNAME file in database data directory to exclude databases directories
# Warning: avoid using "cd", or be sure to come back to current dir # themselves.
# before returning from functions
# example below will create a dump
function beforesync() { function beforesync() {
# next line may be removed if you do something. bash does not like empty
# functions
:
# log is a sync.sh function. # log is a sync.sh function.
log -s -t "calling user beforesync: mysql databases dumps..." log -s -t "calling user beforesync: mysql databases dumps..."
datadir=$(mysql -sN -u root -e 'select @@datadir') datadir="$(mysql -sN -u root -e 'select @@datadir')"
# log "mysql datadir=${datadir}"
rm -f "$datadir/$FILTERNAME" rm -f "$datadir/$FILTERNAME"
databases=($(mysql -sN -u root -e "SHOW DATABASES;")) readarray databases <<< "$(mysql -sN -u root -e "SHOW DATABASES;")"
for db in "${databases[@]}" for db in "${databases[@]}"; do
do
# exclude database directory itself # exclude database directory itself
echo "- /${db}/*" >> "$datadir/$FILTERNAME" printf "- /%s/*\n " "$db" >> "$datadir/$FILTERNAME"
log -n "${db}... " log -n "${db}... "
case "$db" in case "$db" in
@@ -68,7 +68,7 @@ function beforesync() {
*) *)
log -n "dumping to ${datadir}${db}.sql... " log -n "dumping to ${datadir}${db}.sql... "
mysqldump --user=root --routines "$db" > "$datadir/$db.sql" mysqldump --user=root --routines "$db" > "$datadir/$db.sql"
# log -n "compressing... " log -n "compressing... "
gzip "$datadir/$db.sql" gzip "$datadir/$db.sql"
log "done." log "done."
esac esac
@@ -78,9 +78,6 @@ function beforesync() {
} }
function aftersync() { function aftersync() {
# next line may be removed if you do something. bash does not like empty
# functions
:
# we may remove the dump here... # we may remove the dump here...
log -s -t "calling user aftersync" log -s -t "calling user aftersync"
} }

View File

@@ -167,19 +167,20 @@ KEEPLOGFILE=n # (-l) keep log file
# options only settable in config file. # options only settable in config file.
NYEARS=3 # keep # years (int) NYEARS=3 # keep # years (int)
NMONTHS=12 # keep # months (int) NMONTHS=12 # keep # months (int)
NWEEKS=4 # keep # weeks (int) NWEEKS=6 # keep # weeks (int)
NDAYS=7 # keep # days (int) NDAYS=10 # keep # days (int)
declare -a RSYNCOPTS=() # other rsync options declare -a RSYNCOPTS=() # other rsync options
SOURCEDIR="." # source dir SOURCEDIR="" # source dir
DESTDIR="." # destination dir SERVER="" # backup server
DESTDIR="" # destination dir
MODIFYWINDOW=1 # accuracy for mod time comparison MODIFYWINDOW=1 # accuracy for mod time comparison
# these 2 functions can be overwritten in data file, to run specific actions # these 2 functions can be overwritten in data file, to run specific actions
# just before and after the actual sync # just before and after the actual sync
function beforesync () { beforesync() {
log "calling default beforesync..." log "calling default beforesync..."
} }
function aftersync () { aftersync() {
log "calling default aftersync..." log "calling default aftersync..."
} }
@@ -530,8 +531,15 @@ log "Config : %s\n" "$CONFIG"
log "Src dir: %s" "$SOURCEDIR" log "Src dir: %s" "$SOURCEDIR"
log "Dst dir: %s" "$SERVER:$DESTDIR" log "Dst dir: %s" "$SERVER:$DESTDIR"
log "Actions: %s" "${TODO[*]}" log "Actions: %s" "${TODO[*]}"
log "Filter: %s" "$FILTER" if (( ${#RSYNCOPTS[@]} )); then
log "Rsync additional options (%d): %s" "${#RSYNCOPTS[@]}" "${RSYNCOPTS[*]}" log -n "Rsync additional options (%d): " "${#RSYNCOPTS[@]}"
for opt in "${RSYNCOPTS[@]}"; do
log -n '\"%s\" ' "$opt"
done
log ""
else
log "Rsync additional options : None."
fi
log -n "Mail recipient: " log -n "Mail recipient: "
# shellcheck disable=SC2015 # shellcheck disable=SC2015
@@ -676,7 +684,6 @@ while [[ ${TODO[0]} != "" ]]; do
status=0 status=0
echorun rsync \ echorun rsync \
-aHixv \ -aHixv \
"$FILTER" \
"${RSYNCOPTS[@]}" \ "${RSYNCOPTS[@]}" \
$COMPRESS \ $COMPRESS \
$NUMID \ $NUMID \