Is it possible to sync two linux directories in real time ?
Solution 1:
lsyncd seems to be the perfect solution. it combines inotify (kernel builtin function witch watches for file changes in a directory trees) and rsync (cross platform file-syncing-tool).
lsyncd -rsyncssh /home remotehost.org backup-home/
Quote from github:
Lsyncd watches a local directory trees event monitor interface (inotify or fsevents). It aggregates and combines events for a few seconds and then spawns one (or more) process(es) to synchronize the changes. By default this is rsync. Lsyncd is thus a light-weight live mirror solution that is comparatively easy to install not requiring new filesystems or blockdevices and does not hamper local filesystem performance.
Solution 2:
In real time as far as i know there's only DRBD. But I don't think it applies at your situation, since when you delete a file you'll delete it also on the external disk. More easily you can use rsync and a cron script that run every few minutes.
Solution 3:
You can just create a Software RAID1 over your internal and external hard drives. For the system it doesn't make a difference if it's a built-in hard drive or an externally attached mass storage.
But RAID is no backup! What happens if you accidentally delete a file on your hard drive? It also gets deleted on your external "backup" drive.
Backups usually comprise more than one generation of files so you can retrieve accidentally deleted files from it.
Solution 4:
incron (as suggested to me on this site earlier this year).
It's still no substitute for a proper backup procedure though.