localized variables
This commit is contained in:
parent
706c101593
commit
11fc9db848
@ -4,21 +4,21 @@ function g_backup {
|
||||
|
||||
#### Config defaults
|
||||
# dir(s) to backup (: separated)
|
||||
BACKUPDIRS=""
|
||||
local BACKUPDIRS=""
|
||||
# Excludefile für rsync
|
||||
BACKUPEXCLUDES=""
|
||||
local BACKUPEXCLUDES=""
|
||||
# Backup-Server (Backup-Destination)
|
||||
BACKUPSRV=""
|
||||
local BACKUPSRV=""
|
||||
# SSH Port
|
||||
BACKUPSRVPORT="22"
|
||||
local BACKUPSRVPORT="22"
|
||||
# SSH User
|
||||
BACKUPSRVUSER=""
|
||||
local BACKUPSRVUSER=""
|
||||
# Destination path on Backup-Server
|
||||
BACKUPSRVPATH=""
|
||||
local BACKUPSRVPATH=""
|
||||
# run optional command on server and start backup only on success
|
||||
BACKUPSRVTESTCMD=""
|
||||
local BACKUPSRVTESTCMD=""
|
||||
# Copy only without hostname/backup-date Structure
|
||||
NODIRSTRUCT=""
|
||||
local NODIRSTRUCT=""
|
||||
|
||||
g_tries=5
|
||||
g_tries_delay=120
|
||||
@ -37,7 +37,7 @@ function g_backup {
|
||||
[ -n "$7" ] && BACKUPSRVTESTCMD=$7
|
||||
[ -n "$8" ] && NODIRSTRUCT=$8
|
||||
|
||||
usage="
|
||||
local usage="
|
||||
$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
|
||||
@ -89,8 +89,8 @@ var-lib-docker
|
||||
if [ -n "$BACKUPSRV" ]
|
||||
then
|
||||
[ -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"
|
||||
sshoptsnoretry="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"
|
||||
local sshoptsnoretry="ssh -n -p $BACKUPSRVPORT -o BatchMode=yes -o StrictHostKeyChecking=accept-new $BACKUPSRVUSER@$BACKUPSRV"
|
||||
fi
|
||||
|
||||
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'"
|
||||
[ "$BACKUPSRVUSER" == "root" ] && syncopts="$rsyncopts --numeric-ids"
|
||||
|
||||
ORIGIFS="$IFS"
|
||||
local ORIGIFS="$IFS"
|
||||
IFS=':'
|
||||
# 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 "$BACKUPSRVTESTCMD" ] && CMDS="$BACKUPSRVTESTCMD:$CMDS"
|
||||
for CMD in $CMDS
|
||||
@ -151,7 +151,7 @@ var-lib-docker
|
||||
# move from -incomplete to default dir
|
||||
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
|
||||
BACKUPSRVPATH_MONTHLY="$BACKUPSRVPATH_WITH_HOST/backup-${yearmonth}monthly/$BACKUPDIR"
|
||||
@ -164,7 +164,7 @@ var-lib-docker
|
||||
fi
|
||||
|
||||
# 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
|
||||
do
|
||||
g_echo_warn "Removing old Backup $g_toremove"
|
||||
|
Loading…
Reference in New Issue
Block a user