LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-08-2009, 10:01 AM   #1
Paul Griesbaum
Member
 
Registered: Dec 2008
Posts: 48

Rep: Reputation: 15
make duplicate copies of files


I'm using Mandriva 2009 and was wondering if I could somehow save a document or other file in multiple locations? Here's what I'd like to do:
I've created a backup folder. Is there someway to save files to that backup folder at the same time the file is being saved to another location?
 
Old 06-08-2009, 10:04 AM   #2
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
There are a few ways you could script this, though I'm not sure of a native way.
 
Old 06-08-2009, 10:12 AM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
I know of no native way (well, what I understand by "native" anyway). In first place, there's no way that Linux can now which files need to be backed, and which of them do not.

So you have to resort to a more defined criteria. For example, files that are saved on a given directory but only when they have a given extension, or something similar. If you can concrete the conditions under which a file is a candidate for backup, then we might come with a solution based on inotify, which would be the cleanest thing I can think of.
 
Old 06-08-2009, 10:19 AM   #4
Paul Griesbaum
Member
 
Registered: Dec 2008
Posts: 48

Original Poster
Rep: Reputation: 15
saving file to multiple locations

Well, like say something like an abiword file with the abw extension. How could I save a file like this to two different folders? Is there some type of syncing app in the repositories that could do this?
 
Old 06-08-2009, 10:22 AM   #5
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
Why not a little script that checks every n seconds for changes in filesize to .abw files in a specific directory. If true, copy
 
Old 06-08-2009, 10:30 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
maybe you can cron something like this once a day:
Code:
for file in `find ~/stuff`
do
 cp $file ~/bak/$file.`date +%j`
done
by and by, i havent tested this yet; season to taste...

Last edited by schneidz; 06-08-2009 at 10:32 AM.
 
Old 06-08-2009, 10:34 AM   #7
mcolangelo
LQ Newbie
 
Registered: Jun 2009
Location: USA, WI
Distribution: Gentoo
Posts: 25

Rep: Reputation: 17
a script with inotifywait seem like the easiest solution. Something like

Code:
while inotifywait -m -e modify /path/to/primary-save-location/
do
   if [ -f %f ]; then
	cp %f /to/other/save/location
   fi
done
That will watch for changes in "/path/to/primary-save-location/". Then when a change occurs it will verify that the file that triggered the change exists and then copy it to /to/other/save/location

I didn't have a chance to test it, but it looks about right

Last edited by mcolangelo; 06-08-2009 at 10:35 AM.
 
Old 06-08-2009, 10:39 AM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Many approaches could work. If you don't care about it being instantaneous, you can do a cron job to sync it. With this approach you could use rsync, which would take care of the syncing and would only copy the files that are new or need to be updated.

If you need instant sync in the same moment that you save the file, then inotify is the way to go, if you have the inotify tools installed you could do something like this:

Code:
inotifywait tmp/1 --event create --event modify --format=%f --monitor \
  | while read filename
    do
      cp --force "$filename" /some/other/directory/
    done
Untested, so make your checks and make sure you understand the snippet before you use it. Another matter would be how to launch this, if your distro has some kind of file to launch custom scripts at init, you could run this from there (i.e. /etc/rc.d/rc.local or something like that, in Gentoo we have /etc/conf.d/local.start). Wrapped into a

Code:
su your_user_name -c '<insert the above snippet here>'

Last edited by i92guboj; 06-08-2009 at 10:40 AM. Reason: typos
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How to Find duplicate copies of files Using fdupes in Ubuntu LXer Syndicated Linux News 0 10-17-2008 09:21 PM
How do I make qmail forword *copies* of emails? Rotwang Linux - Server 2 07-17-2007 09:01 AM
How to make bootable copies of distro CD's llewellyn Linux - Software 3 02-15-2006 04:01 PM
spooling duplicate copies while printing to samba server jomy Linux - Networking 1 08-04-2004 02:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration