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