changed to
This commit is contained in:
parent
188173eff1
commit
a1dee65712
38
sshbackup
38
sshbackup
|
@ -78,13 +78,13 @@ preflight()
|
||||||
if [ -z $sourcepath ]; then
|
if [ -z $sourcepath ]; then
|
||||||
echo "aborting mission. no source path given."
|
echo "aborting mission. no source path given."
|
||||||
return 1
|
return 1
|
||||||
elif [ -z $destinationpath ]; then
|
elif [ -z $destpath ]; then
|
||||||
echo "aborting mission. no destination path given."
|
echo "aborting mission. no destination path given."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#if remote source or destination check for sshkey
|
#if remote source or destination check for sshkey
|
||||||
if [[ $sourcepath =~ .*@.* ]] || [[ $destinationpath =~ .*@.* ]]; then
|
if [[ $sourcepath =~ .*@.* ]] || [[ $destpath =~ .*@.* ]]; then
|
||||||
if [ -r $sshkeyfile ]; then
|
if [ -r $sshkeyfile ]; then
|
||||||
#echo "sshkeyfile found. continuing."
|
#echo "sshkeyfile found. continuing."
|
||||||
:
|
:
|
||||||
|
@ -107,31 +107,31 @@ sshbackup()
|
||||||
|
|
||||||
#move existing versions
|
#move existing versions
|
||||||
local num=$versions
|
local num=$versions
|
||||||
while [ -d "$destinationpath/0" ]; do
|
while [ -d "$destpath/0" ]; do
|
||||||
if [ -d "$destinationpath/$num" ]; then
|
if [ -d "$destpath/$num" ]; then
|
||||||
mv $destinationpath/$num $destinationpath/$((num+1))
|
mv $destpath/$num $destpath/$((num+1))
|
||||||
fi
|
fi
|
||||||
let num--
|
let num--
|
||||||
done
|
done
|
||||||
|
|
||||||
#create destinationpath if not existing
|
#create destpath if not existing
|
||||||
mkdir -p $destinationpath/0
|
mkdir -p $destpath/0
|
||||||
|
|
||||||
#add link-destination option if existing
|
#add link-destination option if existing
|
||||||
if [ -d $destinationpath/1 ]; then
|
if [ -d $destpath/1 ]; then
|
||||||
cmdopt="$cmdopt --link-dest=$destinationpath/1"
|
cmdopt="$cmdopt --link-dest=$destpath/1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#run rsync
|
#run rsync
|
||||||
$localcmd $cmdopt -e "ssh -q -i $sshkeyfile" --rsync-path="$remotecmd" $sourcepath $destinationpath/0
|
$localcmd $cmdopt -e "ssh -q -i $sshkeyfile" --rsync-path="$remotecmd" $sourcepath $destpath/0
|
||||||
if [ $? -ne "0" ]; then
|
if [ $? -ne "0" ]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#removing obsolet version(s)
|
#removing obsolet version(s)
|
||||||
local i=1
|
local i=1
|
||||||
while [ -d $destinationpath/$((versions+i)) ]; do
|
while [ -d $destpath/$((versions+i)) ]; do
|
||||||
rm -rf $destinationpath/$((versions+i))
|
rm -rf $destpath/$((versions+i))
|
||||||
let i++
|
let i++
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -213,11 +213,11 @@ for option in $options; do
|
||||||
sourcepath="$(pwd)/${option%/}/*"
|
sourcepath="$(pwd)/${option%/}/*"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ -z "$destinationpath" ]; then
|
if [ -z "$destpath" ]; then
|
||||||
if [[ $option =~ ^/.* ]]; then
|
if [[ $option =~ ^/.* ]]; then
|
||||||
destinationpath="${option%/}"
|
destpath="${option%/}"
|
||||||
else
|
else
|
||||||
destinationpath="$(pwd)/${option%/}"
|
destpath="$(pwd)/${option%/}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -244,7 +244,7 @@ if [ -r "$listfile" ]; then
|
||||||
:
|
:
|
||||||
else
|
else
|
||||||
sourcepath=""
|
sourcepath=""
|
||||||
destinationpath=""
|
destpath=""
|
||||||
for option in $line; do
|
for option in $line; do
|
||||||
if [ -z "${option//[0-9]/}" ]; then
|
if [ -z "${option//[0-9]/}" ]; then
|
||||||
versions="$option"
|
versions="$option"
|
||||||
|
@ -258,11 +258,11 @@ if [ -r "$listfile" ]; then
|
||||||
sourcepath="$(pwd)/${option%/}/*"
|
sourcepath="$(pwd)/${option%/}/*"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ -z "$destinationpath" ]; then
|
if [ -z "$destpath" ]; then
|
||||||
if [[ $option =~ ^/.* ]]; then
|
if [[ $option =~ ^/.* ]]; then
|
||||||
destinationpath="${option%/}"
|
destpath="${option%/}"
|
||||||
else
|
else
|
||||||
destinationpath="$(pwd)/${option%/}"
|
destpath="$(pwd)/${option%/}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Reference in New Issue