A good backup strategy for any computer involves keeping control of where stuff is stored. The fewer locations that contain files that change, the fewer locations have to be maintained.
UNIX users have always had the ability to keep things wherever they wanted and then to LINK that information into the required location. Basically, links create a link or tunnel between one file or folder and another. Most of the time, you will not notice that you’ve entered a tunnel and you are not interested really.
Windows users, however, have always been the poor cousins here. Stuck as we were in FATland, we had no access to fancy features such as links. So Microsoft in their inimitable fashion created a poor-man’s link – the Windows Shell Shortcut – so that the Windows GUI had some minimal capability (really only for menu’s and Windows Explorer).
Windows 2000 improved on this by introducing “Reparse Points” one form of which is the “Junction“. This is an extension to NTFS that allows folders to be joined (linked) to another location in the local volume space. Making junctions is not an obvious process, you can do it from the disk manager and there is a tool in the Windows 2000 server resource kit called
linkd. The POSIX tools included in the resource kit contain the UNIX command
ln which can also create junction points and hard links;
fsutil in XP can also. There are some third party tools too.
It’s odd because I seem to remember that OS/2 had some kind of linking feature.
Anyway, links of the UNIX type are a massively useful feature that has finally (with Vista, Windows 2008 and beyond) made it fully to NTFS and Windows.
Vista, Windows 2008 and Windows 7 all have a command line tool called
mklink. This can be used like the Unix
ln command to create both hard links (which must be on the same volume) and soft links. Soft links under Windows can, in fact, span across SMB network drives as well.
You might also like to look at another free tool called “Link Shell Extension” by Hermann Schinagl. This integrates into Windows Explorer, the web site also has a more complete explanation of the history of links in Windows. LSE does a number of clever things and is well worth a look. Hermann also has a “dupmerge” tool on his web site that will replace duplicated files with hard links.
So now, if we want to tweak the HOSTS file for example (c:\windows\system32\drivers\etc\hosts), we don’t need to leave in place since that would mean that we would need an extra backup routine. Instead, copy it to somewhere that already gets backed up. Delete the original file and then from the command line:
mklink c:\windows\system32\drivers\etc\hosts %USERPROFILE%\BACKUPS\hosts
Now you can edit the hosts file from either location, there is only one file (in
%USERPROFILE%\BACKUPS). The difference being that even if you delete the file from its normal location, it will still exist in the “real” location. If you delete it from its “real” place in
BACKUPS of course, the link will be broken and wont work.
To link a complete folder, it is the same command with a
/D parameter added. For example, I keep a folder of command line utilities such as
rsync in a folder on a USB pen drive. I sync that folder to the
BACKUPS location on my hard drive for convenience but I need the folder in my
PATH otherwise its hard to execute the utilities. I don’t want a really long path, it’s bad enough already, so I link the folder to
c:\cmd with the following:
mklink /D c:\cmd %USERPROFILE%\BACKUPS\PEN\cmd
Now I add c:\cmd to the path and the utilities seem to be in both places.
I’ve said in other posts that I like to reinstall Windows now and again but it can be a pain to restore all of the document files. Similarly, if you keep multiple operating systems on your hard drive, how do you keep your documents sorted? One way is to put all documents, videos, music, etc. onto a separate partition. Now, instead of going mad with the Windows registry trying to relocate your normal documents folders to another drive. Simply delete the normal documents folder –
%USERPROFILE%\Documents\ under Windows 7 and relink it to the appropriate folder on the other drive as so:
mklink /D %USERPROFILE%\Documents d:\Docs
Put this in a script that you run when you reinstall Windows and its easy and quick.
One final note. You may find a few pieces of software that cannot cope with links. Certainly Subversion cannot though Bazaar can. Windows Explorer seems OK though as do utilities such as RSYNC.