0

If there's any change in ~/mydir, I want to copy it to ~/someotherdir/mydir_revisions/04-02-2013 (which is today's date). It should continue to copy to this same directory for 1 week. Thereafter, it should create a new directory (~/someotherdir/mydir_revisions/04-09-2013, which is that day's date and continue using that directory for a week). These backups would continue indefinitely, always utilizing a particular date for a whole week before updating the date.

If it matters, I'm using Archlinux and copying to a different filesystem. How can I do this with incron or any other recommended package?

6
  • Are you comfortable with any scripting language? Bash or Perl or similar?
    – terdon
    Apr 3, 2013 at 0:07
  • 1
    I'd like to suggest using inotifywait for this; have used it on several occasions in the past, works a treat.
    – tink
    Apr 3, 2013 at 0:08
  • @terdon, I prefer Python, but I'd be willing to learn Bash if need-be
    – Raj
    Apr 3, 2013 at 0:09
  • Which ever route you're going to go down, I'd like to point out that neither incron, inotifywait or either of the two python implementations I'm aware of will stand up recursive watches for newly created subdirectories automatically - just a small caveat.
    – tink
    Apr 3, 2013 at 2:18
  • Have you considered using a version control system like git? You'd get a record of the changes too.
    – parkydr
    Apr 3, 2013 at 8:39

1 Answer 1

2

Depending on your distribution, there is the package incrond.

What this package does is, it receives filesystem events from the kernel via inotify.

Your setup would be something as:

/path/to/monitored/directory IN_MODIFY /path/to/script/to/execute

Let's say you have the following script in $HOME/incron-move.sh, with does the following:

#!/bin/sh
WEEK_OF_YEAR=`date +"%W"`
cp -ar $HOME/mydir /other/dir/mydir_revisions/$WEEK_OF_YEAR

What this script does, is to copy the full contents of /path/to/monitored/directory to /other/dir/mydir_revisions/13 if it were to run today (02/04/2013 it's in the 13th week of the year)

It isn't the full requirement of yours, but solves your problem with some degree of reliability.

2
  • I'm aware of that package. I'm looking to do something more specific than copying to a directory upon change. I want to include a date, as described in the question.
    – Raj
    Apr 3, 2013 at 0:15
  • @Raj date supports alot of options (eg. +%Y-%m-%d). Also, there is likely a Python inotify interface-module. Apr 4, 2013 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.