Results 1 to 8 of 8

Thread: Python - Simple method of detection file changes

  1. #1
    Join Date
    May 2008
    Location
    UK
    Beans
    1,451
    Distro
    Ubuntu 8.04 Hardy Heron

    Python - Simple method of detection file changes

    I am looking for recommendations for the simplest way of getting a python application to detect or be notified of changes to (i.e. creating, deletion, modifying or renaming of a file) within a file system (or a sub set of directories).

    I would rather not do full recursive search looking for new files and changes and running that every few minutes, i would prefer an (more or less) real time notification of changes.

    Is there anything like that available in a library that i can build an application on ?
    Last edited by Tony Flury; August 25th, 2011 at 09:44 AM.
    Tony - Happy to try to help.
    Unless otherwise stated - all code posted by me is untested. Remember to Mark the Thread as Solved.
    Ubuntu user number # 24044 Projects : TimeWarp - on the fly Backups

  2. #2
    Join Date
    Aug 2007
    Location
    Auckland, NZ
    Beans
    196
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Python - Simple method of detection file changes

    I don't know if this is what you want. But I would track the time you edited the file and possibly the size and save the files last edited time and store it in a database or another file or something.

    Then every so often check that they match up.
    If they don't then, compare them line by line, until you find a change.

    I know this is not really what you asked for.. because that was probably the solution you originally had in mind.
    And if you have lots of tiny files in many sub-directorys it could be a lot of processing overhead, waste of hard disk seek time and could take quite a while.

    I actually have created a database and stored all my files in it as blobs. their file size, name, location, last modified, user who modified etc. and I log the INSERT, UPDATE & DELETES to a history table which is managed by triggers. So this would serve me fine for that purpose. However this will not work with the traditional filesystem.
    Uses: Jaunty J 9.04 & Maverick 10.10

  3. #3
    Join Date
    Sep 2010
    Beans
    62

    Re: Python - Simple method of detection file changes

    Quote Originally Posted by Tony Flury View Post
    I am looking for recommendations for the simplest way of getting a python application to detect or be notified of changes to (i.e. creating, deletion, modifying or renaming of a file) within a file system (or a sub set of directories).

    I would rather not do full recursive search looking for new files and changes and running that every few minutes, i would prefer an (more or less) real time notification of changes.

    Is there anything like that available in a library that i can build an application on ?
    Search google for AIDE (intrusion detection). Or pyInotify

  4. #4
    Join Date
    May 2008
    Location
    UK
    Beans
    1,451
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Python - Simple method of detection file changes

    Thanks Kurum - excellent.

    I have in mind a on-fly backup program, which will keep timed snapshots of individual files, and eventually will have a GUI that allows you to browse through the various time stamped versions of a file, and restore them - i.e. think Nautilus but with a time dimension derived from the backup.

    After the first (admittedly time consuming back up build), a service will sit and monitor the file system, and take a snapshot of the files as they are changed, and queue them for storage.
    If I shutdown before all the queued files are stored - the queue will be retained - and storage will be re-attempted next time.

    My intention is to be able to backup my data to a NAS device but without having to leave my laptop on as it churns away across the folders building massive zip files (which by the time they get to my NAS device they are generally unreadable).

    Eventually I may offer it as an application suite for people to play with, enhance etc.
    Tony - Happy to try to help.
    Unless otherwise stated - all code posted by me is untested. Remember to Mark the Thread as Solved.
    Ubuntu user number # 24044 Projects : TimeWarp - on the fly Backups

  5. #5
    Join Date
    Aug 2011
    Location
    India
    Beans
    34
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Python - Simple method of detection file changes

    Hi,
    I know this post was created a long time ago, but still it has very recently helped me to get out of a similar deadlock. Hence thank you, guys.

  6. #6
    Join Date
    Mar 2010
    Location
    Norway
    Beans
    674

    Re: Python - Simple method of detection file changes

    Quote Originally Posted by kunal00731 View Post
    Hi,
    I know this post was created a long time ago, but still it has very recently helped me to get out of a similar deadlock. Hence thank you, guys.
    AFAIK, it was created one hour ago.

  7. #7
    Join Date
    Aug 2011
    Location
    India
    Beans
    34
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Python - Simple method of detection file changes

    Sorry, My bad. Anyway it was really good.

  8. #8
    Join Date
    Aug 2011
    Location
    India
    Beans
    34
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Python - Simple method of detection file changes

    Sorry, My bad. Anyway it was really good.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •