I have a directory "/mydir" and I want to automatically sync/copy all the content of /mydir directory to "/yourdir" directory all the time.
meaning, if some application creates a file in /mydir, it supposed to be copied/available in "/yourdir" directory
I need to have two copies.
Can we do this using rsync ? or hard link ? (*both /mydir and /yourdir available in same server)
As migurus said, a hard link doesn't create a copy of a file; it creates another name for a single file.
And, even if /mydir and /yourdir are on the same server, you can't create a hard link between files in those directories unless both of those directories are in the same filesystem (i.e. under the same mount point) on that server.
DESCRIPTION
The inotify API provides a mechanism for monitoring filesystem events.
Inotify can be used to monitor individual files, or to monitor directo
ries. When a directory is monitored, inotify will return events for
the directory itself, and for files inside the directory.
which is accessible from the shell with:
inotify-tools is a set of command-line programs for Linux providing a
simple interface to inotify. These programs can be used to monitor and
act upon filesystem events. inotify-tools consists of two utilities:
.
inotifywait simply blocks for inotify events, making it appropriate
for use in shell scripts.
.
inotifywatch collects filesystem usage statistics and outputs counts
of each inotify event.
So one could run inotifywait which would block execution of a script until there was a change, then the script could call rsync , then start all over again.