added remote sync

This commit is contained in:
Steffen Vogel 2013-01-20 01:17:44 +01:00
parent 58f8bba2a1
commit 3ed8227c3e

View file

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
##
# rsync backup
#
@ -26,51 +26,52 @@
# Hostname or IP address of remote box
HOST=sea
HOST_REMOTE=lux
# Maximum file size. Larger files will be exluded
MAX_SIZE=500
MAX_SIZE=1000
MAX_SIZE_REMOTE=500
# Nice factor for rsync
NICENESS=10
# Interval in minutes to reschedule this script via at
# Set to 0 to disable
INTERVAL=180
INTERVAL=60
# Choose own queue for sync jobs
# Uppercase letters will at let behave like batch
QUEUE=S
# Exclude files bigger than MAX_SIZE
find $HOME -type f -size +$(($MAX_SIZE*1024))k > $HOME/rsync.large.exclude
# Start logfile
touch $HOME/rsync.log
echo started: $(date) | tee $HOME/rsync.log
echo "started local sync: $(date)" | tee $HOME/rsync.log
# Notify
if [ -x /usr/bin/notify-send ]; then
notify-send \
-h int:transient:1 \
-a "rsync" \
-c "transfer" \
-i "/usr/share/icons/gnome/256x256/actions/appointment.png" \
-u low -t 1000 \
"Syncronization started" "excluding:\n$(cat ~/*.exclude)"
fi
# Notify function
notify () {
if [ -x /usr/bin/notify-send ]; then
notify-send \
-h int:transient:1 \
-a "rsync" \
-c "transfer" \
-i "/usr/share/icons/gnome/256x256/actions/appointment.png" \
-u low -t 60000 \
"$1" "$2"
fi
}
notify "Syncronization started" "excluding:\n$(cat ~/rsync.exclude)"
# Start the Local Syncronisation
/usr/bin/time \
-a -o $HOME/rsync.log \
-f "secs elapsed: %e" \
nice \
-n ${NICENESS} \
nice --adjustment=$NICENESS \
rsync \
--human-readable \
--exclude-from=$HOME/rsync.exclude \
--exclude-from=$HOME/rsync.large.exclude \
--max-size=${MAX_SIZE}m \
--archive \
--xattrs \
--delete \
@ -82,21 +83,34 @@ rsync \
$HOME/ $HOST:$HOME/backup/ \
2>&1 | tee -a $HOME/rsync.log
echo finished: $(date) | tee -a $HOME/rsync.log
# Resync logfile
scp $HOME/rsync.log $HOST:$HOME/backup/
scp -q $HOME/rsync.log $HOST:$HOME/backup/
# Notify
if [ -x /usr/bin/notify-send ]; then
notify-send \
-h int:transient:1 \
-a "rsync" \
-c "transfer.complete" \
-i "/usr/share/icons/gnome/256x256/actions/appointment.png" \
-u low -t 2000 \
"Syncronisation completed" "$(tail -n16 ~/rsync.log)"
fi
notify "Local syncronisation completed" "$(tail -n16 ~/rsync.log)"
echo "started remote sync: $(date)" | tee -a $HOME/rsync.log
# Start remote syncronisation
ssh -T $HOST <<-ENDSSH
killall --quiet rsync
rsync \
--human-readable \
--archive \
--xattrs \
--delete \
--executability \
--links \
--compress \
--out-format=%f \
--stats \
--bwlimit=300 \
--max-size=${MAX_SIZE_REMOTE}m \
$HOME/backup/ lux:/backup/$USER > rsync.log &
disown
#while ps --pid $RSYNC_PID > /dev/null; do sleep 0.1; done
ENDSSH
notify "Remote syncronisation completed" "$(tail -n16 ~/rsync.log)"
# Prune queue
JOBS=$(atq -q ${QUEUE} | cut -f 1 | xargs)
@ -104,7 +118,8 @@ if [ -n "${JOBS}" ]; then
atrm ${JOBS}
fi
# Queue next run
# Schedule next run
if [ ${INTERVAL} -ne 0 ]; then
echo "bash $0" | at -q ${QUEUE} "now + ${INTERVAL} minutes"
echo -n "next syncronisation: "
echo $0 | at -q ${QUEUE} "now + ${INTERVAL} minutes" 2>&1 | tail -n +2
fi