BackupPC-users

Re: [BackupPC-users] NTFS symbolic links [Solved]

2011-01-13 12:18:06
Subject: Re: [BackupPC-users] NTFS symbolic links [Solved]
From: Erik Hjertén <erik.hjerten AT companion DOT se>
To: backuppc-users AT lists.sourceforge DOT net
Date: Thu, 13 Jan 2011 17:53:38 +0100
Just reporting back my solution for reference.

Denis Jedig skrev 2011-01-02 00:32:

Unfortunately, saving NTFS metadata with rsync has always been a 
pain in the ass, as the protocol simply was not designed for most 
of it. While symbolic links and junctions would fit in rather 
easily, to my best knowledge they are not implemented.

You could build some cludge using dir /S /AL (which will give you 
symbolic links as well as junctions in the output, but 
unfortunately it will come in a way which is poorly suitable for 
scripting it back into shape. Alternatively, you could write some 
powershell lines using Get-ChildItem, checking for the 
ReparsePoint attribute and using Get-ReparsePoint for retrieving 
the destination. The people from the Windows PowerShell 
newsgroups/lists should be able to help you here.

Thanks Denis for your input!

I ended up writing two small powershell scripts, getLinkInfo.ps1 and restoreLinks.ps1 (sources below)

getLinkInfo.ps1 actually calls "dir /al /s" and therefore the script is dependent of languge (in this case swedish) in the output from "dir". The script takes a directory path as argument and creates two text files, dirs.txt and links.txt. They contain the directory structure, including all subdirectories, and all the links. I let BackupPC backup these files.

I didn't use powershell to get the directory and link info as I reached the end of my knowhow. I bet some one else could this properly.

restoreLinks.ps1 reads these two text files and recreates the directory structure and all the links. It needs admin privileges.

I guess one could run the getLinkInfo.ps1 from BackupPC using DumpPreUserCmd or similar. I haven't tried it though.

It's cludgy as h*ll, but it works. There is no error handling so use this at your own risk. :)

Kind regards
/Erik

----- getLinkInfo.ps1 -----
clear-host
$list = cmd /c dir $args[0] /al /s
$newlinklist = ""
$newdirlist = ""
for ($row = 3; $row -le ($list.length-5); $row++) {
  if ($list[$row].split( " ")[1] -like "Inneh*ll") {
    $curdir = $list[$row].substring(22)
    $newdirlist = $newdirlist + $curdir + "`r`n"
    $curdir
  }
  if ($list[$row].split(" ")[6] -like "<symlink>") {
    $curfile = $list[$row].substring(36, $list[$row].indexof("[")-36)
    $curtarget = $list[$row].substring($list[$row].indexof("[")+1, $list[$row].length-$list[$row].indexof("[")-2)   
    $newlinklist = $newlinklist + $curdir + "\" + $curfile + "%" + $curtarget + "`r`n"
  }
}
$result = new-item links.txt -type file -force -value $newlinklist
$result = new-item dirs.txt -type file -force -value $newdirlist
-----

----- restoreLinks.ps1 -----
$linklist = get-content links.txt -encoding UTF8
$dirlist = get-content dirs.txt -encoding UTF8
for ($row = 0; $row -le ($dirlist.length-1); $row++) {
  md $dirlist[$row].split("%")[0]
}

for ($row = 0; $row -le ($linklist.length-1); $row++) {
  cmd /c mklink $linklist[$row].split("%")[0] $linklist[$row].split("%")[1]
}

-----
--

Companion Erik Hjertén
erik.hjerten AT companion DOT se
0708-90 55 30

Näsvägen 40, 139 33 Värmdö
08-403 750 50
www.companion.se
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
BackupPC-users mailing list
BackupPC-users AT lists.sourceforge DOT net
List:    https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki:    http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/
<Prev in Thread] Current Thread [Next in Thread>