Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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?
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.