To synchronize files in real-time between two servers, there are several solutions you can consider:
- rsync with inotifywait:
Usersync
in combination withinotifywait
.inotifywait
monitors file system changes on server A, and every time a change is detected,rsync
synchronizes the files with server B. This method is very efficient for almost real-time synchronization.Example script:
SRC="/path/to/sync"
DEST="user@serverB:/destination/path"
inotifywait -m -r -e modify,create,delete $SRC | while read path action file; do
rsync -avz $SRC $DEST
done
- Lsyncd:
Lsyncd (Live Syncing Daemon) is a more advanced tool that usesrsync
for synchronization andinotify
to monitor changes in real-time. It is easy to configure and runs as a background daemon. - lftp:
Althoughlftp
is not specifically a real-time synchronization tool, you can use it for frequent syncs using itsmirror
command with the--continue
option to synchronize directories between servers A and B. However, this is not a real-time solution but requires periodic execution.Example of
lftp
usage:lftp -e "mirror --reverse --delete --continue --verbose /local/directory /remote/directory; bye" -u user,password serverB
Note: While
lftp
can be useful, it doesn’t provide real-time synchronization. For that,rsync
withinotifywait
orLsyncd
are better options.
Leave A Comment