From 3ed8227c3e292ccd1a0ea084c89a9ab88f867946 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 20 Jan 2013 01:17:44 +0100 Subject: [PATCH] added remote sync --- bash/sync.sh | 87 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 36 deletions(-) diff --git a/bash/sync.sh b/bash/sync.sh index 77058c1..858f6e4 100755 --- a/bash/sync.sh +++ b/bash/sync.sh @@ -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