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

View File

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