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