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`
scp=`which scp`
sgdisk=`which sgdisk`
#ssh=`which ssh`
ssh="`which ssh` -n"
ssh=`which ssh`
sort=`which sort`
tar=`which tar`
tune2fs=`which tune2fs`
@ -230,6 +229,11 @@ sort=`which sort`
sync=`which sync`
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
#
# ------------------ Ende Programme ----------------- #

View File

@ -151,21 +151,40 @@ if $MIRROR ;then
## -
b_timestamp=`$date +"%s"`
if [ $_DEBUG -gt 1 -a $_TEST -eq 0 ]; then
echolog "$rsync --rsync-path='sudo rsync' $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 $?
)
if [ "$srcHost" = "localhost" -a "$destHost" = "localhost" ] ; 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
$(
$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' $progArgs \
"$backupSrcDir" $backup_mirror_dir/$backupSrcParentDir >> $logFile 2> $err_Log
exit $?
)
fi
retval=$?
else
$(
$rsync --rsync-path='sudo rsync' $progArgs \
"$backupSrcDir" $backup_mirror_dir/$backupSrcParentDir >> $logFile 2> $err_Log
exit $?
)
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
retval=$?
## - end timestamp
## -

View File

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

View File

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