Two 10 seconds scripts to keep your data synchronized – Some code from mariocesar – Forrst.
# -- First script. Listen for changes and use
# rsync just when new files are available or
# existing files are modified.
# Bash cousin ala dropbox
echo "Sync ---"
echo "rsync -vrae 'ssh -p 2299' --delete $1 noentrar@creat1va.com:files/$2"
rsync -vrae 'ssh -p 2299' --delete $1 noentrar@creat1va.com:files/$2
echo "Listening changes"
while inotifywait -e modify -e create -e delete -e move -r $1; do
rsync -vrae 'ssh -p 2299' --delete $1 noentrar@creat1va.com:files/$2
done
# -- Second script. In a home network LAN,
# having a server, Backup incrementally
# all your data. Using exclude rules.
# For the candy lover, I use zenity to use
# Gnome notifications
#!/bin/bash
HOST=192.168.2.1
exec 3> >(zenity --notification --text="Backup" --listen)
echo "icon: info" >&3
ping -c 1 -w 3 $HOST
if [ $? -ne 0 ] ; then
echo "message: Servidor $HOST no esta disponible" >&3
else
documents=$(rsync -azr --stats --exclude-from '/media/datos/.exclude' $* /media/datos/ mariocesar@$HOST:/home/mariocesar/Backup)
music=$(rsync -azr --stats $* /media/datos/Música/ mariocesar@$HOST:/home/music)
documents_total=$(echo $documents | grep -o "Number of files transferred: [0-9]*")
music_total=$(echo $music | grep -o "Number of files transferred: [0-9]*")
echo "message: Terminado\nDocumentos: $documents_total \nMúsica: $music_total" >&3
echo -e "\n--- $(date)\n$output" >> ~/.rsync-log
fi
exec 3>&-
