ln - command line hard links

Submit command line tools that you find here.
Post Reply
Message
Author
User avatar
Andrew Lee
Posts: 3116
Joined: Sat Feb 04, 2006 9:19 am
Contact:

ln - command line hard links

#1 Post by Andrew Lee »

Never thought I'd get excited over a CLI program, but here it is:

https://schinagl.priv.at/nt/ln/ln.html

It does exactly what I have been looking for, and possibly more.

So what I wanted to do is this:
  1. Suppose I have a source folder to backup called c:\source
  2. Initially I copy everything to a backup location called d:\backup
  3. Then after things change in c:\source, I want to copy everything to d:\backup2, with these conditions:
    • if a file has not been modified, it creates a hard link back to the same file in d:\backup
    • if a file has been modified or is new, it copies that file instead
  4. After some time, I can create a new backup called d:\backup3, but basing off d:\backup2, and so on
I had no idea this method of backup is called Delorean Copy, so the way to do this via command line is:

Code: Select all

ln --copy c:\source d:\backup
ln --delorean c:\source d:\backup d:\backup2
ln --delorean c:\source d:\backup2 d:\backup3
etc.
The nice thing about this way of copying is that each backup folder always contain a full copy of c:\source, but the amount of disk space used by each subsequent backup is only increased by the changed files.

I have been doing this by hacking together something using rsync and Linux Subsystem for Windows, but this is far simpler and cleaner using a native Win64 CLI.

User avatar
__philippe
Posts: 690
Joined: Wed Jun 26, 2013 2:09 am

Re: ln - command line hard links

#2 Post by __philippe »

@Andrew
Typo correction for above link
https://schinagl.priv.at/nt/ln/ln.html

(...for the lack of an "l" an "ERROR 404" came to the fore... :P )

User avatar
Andrew Lee
Posts: 3116
Joined: Sat Feb 04, 2006 9:19 am
Contact:

Re: ln - command line hard links

#3 Post by Andrew Lee »

Corrected in original post. Thanks!

User avatar
Midas
Posts: 6912
Joined: Mon Dec 07, 2009 7:09 am
Location: Sol3

Re: ln - command line hard links

#4 Post by Midas »

Cool example for DeLorean backups -- and having a CLI utility is great for scripting. 8)

FTR, LinkShellExtension by the same author isn't really portable but has nice GUI for the same purpose...

Specular
Posts: 443
Joined: Sun Feb 16, 2014 10:54 pm

Re: ln - command line hard links

#5 Post by Specular »

Andrew Lee wrote: Fri Jul 21, 2023 11:31 pm I had no idea this method of backup is called Delorean Copy, so the way to do this via command line is:
Interesting term :D I normally see this method referred to as snapshotting. For example rsnapshot for Linux (a popular utility that leverages rsync) uses this same method, where hardlinks are used for unchanged files in the next snapshot. It's very useful for a NAS backup system (particularly if set up to handle NTFS-compatible attributes and where the snapshots have read-only permissions).

The benefit, as you've seen, is all files are visible for each snapshot (rather than merely just the changed files), so whatever the latest version is can be restored as-is.

Downside is any corruption of a file the hardlinks are based on will propagate to all hardlinks. Though drives have their own internal ECC and it's hard to guestimate the likelihood such corruption would occur (seems more likely a drive would die).

User avatar
Andrew Lee
Posts: 3116
Joined: Sat Feb 04, 2006 9:19 am
Contact:

Re: ln - command line hard links

#6 Post by Andrew Lee »

Specular wrote: Mon Jul 24, 2023 11:32 pm Downside is any corruption of a file the hardlinks are based on will propagate to all hardlinks. Though drives have their own internal ECC and it's hard to guestimate the likelihood such corruption would occur (seems more likely a drive would die).
I think what you are referring to is bit-rot, and the way I deal with it is to:

1) Keeps a CRC of all backed up files using RapidCRC, and check from time-to-time

2) Only keep a max of say 7 snapshots before starting all over again with a fresh master.

Yeah, I know it's tedious, but we've all been there before when the hard drive dies on ya...

User avatar
Andrew Lee
Posts: 3116
Joined: Sat Feb 04, 2006 9:19 am
Contact:

Re: ln - command line hard links

#7 Post by Andrew Lee »

Midas wrote: Mon Jul 24, 2023 3:34 am Cool example for DeLorean backups -- and having a CLI utility is great for scripting. 8)

FTR, LinkShellExtension by the same author isn't really portable but has nice GUI for the same purpose...
I had no idea! I thought it was just a cool shell extension for visualizing symlinks/hardlinks. I didn't know it could perform Delorean backups as well.

Will still stick to ln for portability + scripting, but it is great to know a GUI alternative is available!

Post Reply