Add support of multiplexing ssh.

This commit is contained in:
Christoph 2017-11-23 04:30:37 +01:00
parent bceeb9bbbd
commit 97e034bd99
4 changed files with 138 additions and 62 deletions

View File

@ -217,8 +217,7 @@ rm=`which rm`
rsync=`which rsync` rsync=`which rsync`
scp=`which scp` scp=`which scp`
sgdisk=`which sgdisk` sgdisk=`which sgdisk`
#ssh=`which ssh` ssh=`which ssh`
ssh="`which ssh` -n"
sort=`which sort` sort=`which sort`
tar=`which tar` tar=`which tar`
tune2fs=`which tune2fs` tune2fs=`which tune2fs`
@ -230,6 +229,11 @@ sort=`which sort`
sync=`which sync` sync=`which sync`
touch=`which touch` touch=`which touch`
ssh_opts='-o ControlMaster=auto -o ControlPath=/root/.ssh/%r@%h:%p -o ControlPersist=60'
if [[ -n "$ssh" ]] ; then
ssh="$ssh -n $ssh_opts"
fi
export basename dirname awk cat cryptsetup cut date dd e2fsck find fdisk grep gzip hdparm logrotate mkdir mount mv parted ps rm rsync scp ssh sort tar tune2fs umount sfdisk sgdisk su sudo sort sync touch export basename dirname awk cat cryptsetup cut date dd e2fsck find fdisk grep gzip hdparm logrotate mkdir mount mv parted ps rm rsync scp ssh sort tar tune2fs umount sfdisk sgdisk su sudo sort sync touch
# #
# ------------------ Ende Programme ----------------- # # ------------------ Ende Programme ----------------- #

View File

@ -151,6 +151,8 @@ if $MIRROR ;then
## - ## -
b_timestamp=`$date +"%s"` b_timestamp=`$date +"%s"`
if [ "$srcHost" = "localhost" -a "$destHost" = "localhost" ] ; then
if [ $_DEBUG -gt 1 -a $_TEST -eq 0 ]; then if [ $_DEBUG -gt 1 -a $_TEST -eq 0 ]; then
echolog "$rsync --rsync-path='sudo rsync' $progArgs $logArgs="$formats" $backupSrcDir $backup_mirror_dir/$backupSrcParentDir" 2 echolog "$rsync --rsync-path='sudo rsync' $progArgs $logArgs="$formats" $backupSrcDir $backup_mirror_dir/$backupSrcParentDir" 2
$( $(
@ -166,6 +168,23 @@ if $MIRROR ;then
) )
fi fi
retval=$? retval=$?
else
if [ $_DEBUG -gt 1 -a $_TEST -eq 0 ]; then
echolog "$rsync --rsync-path='sudo rsync' -e "ssh $ssh_opts" $progArgs $logArgs="$formats" $backupSrcDir $backup_mirror_dir/$backupSrcParentDir" 2
$(
$rsync --rsync-path='sudo -i -u root rsync' $progArgs $logArgs="$formats" \
"$backupSrcDir" $backup_mirror_dir/$backupSrcParentDir >> $logFile 2> $err_Log
exit $?
)
else
$(
$rsync --rsync-path='sudo rsync' -e "ssh $ssh_opts" $progArgs \
"$backupSrcDir" $backup_mirror_dir/$backupSrcParentDir >> $logFile 2> $err_Log
exit $?
)
fi
retval=$?
fi
## - end timestamp ## - end timestamp
## - ## -

View File

@ -92,19 +92,27 @@ for _disk in $disks ; do
else else
$hdparm -I $disk > ${LOCK_DIR}/info_${_disk}.txt 2> $err_Log $hdparm -I $disk > ${LOCK_DIR}/info_${_disk}.txt 2> $err_Log
fi fi
if [ "$?" != "0!" ]; then if [ "$?" != "0" ]; then
echolog "\t[ERROR] Cannot determin identification info for disk $disk: \n\t`$cat $err_Log`\n"
else
if [ "$srcHost" = "localhost" -a "$destHost" = "localhost" ] ; then
$( $(
$rsync --rsync-path='sudo rsync' $progArgs ${LOCK_DIR}/info_${_disk}.txt $target_dir/info_${_disk}.txt >> $logFile 2> $err_Log $rsync --rsync-path='sudo rsync' $progArgs ${LOCK_DIR}/info_${_disk}.txt $target_dir/info_${_disk}.txt >> $logFile 2> $err_Log
exit $? exit $?
) )
retval=$? retval=$?
else
$(
$rsync --rsync-path='sudo rsync' -e "ssh $ssh_opts" $progArgs ${LOCK_DIR}/info_${_disk}.txt $target_dir/info_${_disk}.txt >> $logFile 2> $err_Log
exit $?
)
retval=$?
fi
if [ "$retval" = "0" ]; then if [ "$retval" = "0" ]; then
echolog "\t--- \"info_${_disk}.txt\" successfully saved ---" echolog "\t--- \"info_${_disk}.txt\" successfully saved ---"
else else
echolog "\t[ERROR] Cannot save identification info for disk $disk: \n\t`$cat $err_Log`\n" echolog "\t[ERROR] Cannot save identification info for disk $disk: \n\t`$cat $err_Log`\n"
fi fi
else
echolog "\t[ERROR] Cannot determin identification info for disk $disk: \n\t`$cat $err_Log`\n"
fi fi
if [ "X$parted" = "X" ]; then if [ "X$parted" = "X" ]; then
@ -134,11 +142,19 @@ for _disk in $disks ; do
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
echolog "\t[ERROR] Cannot determin partition tables for $disk (info file): \n\t`$cat $err_Log`\n" echolog "\t[ERROR] Cannot determin partition tables for $disk (info file): \n\t`$cat $err_Log`\n"
else else
if [ "$srcHost" = "localhost" -a "$destHost" = "localhost" ] ; then
$( $(
$rsync --rsync-path='sudo rsync' $progArgs ${LOCK_DIR}/fdisk_${_disk}.txt $target_dir/fdisk_${_disk}.txt >> $logFile 2> $err_Log $rsync --rsync-path='sudo rsync' $progArgs ${LOCK_DIR}/fdisk_${_disk}.txt $target_dir/fdisk_${_disk}.txt >> $logFile 2> $err_Log
exit $? exit $?
) )
retval=$? retval=$?
else
$(
$rsync --rsync-path='sudo rsync' -e "ssh $ssh_opts" $progArgs ${LOCK_DIR}/fdisk_${_disk}.txt $target_dir/fdisk_${_disk}.txt >> $logFile 2> $err_Log
exit $?
)
retval=$?
fi
if [ "$retval" = "0" ]; then if [ "$retval" = "0" ]; then
echolog "\t--- \"fdisk_${_disk}.txt\" successfully saved ---" echolog "\t--- \"fdisk_${_disk}.txt\" successfully saved ---"
else else
@ -152,12 +168,20 @@ for _disk in $disks ; do
else else
$dd if=$disk bs=512 count=1 > ${LOCK_DIR}/${_disk}.mbr 2> $err_Log $dd if=$disk bs=512 count=1 > ${LOCK_DIR}/${_disk}.mbr 2> $err_Log
fi fi
if [ "$?" != "0!" ]; then if [ "$?" = "0" ]; then
if [ "$srcHost" = "localhost" -a "$destHost" = "localhost" ] ; then
$( $(
$rsync --rsync-path='sudo rsync' $progArgs ${LOCK_DIR}/${_disk}.mbr $target_dir/${_disk}.mbr >> $logFile 2> $err_Log $rsync --rsync-path='sudo rsync' $progArgs ${LOCK_DIR}/${_disk}.mbr $target_dir/${_disk}.mbr >> $logFile 2> $err_Log
exit $? exit $?
) )
retval=$? retval=$?
else
$(
$rsync --rsync-path='sudo rsync' -e "ssh $ssh_opts" $progArgs ${LOCK_DIR}/${_disk}.mbr $target_dir/${_disk}.mbr >> $logFile 2> $err_Log
exit $?
)
retval=$?
fi
if [ "$retval" = "0" ]; then if [ "$retval" = "0" ]; then
echolog "\t--- \"${_disk}.mbr\" successfully saved ---" echolog "\t--- \"${_disk}.mbr\" successfully saved ---"
else else
@ -173,12 +197,20 @@ for _disk in $disks ; do
else else
$sfdisk -d $disk > ${LOCK_DIR}/${_disk}-partitions.sfdisk 2> $err_Log $sfdisk -d $disk > ${LOCK_DIR}/${_disk}-partitions.sfdisk 2> $err_Log
fi fi
if [ "$?" != "0!" ]; then if [ "$?" = "0" ]; then
if [ "$srcHost" = "localhost" -a "$destHost" = "localhost" ] ; then
$( $(
$rsync --rsync-path='sudo rsync' $progArgs ${LOCK_DIR}/${_disk}-partitions.sfdisk $target_dir/${_disk}-partitions.sfdisk >> $logFile 2> $err_Log $rsync --rsync-path='sudo rsync' $progArgs ${LOCK_DIR}/${_disk}-partitions.sfdisk $target_dir/${_disk}-partitions.sfdisk >> $logFile 2> $err_Log
exit $? exit $?
) )
retval=$? retval=$?
else
$(
$rsync --rsync-path='sudo rsync' -e "ssh $ssh_opts" $progArgs ${LOCK_DIR}/${_disk}-partitions.sfdisk $target_dir/${_disk}-partitions.sfdisk >> $logFile 2> $err_Log
exit $?
)
retval=$?
fi
if [ "$retval" = "0" ]; then if [ "$retval" = "0" ]; then
echolog "\t--- \"${_disk}-partitions.sfdisk\" successfully saved ---" echolog "\t--- \"${_disk}-partitions.sfdisk\" successfully saved ---"
else else
@ -203,12 +235,20 @@ for _disk in $disks ; do
else else
$dd if=$partition bs=512 count=1 > ${LOCK_DIR}/boot_sec-${_part}.bin 2> $err_Log $dd if=$partition bs=512 count=1 > ${LOCK_DIR}/boot_sec-${_part}.bin 2> $err_Log
fi fi
if [ "$?" != "0!" ]; then if [ "$?" = "0" ]; then
if [ "$srcHost" = "localhost" -a "$destHost" = "localhost" ] ; then
$( $(
$rsync --rsync-path='sudo rsync' $progArgs ${LOCK_DIR}/boot_sec-${_part}.bin $target_dir/boot_sec-${_part}.bin >> $logFile 2> $err_Log $rsync --rsync-path='sudo rsync' $progArgs ${LOCK_DIR}/boot_sec-${_part}.bin $target_dir/boot_sec-${_part}.bin >> $logFile 2> $err_Log
exit $? exit $?
) )
retval=$? retval=$?
else
$(
$rsync --rsync-path='sudo rsync' -e "ssh $ssh_opts" $progArgs ${LOCK_DIR}/boot_sec-${_part}.bin $target_dir/boot_sec-${_part}.bin >> $logFile 2> $err_Log
exit $?
)
retval=$?
fi
if [ "$retval" = "0" ]; then if [ "$retval" = "0" ]; then
echolog "\t--- \"boot_sec-${_part}.bin\" successfully saved ---" echolog "\t--- \"boot_sec-${_part}.bin\" successfully saved ---"
else else
@ -238,11 +278,19 @@ for _disk in $disks ; do
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
echolog "\t[ERROR] Cannot determin partition tables for $disk (info file): \n\t`$cat $err_Log`\n" echolog "\t[ERROR] Cannot determin partition tables for $disk (info file): \n\t`$cat $err_Log`\n"
else else
if [ "$srcHost" = "localhost" -a "$destHost" = "localhost" ] ; then
$( $(
$rsync --rsync-path='sudo rsync' $progArgs ${LOCK_DIR}/sgdisk_${_disk}.txt $target_dir/sgdisk_${_disk}.txt >> $logFile 2> $err_Log $rsync --rsync-path='sudo rsync' $progArgs ${LOCK_DIR}/sgdisk_${_disk}.txt $target_dir/sgdisk_${_disk}.txt >> $logFile 2> $err_Log
exit $? exit $?
) )
retval=$? retval=$?
else
$(
$rsync --rsync-path='sudo rsync' -e "ssh $ssh_opts" $progArgs ${LOCK_DIR}/sgdisk_${_disk}.txt $target_dir/sgdisk_${_disk}.txt >> $logFile 2> $err_Log
exit $?
)
retval=$?
fi
if [ "$retval" = "0" ]; then if [ "$retval" = "0" ]; then
echolog "\t--- \"fdisk_${_disk}.txt\" successfully saved ---" echolog "\t--- \"fdisk_${_disk}.txt\" successfully saved ---"
else else
@ -257,12 +305,20 @@ for _disk in $disks ; do
else else
$sgdisk -b ${LOCK_DIR}/${_disk}-partitions.sgdisk $disk > /dev/null $sgdisk -b ${LOCK_DIR}/${_disk}-partitions.sgdisk $disk > /dev/null
fi fi
if [ "$?" != "0!" ]; then if [ "$?" = "0" ]; then
if [ "$srcHost" = "localhost" -a "$destHost" = "localhost" ] ; then
$( $(
$rsync --rsync-path='sudo rsync' $progArgs ${LOCK_DIR}/${_disk}-partitions.sgdisk $target_dir/${_disk}-partitions.sgdisk >> $logFile 2> $err_Log $rsync --rsync-path='sudo rsync' $progArgs ${LOCK_DIR}/${_disk}-partitions.sgdisk $target_dir/${_disk}-partitions.sgdisk >> $logFile 2> $err_Log
exit $? exit $?
) )
retval=$? retval=$?
else
$(
$rsync --rsync-path='sudo rsync' -e "ssh $ssh_opts" $progArgs ${LOCK_DIR}/${_disk}-partitions.sgdisk $target_dir/${_disk}-partitions.sgdisk >> $logFile 2> $err_Log
exit $?
)
retval=$?
fi
if [ "$retval" = "0" ]; then if [ "$retval" = "0" ]; then
echolog "\t--- \"${_disk}-partitions.sgdisk\" successfully saved ---" echolog "\t--- \"${_disk}-partitions.sgdisk\" successfully saved ---"
else else

View File

@ -44,11 +44,8 @@ if ! $ssh_hopping && ! $ssh_tunnel ; then
_via_ssh_tunnel=false _via_ssh_tunnel=false
export _via_ssh_tunnel export _via_ssh_tunnel
if [ "$srcHost" = "localhost" -a "$destHost" = "localhost" ] ; then
progArgs="$rsync_progArgs -a -p --delete" progArgs="$rsync_progArgs -a -p --delete"
else
progArgs="$rsync_progArgs -a -p -e ssh --delete"
fi
else else
## - create ssh-tunnel localhost -> $hop_host -> $target_host ## - create ssh-tunnel localhost -> $hop_host -> $target_host