You are not logged in.

#1 2012-07-26 14:49:33

Lenry
Member
From: Szeged, Hungary
Registered: 2010-03-27
Posts: 66
Website

Copying files into two directories

I would like a solution about how can I do that whenever somebody places something in a specified directory, some daemon immediately sync it to a backup directory, keeping the original tree structure. Not scheduling, but immediately copy, as soon as the original copy ends.
But only on copying. I don't want to delete automatically anything from the backup dir.

I know it looks like a lame question, but I can't find a good solution by myself.

Offline

#2 2012-07-26 15:07:15

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Copying files into two directories

rsync maybe?


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#3 2012-07-26 15:23:39

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: Copying files into two directories

if you are using systemd, a systemd path unit may work. This could trigger a service file which in turn runs rsync.

Or something like this with inotify-tools:

inotifywait -r -m -e close_write --format %w%f <directory> | while read f; do
 echo $f was written to
 <sync $f>
done

I use something similiar to automatically encode video files I put in a specific directory, works quite well.

Offline

#4 2012-07-26 15:34:33

aline
Member
Registered: 2009-12-17
Posts: 22

Re: Copying files into two directories

incron offers a easy way to configure actions when certain path in filesystem changes. In your incrontab you could do something like

/my/directory/watch IN_MODIFY,IN_CREATE,IN_MOVE,IN_DELETE rsync ...

Last edited by aline (2012-07-26 15:35:23)

Offline

#5 2012-07-27 21:09:47

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: Copying files into two directories

That sounds a lot like you want to snoop on someone else tongue

If you specify your problem better maybe someone might have some experience with it and suggest an appropriate solution, you may want to say if you want to "backup" only text files or all files.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#6 2012-07-27 23:17:15

anonymous_user
Member
Registered: 2009-08-28
Posts: 3,059

Re: Copying files into two directories

Perhaps look into fsniper?

Offline

#7 2012-07-28 07:03:29

Lenry
Member
From: Szeged, Hungary
Registered: 2010-03-27
Posts: 66
Website

Re: Copying files into two directories

R00KIE wrote:

That sounds a lot like you want to snoop on someone else tongue

If you specify your problem better maybe someone might have some experience with it and suggest an appropriate solution, you may want to say if you want to "backup" only text files or all files.

Nothing illegal smile
I'm a sysadmin at an office. We have a fileserver, from which I do a weekly backup to a portable USB drive. Some days ago I deleted everything from the USB drive as I prepare to do the weekly backup and that very moment I finished the wipe, one of my colleagues accidentally deleted something important from the server. As I wiped the backup a minute ago, there were no backup to restore those files.
That is I want to avoid in the future with this secondary backup.

anonymous_user wrote:

Perhaps look into fsniper?

I'll look into it, thanks

Last edited by Lenry (2012-07-28 07:05:09)

Offline

#8 2012-07-28 10:35:22

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: Copying files into two directories

Fair enough smile I'd say you should probably look into your backup sequence as it seems is what made things fail. I'm no expert but deleting your only backup before you make a new one sounds like a bad idea.

If it was me I would keep some copies local to the file server, say a week's worth of backups, maybe using something like rsnapshot or similar. If you need to clear the external hd before you backup then get another one, then always delete the oldest copy.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#9 2012-07-31 07:46:02

Lenry
Member
From: Szeged, Hungary
Registered: 2010-03-27
Posts: 66
Website

Re: Copying files into two directories

R00KIE wrote:

Fair enough smile I'd say you should probably look into your backup sequence as it seems is what made things fail. I'm no expert but deleting your only backup before you make a new one sounds like a bad idea.

I know, it is, but I have to work with what I have.

If it was me I would keep some copies local to the file server, say a week's worth of backups.

That's exactly what I did at the end of the day smile
I made a cron job, that runs an rsync script every night, and create a backup of every new file.
It still needs a little tweaking (it would be great if it magically know what subfolders belongs to one project, and do a new backup of the full project, if anything changes in that, but I'll figure out something), but at least it works, and add some bonus level of safety.

Last edited by Lenry (2012-07-31 07:51:15)

Offline

#10 2012-07-31 08:33:57

JackH79
Member
From: Australia
Registered: 2009-06-18
Posts: 663
Website

Re: Copying files into two directories

As anonymous_user mentioned already, fsniper will do everything you ask for.
If you want to run it as a daemon, have a look at the wiki page on how to do it.

Offline

Board footer

Powered by FluxBB