Two 10 seconds scripts to keep your data synchronized – Some code from mariocesar – Forrst

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>&-

This entry was posted in linux administration. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>