fixes and additions
This commit is contained in:
parent
b1122df33a
commit
6e309e9bae
@ -4,7 +4,7 @@ function g_backup {
|
|||||||
|
|
||||||
#### Config defaults
|
#### Config defaults
|
||||||
# dir(s) to backup (: separated)
|
# dir(s) to backup (: separated)
|
||||||
BACKUPDIRS=/""
|
BACKUPDIRS=""
|
||||||
# Excludefile für rsync
|
# Excludefile für rsync
|
||||||
BACKUPEXCLUDES=""
|
BACKUPEXCLUDES=""
|
||||||
# Backup-Server (Backup-Destination)
|
# Backup-Server (Backup-Destination)
|
||||||
@ -40,16 +40,52 @@ function g_backup {
|
|||||||
usage="
|
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_exit "No Directory to Backup (BACKUPDIR) given $usage"
|
[ -z "$BACKUPDIRS" ] && g_echo_error "No Directory to Backup (BACKUPDIR) given $usage" && return 1
|
||||||
[ -z "$BACKUPSRVPATH" ] && g_echo_error_exit "No path to put the Backup (BACKUPPATH) given $usage"
|
[ -z "$BACKUPSRVPATH" ] && g_echo_error "No path to put the Backup (BACKUPPATH) given $usage" && return 1
|
||||||
|
|
||||||
|
if [ "$BACKUPEXCLUDES" == "default" ]
|
||||||
|
then
|
||||||
|
BACKUPEXCLUDES="$g_tmp/default-excludes"
|
||||||
|
echo '.local/share/keyrings/*temp*
|
||||||
|
.local/share/gvfs-metadata
|
||||||
|
.local/share/Trash
|
||||||
|
.unison*
|
||||||
|
unison.log
|
||||||
|
.unison.sh.log
|
||||||
|
.local/share/Steam/
|
||||||
|
dwhelper
|
||||||
|
.cache
|
||||||
|
vpn
|
||||||
|
.config/Nextcloud/
|
||||||
|
.VirtualBox/
|
||||||
|
.g_tmp
|
||||||
|
DMS/
|
||||||
|
tmp
|
||||||
|
.zoom/
|
||||||
|
.steam/
|
||||||
|
pagefile.sys
|
||||||
|
.config/Signal/
|
||||||
|
.var/app/com.microsoft.Teams
|
||||||
|
GTC/
|
||||||
|
.xsession-errors*
|
||||||
|
part.dd
|
||||||
|
.var/app/org.mozilla.firefox/*/cache/*
|
||||||
|
.local/share/Steam
|
||||||
|
Nextcloud/
|
||||||
|
/proc/
|
||||||
|
/sys/
|
||||||
|
/dev/
|
||||||
|
/run/
|
||||||
|
/mnt/' >$g_tmp/default-excludes
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "$BACKUPSRV" ]
|
if [ -n "$BACKUPSRV" ]
|
||||||
then
|
then
|
||||||
[ -z "$BACKUPSRVPORT" ] && g_echo_error_exit "No SSH-Port given $usage"
|
[ -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"
|
sshopts="g_retrycmd ssh -n -p $BACKUPSRVPORT -o BatchMode=yes -o StrictHostKeyChecking=accept-new $BACKUPSRVUSER@$BACKUPSRV"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rsyncopts="-aXAh --delete --ignore-missing-args --inplace"
|
rsyncopts="-aXAh --delete --ignore-missing-args --inplace --partial"
|
||||||
[ -n "$BACKUPEXCLUDES" ] && rsyncopts="$rsyncopts --delete-excluded --exclude-from=$BACKUPEXCLUDES"
|
[ -n "$BACKUPEXCLUDES" ] && rsyncopts="$rsyncopts --delete-excluded --exclude-from=$BACKUPEXCLUDES"
|
||||||
[ -n "$BACKUPSRV" ] && rsyncopts="$rsyncopts -e 'ssh -p $BACKUPSRVPORT'"
|
[ -n "$BACKUPSRV" ] && rsyncopts="$rsyncopts -e 'ssh -p $BACKUPSRVPORT'"
|
||||||
|
|
||||||
@ -62,14 +98,14 @@ function g_backup {
|
|||||||
for CMD in $CMDS
|
for CMD in $CMDS
|
||||||
do
|
do
|
||||||
IFS="$ORIGIFS"
|
IFS="$ORIGIFS"
|
||||||
g_runcmd $sshopts $CMD || exit $?
|
g_runcmd $sshopts $CMD || return $?
|
||||||
done
|
done
|
||||||
|
|
||||||
IFS=':'
|
IFS=':'
|
||||||
for BACKUPDIR in $BACKUPDIRS
|
for BACKUPDIR in $BACKUPDIRS
|
||||||
do
|
do
|
||||||
IFS="$ORIGIFS"
|
IFS="$ORIGIFS"
|
||||||
rsyncoptsrun=$rsyncopts
|
rsyncoptsrun="$rsyncopts"
|
||||||
|
|
||||||
# prepare paths
|
# prepare paths
|
||||||
if [ -z "$NODIRSTRUCT" ]
|
if [ -z "$NODIRSTRUCT" ]
|
||||||
@ -78,31 +114,26 @@ function g_backup {
|
|||||||
BACKUPSRVPATH_WITH_HOST="$BACKUPSRVPATH/$(hostname)"
|
BACKUPSRVPATH_WITH_HOST="$BACKUPSRVPATH/$(hostname)"
|
||||||
BACKUPSRVPATH_WITH_DATE="$BACKUPSRVPATH_WITH_HOST/backup-$(date +%Y-%m-%d)/$BACKUPDIR"
|
BACKUPSRVPATH_WITH_DATE="$BACKUPSRVPATH_WITH_HOST/backup-$(date +%Y-%m-%d)/$BACKUPDIR"
|
||||||
BACKUPSRVPATH_WITH_DATE_INCOMPLETE="$BACKUPSRVPATH_WITH_DATE-incomplete"
|
BACKUPSRVPATH_WITH_DATE_INCOMPLETE="$BACKUPSRVPATH_WITH_DATE-incomplete"
|
||||||
g_runcmd $sshopts "mkdir -p $BACKUPSRVPATH_WITH_DATE_INCOMPLETE" || exit $?
|
g_runcmd $sshopts mkdir -p "$BACKUPSRVPATH_WITH_DATE_INCOMPLETE" || continue
|
||||||
BACKUPSRVPATH_LINK_DEST="$($sshopts ls -d $BACKUPSRVPATH_WITH_HOST/backup-*/$BACKUPDIR 2>/dev/null | egrep -v incomplete$ | tail -n1)"
|
BACKUPSRVPATH_LINK_DEST="$($sshopts ls -d "$BACKUPSRVPATH_WITH_HOST/backup-*/$BACKUPDIR" 2>/dev/null | egrep -v incomplete$ | tail -n1)"
|
||||||
# linkdest
|
# linkdest
|
||||||
[ -n "$BACKUPSRVPATH_LINK_DEST" ] && rsyncoptsrun="$rsyncoptsrun --link-dest=$BACKUPSRVPATH_LINK_DEST"
|
[ -n "$BACKUPSRVPATH_LINK_DEST" ] && rsyncoptsrun="$rsyncoptsrun --link-dest=$BACKUPSRVPATH_LINK_DEST"
|
||||||
else
|
else
|
||||||
BACKUPSRVPATH_WITH_DATE_INCOMPLETE="/$BACKUPSRVPATH"
|
BACKUPSRVPATH_WITH_DATE_INCOMPLETE="$BACKUPSRVPATH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Backup
|
# Backup
|
||||||
[ -n "$BACKUPSRV" ] && sshrsync="$BACKUPSRVUSER@$BACKUPSRV:"
|
[ -n "$BACKUPSRV" ] && sshrsync="$BACKUPSRVUSER@$BACKUPSRV:"
|
||||||
set -x
|
g_runcmd g_retrycmd rsync $rsyncoptsrun "$BACKUPDIR"/ "${sshrsync}$BACKUPSRVPATH_WITH_DATE_INCOMPLETE"/ || continue
|
||||||
g_runcmd g_retrycmd rsync $rsyncoptsrun "$BACKUPDIR"/ "${sshrsync}$BACKUPSRVPATH_WITH_DATE_INCOMPLETE"/ || exit $?
|
|
||||||
# echo "g_retrycmd rsync $rsyncoptsrun $BACKUPDIR/ ${sshrsync}$BACKUPSRVPATH_WITH_DATE_INCOMPLETE/" >$g_tmp/bcmd
|
|
||||||
# g_echo "Running Backup $BACKUPDIR with
|
|
||||||
#$(cat $g_tmp/bcmd)"
|
|
||||||
# g_runcmd bash $g_tmp/bcmd || exit $?
|
|
||||||
|
|
||||||
# done if no direstructure
|
# done if no direstructure
|
||||||
[ -n "$NODIRSTRUCT" ] && continue
|
[ -n "$NODIRSTRUCT" ] && continue
|
||||||
|
|
||||||
# if backups from this day already exists move it to $BACKUPSRVPATH_WITH_DATE-$$-old
|
# if backups from this day already exists move it to $BACKUPSRVPATH_WITH_DATE-$$-old
|
||||||
$sshopts test -e $BACKUPSRVPATH_WITH_DATE && $sshopts mv $BACKUPSRVPATH_WITH_DATE $BACKUPSRVPATH_WITH_DATE-$$-old
|
g_runcmd $sshopts test -e "$BACKUPSRVPATH_WITH_DATE" && $sshopts mv "$BACKUPSRVPATH_WITH_DATE" "$BACKUPSRVPATH_WITH_DATE-$$-old"
|
||||||
|
|
||||||
# move from -incomplete to default dir
|
# move from -incomplete to default dir
|
||||||
$sshopts mv $BACKUPSRVPATH_WITH_DATE_INCOMPLETE $BACKUPSRVPATH_WITH_DATE || exit $?
|
g_runcmd $sshopts mv "$BACKUPSRVPATH_WITH_DATE_INCOMPLETE" "$BACKUPSRVPATH_WITH_DATE" || continue
|
||||||
|
|
||||||
yearmonth="$(date +%Y-%m-)"
|
yearmonth="$(date +%Y-%m-)"
|
||||||
|
|
||||||
@ -111,9 +142,9 @@ function g_backup {
|
|||||||
if ! $sshopts test -e "$BACKUPSRVPATH_MONTHLY"
|
if ! $sshopts test -e "$BACKUPSRVPATH_MONTHLY"
|
||||||
then
|
then
|
||||||
g_echo "Creating monthly-Backup $BACKUPSRVPATH_MONTHLY"
|
g_echo "Creating monthly-Backup $BACKUPSRVPATH_MONTHLY"
|
||||||
$sshopts mkdir -p "$BACKUPSRVPATH_MONTHLY"
|
g_runcmd $sshopts mkdir -p "$BACKUPSRVPATH_MONTHLY" || continue
|
||||||
$sshopts mv -T "$BACKUPSRVPATH_WITH_DATE" "$BACKUPSRVPATH_MONTHLY"
|
g_runcmd $sshopts mv -T "$BACKUPSRVPATH_WITH_DATE" "$BACKUPSRVPATH_MONTHLY" || continue
|
||||||
$sshopts ln -s "$BACKUPSRVPATH_MONTHLY" "$BACKUPSRVPATH_WITH_DATE"
|
g_runcmd $sshopts ln -s "$BACKUPSRVPATH_MONTHLY" "$BACKUPSRVPATH_WITH_DATE" || continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cleanup old backups
|
# Cleanup old backups
|
||||||
@ -121,7 +152,7 @@ function g_backup {
|
|||||||
$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 Backup $g_toremove"
|
g_echo_warn "Removing Backup $g_toremove"
|
||||||
$sshopts rm -r "$g_toremove"
|
g_runcmd $sshopts rm -r "$g_toremove"
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user