Evaggelos Balaskas - System Engineer

The sky above the port was the color of television, tuned to a dead channel

Blog
Posts
Wiki
About
Contact
rss.png twitter linkedin github gitlab profile for ebal on Stack Exchange

Next Page »
  -  
Apr
12
2011
pirsyncd new version: 20110412
Posted by ebal at 19:50:53 in planet_ellak, pirsynd, planet_Sysadmin

pirsyncd stands for: Python Inotify Rsync Daemon.

Description:
This is an attempt of writing a daemon to watch a directory for kernel’s inotify events and then execute an rsync command to synchronize two different directories (local or remote). This is a poor man’s mirroring or an alternative (not so) real data replication mechanism and it is based on Pyinotify.

pirsyncd

From ChangeLog:

Plz notice that this is the last version in python2
The next version of piryncd would be only in python3

  • Pyinotify.py updated to 0.9.1 (20110405)
  • Added ssh port parameter for synchronize of ssh
  • Removed trailing slash (/) requirement for source & destination path
  • Added Pyinotify.py version3 for pirsyncd.Py3k

plz try ./pirsyncd –help & ./pirsyncd –examples to see more.

Get the latest version of pirsyncd v20110412

Dec
09
2010
Famous Why Interview
Posted by ebal at 17:56:20 in planet_ellak, pirsynd, planet_Sysadmin

No so long ago, i’ve noticed that pirsyncd published (not by me) in download.famouswhy.com . I have to say that i didnt know about this site. But the people behind it, have found me and asked me a few questions. So here is my first interview about me & pirsyncd.

Sep
07
2010
pirsyncd new version: 20100907
Posted by ebal at 18:17:08 in planet_ellak, pirsynd, planet_Sysadmin

pirsyncd stands for: Python Inotify Rsync Daemon.

Description:
This is an attempt of writing a daemon to watch a directory for kernel’s inotify events and then execute an rsync command to synchronize two different directories (local or remote). This is a poor man’s mirroring or an alternative (not so) real data replication mechanism and it is based on Pyinotify.

pirsyncd

From ChangeLog:

  • Pyinotify has been updated in version 0.9.0 (20100604)
  • Rsync option “–safe-links” has been added
  • Scoring 7.38 with pylint (better code styling)

plz try ./pirsyncd –help & ./pirsyncd –examples to see more.

Get the latest version of pirsyncd v20100907

Jul
24
2010
PIrsyncD new version: 20100724
Posted by ebal at 10:09:46 in planet_ellak, pirsynd

PIrsyncD stands for: Python Inotify Rsync Daemon.

Description:
This is an attempt of writing a daemon to watch a directory for kernel’s inotify events and then execute an rsync command to synchronize two different directories (local or remote). This is a poor man’s mirroring or an alternative (not so) real data replication mechanism and it is based on Pyinotify.

PIrsyncD

A lot of changes over the past couple releases

From ChangeLog:

  • Rewrite code for duplicate inode events, using python dictionary
  • Added option to run PIryncD in foreground
  • Added code for mirroring in first run, without looking inode events.
  • Scoring 7.35 with pylint (better code styling)
  • Redifind global variables (errors may occured, plz notify me).

plz try ./PIrsyncD –help to see more

Get the latest version of PIrsyncD v20100724

Mar
16
2010
python code styling
Posted by ebal at 20:13:14 in pirsynd

Κατά το οπενfest είχα την τύχη να γνωρίσω τα παιδιά του tas python. Έτσι λοιπόν και μετά το σχόλιο του Λεβεντέας Δημήτρης ότι γράφω “καλό” κώδικα, μου υπέδειξε και μου διευκρίνισε μερικά πράγματα γύρω από το python code styling. (φίλε σε ευχαριστώ πολύ για τις παρατηρήσεις σου). Με αρκετή υπομονή και την χρήση του pylint ξεκίνησα λοιπόν να βελτιώνω την εικόνα του κώδικα του PIrsyncD. Άλλες 46 γραμμές λοιπόν προστέθηκαν ώστε πλέον να είμαστε στις 434 γραμμές (από 17 γραμμές που είχε η πρώτη έκδοση!) στην έκδοση: 20100317

  • 1 comment
Mar
10
2010
PIrsyncD new version: 20100310
Posted by ebal at 17:56:28 in planet_ellak, pirsynd

PIrsyncD stands for: Python Inotify Rsync Daemon.

Description:
This is an attempt of writing a daemon to watch a directory for kernel’s inotify events and then execute an rsync command to synchronize two different directories (local or remote). This is a poor man’s mirroring or an alternative (not so) real data replication mechanism and it is based on Pyinotify.

PIrsyncD

A lot of changes over the past couple releases

From ChangeLog:

  • Added functionality to run multiple instances of PIrsyncD (Based on Jeff Templon & Jan Just Keijser’s patch)
  • Added functionality to rsync over a destination rsync server (Based on Jeff Templon & Jan Just Keijser’s patch)
  • Added python regular expression module (import re), for argument validation.
  • Fallback solution if rsync functionality is failed
  • Changed –host argument from IP value to hostname
  • TODO file Reviewed
  • Better examples
  • Better usage message

Thanks Jeff Templon < templon AT nikhef DOT nl > and Jan Just Keijser < janjust AT nikhef DOT nl > for your feedback on PIrsyncD.

plz try ./PIrsyncD –help to see more

Get the latest version of PIrsyncD v20100310

Feb
19
2010
PIrsyncD new version: 20100219
Posted by ebal at 12:26:38 in planet_ellak, pirsynd

PIrsyncD stands for: Python Inotify Rsync Daemon.

Description:
This is an attempt of writing a daemon to watch a directory for kernel’s inotify events and then execute an rsync command to synchronize two different directories (local or remote). This is a poor man’s mirroring or an alternative (not so) real data replication mechanism and it is based on Pyinotify.

PIrsyncD

From ChangeLog:

  • Added variable to define the rsync version (parameter: –rsync_v2)
  • Rewrite of INSTALL file (to meet better the minimal requirements)
  • Checking of the destination directory is now disabled when –host is set.
  • rsync append functionality was added.
  • Better examples were provided.

All the above were suggested by Jeff Templon < templon AT nikhef DOT nl >
Thanks Jeff for your feedback on PIrsyncD.

plz try ./PIrsyncD –help to see more

Get the latest version of PIrsyncD v20100219

Jan
02
2010
PIrsyncD new version: 20100102
Posted by ebal at 17:17:43 in pirsynd

PIrsyncD

From ChangeLog:

  • This release adds the ability to Disable Logging and Debbuging functionality
  • Also has better debugging information (pyinotify events and rsync command)

plz try ./PIrsyncD –help to see more

Get the latest version of PIrsyncD v20100102

btw: BitBucket rocks!!!

Dec
30
2009
PIrsyncD new version: 20091230
Posted by ebal at 21:48:45 in pirsynd

PIrsyncD

From ChangeLog:

  • Added Debug Logging Functionality (this is extremely useful for debugging pyinotify events)
  • Added Automatically Learning/Watching functionality for better recursive synchronization process

plz try ./PIrsyncD –help to see more

Get the latest version of PIrsyncD v20091230

TODO (or next goal):

  • Try to rsync specific files (only the changes) for smaller rsync file list
  • Exclude files via pattern
Nov
22
2009
PIrsyncD on bitbucket
Posted by ebal at 16:03:59 in pirsynd

Στην αναζήτηση μου για να ανεβάσω τον κώδικα του PIrsyncD σε μία ελεύθερη πλατφόρμα λογισμικού με υποστήριξη mercurial κατέληξα στις εξής δύο λύσεις:

α. SourceForge
β. BitBucket

Είμαι μέλος του sf από το 2002 (7 χρόνια), μάλιστα η πτυχιακή μου ήταν βασισμένη στο sf (δημιούργησα το ellak-dev και λειτούργησε στις αρχές ως πλατφόρμα λογισμικού για έλληνες developers υπό το ellak.gr) και πλέον το sf υποστηρίζει Mercurial, αλλά … αλλά τελικά κατέληξα στο bitbucket κυρίως λόγω της απλότητάς του:

http://bitbucket.org/ebal/pirsyncd/

Οπότε εάν κάποιος θέλει ένα αντίγραφο του PIrsyncD μπορεί να το κατεβάσει κι έτσι:

hg clone https://ebal@bitbucket.org/ebal/pirsyncd/

Nov
15
2009
PIrsyncD new version: 20091115
Posted by ebal at 16:47:52 in pirsynd

PIrsyncD

From ChangeLog:

  • Add Max-Size & Min-Size exclude functionality
  • Remove Usage Examples from –help
  • Add –examples for Usage Examples
  • minor code fixes

Get the latest version of PIrsyncD v20091115

TODO (or next goal): Exclude files via pattern

Nov
15
2009
PIrsyncD new version: 20091114
Posted by ebal at 10:16:20 in pirsynd

PIrsyncD

From ChangeLog:

  • pyinotify.py was updated to the latest stable version (0.8.8).
  • rsync partial functionality was added.
  • Minor code changes were made.

Get the latest version of PIrsyncD v20091114

TODO (or next goal): Excludes, Sure there would be files that you dont want to synchronize.

Jul
12
2009
Mirroring directories with PIrsynD
Posted by ebal at 20:29:45 in planet_ellak, pirsynd

Mirroring directories with PIrsynD

Τον τελευταίο καιρό βρέθηκα αντιμέτωπος με το εξής πρόβλημα:

Real time Data Replication over network.

Έπρεπε να υλοποιήσω μία λύση ανάμεσα σε δύο συστήματα που θα λειτουργούν ως Active/Passive. Ξεκίνησα το οδοιπορικό μου, ρωτώντας φίλους και συνεργάτες για το μοντέλο που θα επέλεγαν οι ίδιοι.

Φυσικά και η απλούστερη λύση είναι το rsync, αλλά το rsync θα πρέπει να εκτελείτε από κάποιο δαίμονα (π.χ. crond). Το πρόβλημα εδώ είναι ότι υπάρχει time lug μεταξύ των δύο συστημάτων. Εάν βάλω τον δαίμονα ανά μία ώρα θα έχω μία τεράστια διαφορά των δεδομένων της τάξης μίας ολόκληρης ώρας, κατά την ατυχή περίπτωση failover. Εάν βάλω τον δαίμονα ανά 5 λεπτά υπάρχει περίπτωση να μην προλάβει στα 5 λεπτά να ολοκληρώσει το syncing. Γενικά πρέπει να δημιουργήσεις ένα custom script που θα ελέγχει όλα αυτά κι όχι μπορεί να προκύψουν και φυσικά η διαχειριστική ευθύνη και κόστος αυξάνει αρκετά.

Οι περισσότεροι μου πρότειναν το drbd με την χρήση του υπάρχοντος heartbeat. Απλά απαράδεκτο. Πάρα πολλοί περιορισμοί: Ανάγκη για ξεχωριστό δίσκο (block device), ΔΕΝ κάνει scale up, πολύ δύσχρηστο, αρκετή δουλειά μέχρι να το φέρεις στα μέτρα σου, δουλεύει μόνο ως Server/Client. Με απογοήτευσε αρκετά τολμώ να πω με θάρρος. Είναι όμως kernel module, το οποίο σημαίνει: ταχύτητα και διαφάνεια στον τρόπο που εργάζεται το υπόλοιπο σύστημα στο block device κι όντως έχεις Real time Data Replication

Η επόμενη επιλογή μου ήταν το gluster. Ένα από τα καλύτερα λογισμικά που έχω δει και δουλέψει. Μερικά από τα χαρακτηριστικά του είναι τα εξής: πανεύκολη εγκατάσταση, απλούστατο configuration, εξαιρετικό scale up (no limit πιστεύω), μπορείς να χρησιμοποιήσεις ως distribute filesystem, για replication, για striping, και μπορείς να υλοποιήσεις κάποια μοντέλα raid δια μέσου του δικτύου. Οι δυνατότητες που έχει, πιστεύω ότι μπορούν να καλύψουν τον οποιοδήποτε. Αλλά υλοποιείται με το μοντέλο server/client. Ορίζεις έναν client ο οποίος μπορεί να μιλήσει με n servers. Με δύο συστήματα μόνο ΔΕΝ μπορεί να δουλέψει και φυσικά μόνο όταν όλοι οι clients είναι linux.

Το επόμενο μου λογισμικό προς δοκιμή ήταν το incrond. Κάνει χρήση του inotify όταν αλλάζει ένα αρχείο οπότε με ελάχιστο scripting και λίγο rsync μπορείς να κάνεις αρκετά πράγματα. Αλλά και πάλι υπάρχει το διαχειριστικό κόστος, αρκετό scripting και φυσικά υπάρχει ένα θεματάκι με το recursive στους καταλόγους. Έχει όμως τρομερό documentation κι εάν το έχεις λίγο με τον προγραμματισμό μπορείς να δημιουργήσεις μία αρκετά καλή λύση.

Προσπαθώντας να βρω όντως την τέλεια λύση, στο μυαλό μου ήρθαν τα λόγια του Γιάννη Στοΐλη

  • Γιάννη, έχεις δουλέψει ποτέ με κάποιο cluster file system ή κάτι παρόμοιο; Θέλω να βρω μία λύση για real time data replication
  • Μπα, κάτι τέτοια τα αφήνω σε εσένα για δοκιμές, εγώ συνεχίζω να παίζω με custom rsync scripts

Τελικά το σκέφτηκα λίγο παραπάνω και μου ήρθε στο μυαλό η εξής εικόνα:

chickenrazor.jpg

Ξεκίνησα λοιπόν να “ξαναβλέπω” το rsync ίσως με κάποιο inotify feature και voila: lsyncd
Μερικά δευτερόλεπτα μετά κι έτοιμο:

On server1:


lsyncd /data server2:/data

On server2:


lsyncd /data server2:/data

it’s just too simple

Αλλά … unbelievable αργό και buggy. Επίσης υπάρχει κι εδώ ένα θέμα με τo recursive, κρίμα γιατί μου άρεσε πάρα μα πάρα πολύ.

Σε αυτό το σημείο, σκέφτηκα να κάνω ένα βήμα πίσω και να ξαναδώ καλύτερα τις επιλογές μου. Αυτό που θέλω να υλοποιήσω είναι μία απλή και γρήγορη λύση για να συγχρονίζω δύο συστήματα. Στο μυαλό μου τριγύριζε η κουβέντα του Γιάννη: “Εγώ παίζω με custom rsync scripts” και σκέφτηκα: “What the fuck” ας κάνω κι εγώ κάτι τέτοιο. Έπρεπε όμως να βρω μία λύση να το συνδειάσω με το inotify.

Αναζητώντας στο διαδίκτυο για μία καλή υλοποίηση του inotify κατέληξα στο εξής: Pyinotify. Είναι η πιο πλήρης τεκμηριωμένη υλοποίηση του inotify, είναι γραμμένη σε python και έχει εξαιρετικά απλά παραδείγματα. Άρχισα να παίζω με τα παραδείγματα που έχει και να καταλαβαίνω καλύτερα το πως δουλεύει. Ίσως σε αυτό το σημείο να είναι καλό να αναφέρω ότι ΔΕΝ ξέρω python κι ότι ΔΕΝ έχω ξαναγράψει ποτέ κάποιο python script. Ξέρω όμως από προγραμματισμό και λίγο από εδώ - λίγο από εκεί κατέληξα στο εξής script: PIrsyncD!!!

To PIrsyncd σημαίνει: Python Inotify Rsync Daemon και είναι ένα εξαιρετικά απλό python script που τρέχει στο background ως δαίμονας. Ελέγχει συνεχώς έναν source κατάλογο που του έχουμε πει κι όταν γραφτεί κάτι σε αυτόν ή στους υποκαταλόγους του εκτελεί μία rsync εντολή ώστε να συγχρονίσει τους δύο καταλόγους. Το ενδιαφέρον εδώ είναι θα εκτελεστεί ΜΟΝΟ όταν γραφτεί κάτι, και ποτέ άλλοτε.

Παραθέτω τον κώδικα:


#!/usr/bin/env python

# Python Inotify Rsync Daemon
# Evaggelos Balaskas, ebalaskas AT ebalaskas DOT gr
# Last change: Sun Jul 12 22:50:17 EEST 2009

import pyinotify,os

source_path = "/tmp/data/"
dest_path   = "/tmp/data2/"

# Variables for rsync to a remote server
dest_server = ""
#dest_server = "server:"
rsync_ssh   = ""
# rsync_ssh   = "-e ssh"

rsync_path  = "/usr/bin/rsync"
rsync_args  = "-az --delete"

rsync_command = rsync_path + " " + rsync_args + " " + source_path + " " + rsync_ssh + " " + dest_server + dest_path

wm = pyinotify.WatchManager()
mask = pyinotify.IN_CLOSE_WRITE

class PTmp(pyinotify.ProcessEvent):
    def process_IN_CLOSE_WRITE(self, event):
        os.system(rsync_command)

p = PTmp()

notifier = pyinotify.Notifier(wm, p)
wm.add_watch(source_path, mask, rec=True)
notifier.loop(daemonize=True, pid_file='/tmp/PIrsyncD.pid')

Η αλήθεια είναι ότι είναι αρκετά buggy και θέλει δουλίτσα, αλλά δουλεύει και μάλιστα αρκετά καλά. Όσοι γνωρίζεται από python στείλτε μου τις παρατηρήσεις σας, είναι μάλιστα καλή ευκαιρία για να μάθω python.

Εάν θέλετε να το δοκιμάσετε τότε χρειάζεται να εγκαταστήσετε και την pyinotify ή μπορείτε να κατεβάσετε το εξής αρχείο: PIrsyncD_20090712

  -  

Search

Admin area

  • Login

Categories

  • blog
  • wiki
  • pirsynd
  • midori
  • books
  • archlinux
  • movies
  • xfce
  • code
  • beer
  • planet_ellak
  • planet_Sysadmin
  • microblogging
  • UH572
  • KoboGlo
  • planet_fsfe

Archives

  • 2025
    • April
    • March
    • February
  • 2024
    • November
    • October
    • August
    • April
    • March
  • 2023
    • May
    • April
  • 2022
    • November
    • October
    • August
    • February
  • 2021
    • November
    • July
    • June
    • May
    • April
    • March
    • February
  • 2020
    • December
    • November
    • September
    • August
    • June
    • May
    • April
    • March
    • January
  • 2019
    • December
    • October
    • September
    • August
    • July
    • June
    • May
    • April
    • March
    • February
    • January
  • 2018
    • December
    • November
    • October
    • September
    • August
    • June
    • May
    • April
    • March
    • February
    • January
  • 2017
    • December
    • October
    • September
    • August
    • July
    • June
    • May
    • April
    • March
    • February
    • January
  • 2016
    • December
    • November
    • October
    • August
    • July
    • June
    • May
    • April
    • March
    • February
    • January
  • 2015
    • December
    • November
    • October
    • September
    • August
    • July
    • June
    • May
    • April
    • March
    • January
  • 2014
    • December
    • November
    • October
    • September
    • August
    • July
    • June
    • May
    • April
    • March
    • February
    • January
  • 2013
    • December
    • November
    • October
    • September
    • August
    • July
    • June
    • May
    • April
    • March
    • February
    • January
  • 2012
    • December
    • November
    • October
    • September
    • August
    • July
    • June
    • May
    • April
    • March
    • February
    • January
  • 2011
    • December
    • November
    • October
    • September
    • August
    • July
    • June
    • May
    • April
    • March
    • February
    • January
  • 2010
    • December
    • November
    • October
    • September
    • August
    • July
    • June
    • May
    • April
    • March
    • February
    • January
  • 2009
    • December
    • November
    • October
    • September
    • August
    • July
    • June
    • May
    • April
    • March
    • February
    • January
Ευάγγελος.Μπαλάσκας.gr

License GNU FDL 1.3 - CC BY-SA 3.0