Θέλω λοιπόν να συγχρονίσω δύο φακέλους, αυτόν που μου κρατάει τα αρχεία από το Owncloud με ένα δικτυακό φάκελο τον οποίο τον έχω κάνει mount στο /media/OwnCloudFiles/
Θα το κάνω δίνοντας την εντολή
rsync -av –delete /home/karanik/data.owncloud/karanik/files/ /media/OwnCloudFiles/
Θα μπορούσα να τρέχω την εντολή προγραμματισμένα με την βοήθεια της crontab αλλά αυτό δεν θα είχε real time sync αποτελέσματα. Εγώ θέλω με το που κάνω οποιαδήποτε αλλαγή στο Owncloud να γίνεται αυτόματα backup. Αυτό γίνεται με την εντολή incron η οποία έχει και ίδια σύνταξη με την crontab ωστόσο βρήκα ένα πιο εύκολο τρόπο ο οποίος δουλεύει και Recursive. Πρόκειται για το Watcher, το βρήκα στο https://github.com/splitbrain/Watcher και είναι ένα μικρό προγραμματάκι γραμμένο σε python.
wget https://github.com/splitbrain/Watcher/archive/master.zip
Περιέχει 2 αρχεία watcher.py & watcher.ini
Στο watcher.ini έβαλα τα παρακάτω (δες πράσινα bold ).
Στo watch έβαλα τον φάκελο που παρατηρεί για αλλαγές και στο command το τί θα τρέξει όταν υπάρξει αλλαγή.
; ———————-
; General Settings
; ———————-
[DEFAULT]
; where to store output
logfile=/var/log/watcher.log
; where to save the PID file
pidfile=/tmp/watcher.pid; ———————-
; Job Setups
; ———————-
[job1]
; directory or file to watch. Probably should be abs path.
watch=/home/karanik/data.owncloud
; list of events to watch for.
; supported events:
; ‘access’ – File was accessed (read) (*)
; ‘attribute_change’ – Metadata changed (permissions, timestamps, extended attributes, etc.) (*)
; ‘write_close’ – File opened for writing was closed (*)
; ‘nowrite_close’ – File not opened for writing was closed (*)
; ‘create’ – File/directory created in watched directory (*)
; ‘delete’ – File/directory deleted from watched directory (*)
; ‘self_delete’ – Watched file/directory was itself deleted
; ‘modify’ – File was modified (*)
; ‘self_move’ – Watched file/directory was itself moved
; ‘move_from’ – File moved out of watched directory (*)
; ‘move_to’ – File moved into watched directory (*)
; ‘open’ – File was opened (*)
; ‘all’ – Any of the above events are fired
; ‘move’ – A combination of ‘move_from’ and ‘move_to’
; ‘close’ – A combination of ‘write_close’ and ‘nowrite_close’
;
; When monitoring a directory, the events marked with an asterisk (*) above
; can occur for files in the directory, in which case the name field in the
; returned event data identifies the name of the file within the directory.
events=create,delete,modify
; Comma separated list of excluded dir. Absolute path needed.
; Leave blank if no excluded dir setted
excluded=
; if true, watcher will monitor directories recursively for changes
recursive=true
; if true, watcher will automatically watch new subdirectory
autoadd=true
; the command to run. Can be any command. It’s run as whatever user started watcher.
; The following wildards may be used inside command specification:
; $$ dollar sign
; $watched watched filesystem path (see above)
; $filename event-related file name
; $tflags event flags (textually)
; $nflags event flags (numerically)
; $cookie event cookie (integer used for matching move_from and move_to events, otherwise 0)
command=/home/karanik/syncOwnCloud.kpc.sh
Το αρχείο syncOwnCloud.kpc.sh περιέχει
#!/bin/sh
rsync -av –delete /home/karanik/data.owncloud/karanik/files/ /media/OwnCloudFiles/
Και θα το κάνω εκτελέσιμο δίνοντας
chmod +x syncOwnCloud.kpc.sh
./watcher.py -c watcher.ini start
Δημιουργία του αρχείου watcher.sh δίνοτνας
nano watcher.sh
Και μέσα βάζω
#!/bin/sh
/home/karanik/watcher.py -c watcher.ini start
sudo crontab -e
@reboot /home/karanik/watcher.sh