localized variables
This commit is contained in:
parent
706c101593
commit
11fc9db848
@ -4,21 +4,21 @@ function g_backup {
|
|||||||
|
|
||||||
#### Config defaults
|
#### Config defaults
|
||||||
# dir(s) to backup (: separated)
|
# dir(s) to backup (: separated)
|
||||||
BACKUPDIRS=""
|
local BACKUPDIRS=""
|
||||||
# Excludefile für rsync
|
# Excludefile für rsync
|
||||||
BACKUPEXCLUDES=""
|
local BACKUPEXCLUDES=""
|
||||||
# Backup-Server (Backup-Destination)
|
# Backup-Server (Backup-Destination)
|
||||||
BACKUPSRV=""
|
local BACKUPSRV=""
|
||||||
# SSH Port
|
# SSH Port
|
||||||
BACKUPSRVPORT="22"
|
local BACKUPSRVPORT="22"
|
||||||
# SSH User
|
# SSH User
|
||||||
BACKUPSRVUSER=""
|
local BACKUPSRVUSER=""
|
||||||
# Destination path on Backup-Server
|
# Destination path on Backup-Server
|
||||||
BACKUPSRVPATH=""
|
local BACKUPSRVPATH=""
|
||||||
# run optional command on server and start backup only on success
|
# run optional command on server and start backup only on success
|
||||||
BACKUPSRVTESTCMD=""
|
local BACKUPSRVTESTCMD=""
|
||||||
# Copy only without hostname/backup-date Structure
|
# Copy only without hostname/backup-date Structure
|
||||||
NODIRSTRUCT=""
|
local NODIRSTRUCT=""
|
||||||
|
|
||||||
g_tries=5
|
g_tries=5
|
||||||
g_tries_delay=120
|
g_tries_delay=120
|
||||||
@ -37,7 +37,7 @@ function g_backup {
|
|||||||
[ -n "$7" ] && BACKUPSRVTESTCMD=$7
|
[ -n "$7" ] && BACKUPSRVTESTCMD=$7
|
||||||
[ -n "$8" ] && NODIRSTRUCT=$8
|
[ -n "$8" ] && NODIRSTRUCT=$8
|
||||||
|
|
||||||
usage="
|
local usage="
|
||||||
$0 BACKUPDIR1[:BACKUPDIR2:BACKUPDIR3] BACKUPPATH [BACKUPEXCLUDES BACKUPSRV BACKUPSRVPORT BACKUPSRVUSER BACKUPSRVTESTCMD NODIRSTRUCT]"
|
$0 BACKUPDIR1[:BACKUPDIR2:BACKUPDIR3] BACKUPPATH [BACKUPEXCLUDES BACKUPSRV BACKUPSRVPORT BACKUPSRVUSER BACKUPSRVTESTCMD NODIRSTRUCT]"
|
||||||
|
|
||||||
[ -z "$BACKUPDIRS" ] && g_echo_error "No Directory to Backup (BACKUPDIR) given $usage" && return 1
|
[ -z "$BACKUPDIRS" ] && g_echo_error "No Directory to Backup (BACKUPDIR) given $usage" && return 1
|
||||||
@ -89,8 +89,8 @@ var-lib-docker
|
|||||||
if [ -n "$BACKUPSRV" ]
|
if [ -n "$BACKUPSRV" ]
|
||||||
then
|
then
|
||||||
[ -z "$BACKUPSRVPORT" ] && g_echo_error "No SSH-Port given $usage" && return 1
|
[ -z "$BACKUPSRVPORT" ] && g_echo_error "No SSH-Port given $usage" && return 1
|
||||||
sshopts="g_retrycmd ssh -n -p $BACKUPSRVPORT -o BatchMode=yes -o StrictHostKeyChecking=accept-new $BACKUPSRVUSER@$BACKUPSRV"
|
local sshopts="g_retrycmd ssh -n -p $BACKUPSRVPORT -o BatchMode=yes -o StrictHostKeyChecking=accept-new $BACKUPSRVUSER@$BACKUPSRV"
|
||||||
sshoptsnoretry="ssh -n -p $BACKUPSRVPORT -o BatchMode=yes -o StrictHostKeyChecking=accept-new $BACKUPSRVUSER@$BACKUPSRV"
|
local sshoptsnoretry="ssh -n -p $BACKUPSRVPORT -o BatchMode=yes -o StrictHostKeyChecking=accept-new $BACKUPSRVUSER@$BACKUPSRV"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rsyncopts="-aXAh --no-inc-recursive --timeout=180 --force -yy --one-file-system --open-noatime --delete-after --ignore-missing-args --partial"
|
rsyncopts="-aXAh --no-inc-recursive --timeout=180 --force -yy --one-file-system --open-noatime --delete-after --ignore-missing-args --partial"
|
||||||
@ -98,10 +98,10 @@ var-lib-docker
|
|||||||
[ -n "$BACKUPSRV" ] && rsyncopts="$rsyncopts -e 'ssh -p $BACKUPSRVPORT'"
|
[ -n "$BACKUPSRV" ] && rsyncopts="$rsyncopts -e 'ssh -p $BACKUPSRVPORT'"
|
||||||
[ "$BACKUPSRVUSER" == "root" ] && syncopts="$rsyncopts --numeric-ids"
|
[ "$BACKUPSRVUSER" == "root" ] && syncopts="$rsyncopts --numeric-ids"
|
||||||
|
|
||||||
ORIGIFS="$IFS"
|
local ORIGIFS="$IFS"
|
||||||
IFS=':'
|
IFS=':'
|
||||||
# Prepare Dest-Dir on Backup-Server
|
# Prepare Dest-Dir on Backup-Server
|
||||||
CMDS="mkdir -p ${BACKUPSRVPATH}/$(hostname):chmod 700 ${BACKUPSRVPATH}/$(hostname)"
|
local CMDS="mkdir -p ${BACKUPSRVPATH}/$(hostname):chmod 700 ${BACKUPSRVPATH}/$(hostname)"
|
||||||
[ -n "$NODIRSTRUCT" ] && CMDS="mkdir -p ${BACKUPSRVPATH}"
|
[ -n "$NODIRSTRUCT" ] && CMDS="mkdir -p ${BACKUPSRVPATH}"
|
||||||
[ -n "$BACKUPSRVTESTCMD" ] && CMDS="$BACKUPSRVTESTCMD:$CMDS"
|
[ -n "$BACKUPSRVTESTCMD" ] && CMDS="$BACKUPSRVTESTCMD:$CMDS"
|
||||||
for CMD in $CMDS
|
for CMD in $CMDS
|
||||||
@ -151,7 +151,7 @@ var-lib-docker
|
|||||||
# move from -incomplete to default dir
|
# move from -incomplete to default dir
|
||||||
g_runcmd $sshopts mv "$BACKUPSRVPATH_WITH_DATE_INCOMPLETE" "$BACKUPSRVPATH_WITH_DATE" || continue
|
g_runcmd $sshopts mv "$BACKUPSRVPATH_WITH_DATE_INCOMPLETE" "$BACKUPSRVPATH_WITH_DATE" || continue
|
||||||
|
|
||||||
yearmonth="$(date +%Y-%m-)"
|
local yearmonth="$(date +%Y-%m-)"
|
||||||
|
|
||||||
# Create monthly dir if not exists
|
# Create monthly dir if not exists
|
||||||
BACKUPSRVPATH_MONTHLY="$BACKUPSRVPATH_WITH_HOST/backup-${yearmonth}monthly/$BACKUPDIR"
|
BACKUPSRVPATH_MONTHLY="$BACKUPSRVPATH_WITH_HOST/backup-${yearmonth}monthly/$BACKUPDIR"
|
||||||
@ -164,7 +164,7 @@ var-lib-docker
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Cleanup old backups
|
# Cleanup old backups
|
||||||
yearmonthbefore="$(date +%Y-%m- --date='-1 month')"
|
local yearmonthbefore="$(date +%Y-%m- --date='-1 month')"
|
||||||
$sshopts find $BACKUPSRVPATH_WITH_HOST -mindepth 1 -maxdepth 1 -type d -name "backup-*" | egrep -v "backup-$yearmonth|backup-$yearmonthbefore|backup-20[0-9][0-9]-[0-9][0-9]-monthly" | while read g_toremove
|
$sshopts find $BACKUPSRVPATH_WITH_HOST -mindepth 1 -maxdepth 1 -type d -name "backup-*" | egrep -v "backup-$yearmonth|backup-$yearmonthbefore|backup-20[0-9][0-9]-[0-9][0-9]-monthly" | while read g_toremove
|
||||||
do
|
do
|
||||||
g_echo_warn "Removing old Backup $g_toremove"
|
g_echo_warn "Removing old Backup $g_toremove"
|
||||||
|
Loading…
Reference in New Issue
Block a user