Commit 7a226758 authored by Leo Leung's avatar Leo Leung Committed by root
Browse files

Using screen to background jobs because of unreliable breakage caused by pv

parent 5e5a8067
......@@ -13,16 +13,17 @@ fi
# Keep track of start time, so short jobs are considered 'failed'
StartTime=$(date +%s)
while read disk size type label ; do
if [ -b /dev/$disk ] ; then
echo "Starting backup on disk $disk ($label)"
(sh start.sh $disk | tee >(mail -s "Backup process report $label" leo@steamr.com)) &
screen -S backup-$disk -dm bash -c "sh start.sh $disk | tee >(mail -s \"Backup process report $label\" leo@steamr.com)"
fi
done < <(echo "$Disks")
# Join
wait
# Wait for screen sessions to terminate.
while screen -ls | grep backup ; do
sleep 10
done
# Total elapsed time
EndTime=$(date +%s)
......@@ -33,7 +34,7 @@ if [ $(( $EndTime - $StartTime )) -gt 60 ] ; then
# Backup took some time, probably did something?
echo "powering off..."
sleep 5
poweroff
# poweroff
fi
......
......@@ -188,15 +188,22 @@ function backup_volume() {
# Initiate the snapshot transfer.
if [ -z "$NextSnapshotId" ] ; then
log "Sending full snapshot for $Volume@backup-$LABEL-$OriginSnapshotId to $LocalVolumeName"
$(sleep 3 && ssh $SSHAUTH "sudo zfs send -w $Volume@backup-$LABEL-$OriginSnapshotId | nc $LocalIP $TransferPort") &
$(sleep 3 && ssh -n $SSHAUTH "sudo zfs send -w $Volume@backup-$LABEL-$OriginSnapshotId | nc $LocalIP $TransferPort") </dev/null &
else
log "Sending incremental snapshot ($OriginSnapshotId to $NextSnapshotId), for $Volume@backup-$LABEL-$OriginSnapshotId to $LABEL/$LocalVolumeName"
$(sleep 3 && ssh $SSHAUTH "sudo zfs send -w -i $Volume@backup-$LABEL-$OriginSnapshotId $Volume@backup-$LABEL-$NextSnapshotId | nc $LocalIP $TransferPort") &
$(sleep 3 && ssh -n $SSHAUTH "sudo zfs send -w -i $Volume@backup-$LABEL-$OriginSnapshotId $Volume@backup-$LABEL-$NextSnapshotId | nc $LocalIP $TransferPort") &
fi
# The actual transfer happens here
# We need to run this in foreground because of pv, hence the sleep + forking of the above command
netcat_listen $TransferPort | pv | zfs receive -u -F $LABEL/$LocalVolumeName
if [ -z "$NOPV" ] || [ "$NOPV" -eq 0 ] ; then
netcat_listen $TransferPort | pv | zfs receive -u -F $LABEL/$LocalVolumeName
else
# PV can cause 'Stopped (tty output)' for forked jobs, breaking the pipe. If we run
# with the NOPV option, we remove pv from the pipeline
echo "Receiving without pv pipeviewer."
netcat_listen $TransferPort | zfs receive -u -F $LABEL/$LocalVolumeName
fi
local Status=$?
# Finished
......
#!/bin/bash
cd "$(dirname "$0")"
if [[ "$1" == "--nopv" ]] ; then
shift
NOPV=1
export NOPV=1
fi
Device="$1"
if [ -z "$Device" ] ; then
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment