I want to keep one directory mirrored to another automatically. I had trouble getting lsyncd to run reliably and would rather try something else. Can rsync run whenever files change, or is there a better tool for this?
What can I use to automatically mirror a directory on Linux?
Answers
Syncthing is worth a look if you want a dedicated sync tool rather than a script. It can run locally or sync across devices, and has a fair amount of configuration available.
Check the folder settings before relying on it as a one-way mirror. Syncing and keeping a destination as a faithful copy of a source are not necessarily the same thing.
Reply to this answer
Rsync does the copying, but it doesn't watch directories by itself. You can schedule it with cron or a systemd timer. That won't be instant, but it avoids having to build a file-watching script.
If you need changes picked up sooner, inotifywait can watch the source and trigger rsync. A script needs to handle new subdirectories, missed events and restarts, so this is a bit more work than just calling rsync once. A systemd path unit combined with rsync is another option to investigate.
Be careful with rsync's delete option. Without it, files removed from the source can remain at the destination. With it, deletions are propagated, so check the source and destination paths and do a dry run first.
Reply to this answer
For a graphical option, look at FreeFileSync or luckyBackup. They are alternatives to setting up the whole thing by hand. Check their scheduling and mirror settings against what you need, especially how they handle deleted files.
Reply to this answer
A mirror isn't much protection against mistakes. If a file gets deleted or damaged at the source, an automatic sync can carry that change over too. Keep a separate backup, preferably another copy off site, if these files matter.
Reply to this answer
A symbolic link might be enough if the goal is simply to access the same directory from two paths. It won't give you a second copy, though, so it doesn't meet the usual meaning of a mirror.
Reply to this answer
Add your answer
Answers are reviewed before publication.
4e~clampcase_732:
Running a sync manually can give you a chance to catch a mistake first, though it still isn't a substitute for a separate backup.