29

I would like to sync a directory of an internal hard drive to an external hard drive.

When I write or modify a file on my internal hard drive, automatically the same file would be copied to the external hard drive... and bye bye backup ;)

This would be something like a RAID with an external hard drive.

Is this possible?

TRiG
  • 1,167
  • 2
  • 13
  • 30
stighy
  • 911
  • 8
  • 21
  • 31

7 Answers7

32

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.

juwens
  • 420
  • 4
  • 5
9

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.

sfarbota
  • 103
  • 4
PiL
  • 1,591
  • 8
  • 6
  • Thank you for your answer. But if "cron" rsync to run every ..5 minutes, does it compromise performance ? Isn't it too heavy (it check every files if something is changed ?) ? – stighy Jun 06 '10 at 11:16
  • That's why they invented file system with snapshots capabilities ;) – PiL Jun 06 '10 at 11:31
  • 1
    DRBD can be a bit complicated to configure, if you need help configuring it I wrote a nice article: http://geek-kb.com/install-and-configure-drbd-centos-6/ – Itai Ganot Aug 31 '15 at 09:14
8

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.

joschi
  • 20,747
  • 3
  • 46
  • 50
  • 5
    A big +1 for the explicit "RAID is not backup". – nickgrim Jun 21 '12 at 11:29
  • Also a software raid with internal and external hard drive members is probably going to be very slow, unreliable and designated to break pretty often. – David Sep 12 '16 at 14:34
2

incron (as suggested to me on this site earlier this year).

It's still no substitute for a proper backup procedure though.

Matthew Iselin
  • 717
  • 1
  • 7
  • 20
1

git-annex can also be used to achieve this.

git-annex allows managing files with git, without checking the file contents into git. While that may seem paradoxical, it is useful when dealing with files larger than git can currently easily handle, whether due to limitations in memory, time, or disk space

There is a walkthrough to quickly bring users up to speed with git-annex

Dave M
  • 4,494
  • 21
  • 30
  • 30
ypid
  • 161
  • 1
  • 4
  • Whilst this may theoretically answer the question, [it would be preferable] to include the essential parts of the answer here, and provide the link for reference. – Itai Ganot Aug 31 '15 at 09:05
0

https://github.com/perfecto25/poni

inotify-based rsync daemon, written in crystal lang

perfecto25
  • 288
  • 3
  • 7
0

You can maybe check chironfs http://www.furquim.org/chironfs/

pQd
  • 29,561
  • 5
  • 64
  • 106
Dom
  • 6,628
  • 1
  • 19
  • 24