To synchronize files in real-time between two servers, there are several solutions you can consider:
- rsync with inotifywait:
Usersyncin combination withinotifywait.inotifywaitmonitors file system changes on server A, and every time a change is detected,rsyncsynchronizes 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 usesrsyncfor synchronization andinotifyto monitor changes in real-time. It is easy to configure and runs as a background daemon. - lftp:
Althoughlftpis not specifically a real-time synchronization tool, you can use it for frequent syncs using itsmirrorcommand with the--continueoption to synchronize directories between servers A and B. However, this is not a real-time solution but requires periodic execution.Example of
lftpusage:lftp -e "mirror --reverse --delete --continue --verbose /local/directory /remote/directory; bye" -u user,password serverB
Note: While
lftpcan be useful, it doesn’t provide real-time synchronization. For that,rsyncwithinotifywaitorLsyncdare better options.

Leave A Comment