File Reconciliation

kevinoffsite

New Member
I was recently involved in a server rebuild and restoration of files from a backup, the main file share failed to restore all files the first time, it skipped over large files. So while preparing to correct that problem employees jumped into the files that were restored and began editing them and creating new files, So I was forced to to a new restore to external drive which this time succeeded. So Now I want to reconcile the full backup with the file system.

I do not want over write folders but just add the files that were missing without replacing stuff that has been edited..

I was going to use salamader but got nervous, any advice?
 
A simple powershell script could handle this

sudo code
  • Grab list of prod_share files only something like $prodFiles = Get-ChildItem -Path <prodshare> -Recurse -File
  • Grab list of externalBackup $externalFiles = Get-ChildItem -Path <externalBackupshare> -Recurse -File
  • Compare the lists if file is in externalBackup and not prod add the file object to an array
  • Run through the $missingFile array and copy each file over
 
A simple powershell script could handle this

sudo code
  • Grab list of prod_share files only something like $prodFiles = Get-ChildItem -Path <prodshare> -Recurse -File
  • Grab list of externalBackup $externalFiles = Get-ChildItem -Path <externalBackupshare> -Recurse -File
  • Compare the lists if file is in externalBackup and not prod add the file object to an array
  • Run through the $missingFile array and copy each file over
Not super efficient with PS, and we are talking 2TB of data...
 
This should work, be warned I haven't tested the code.
Code:
$prodShare = "\\fileserver\share"
$externalBackup = "\\backupserver\share"

$prodFileList = Get-ChildItem -Path $prodShare -Recurse -File
$externalBackupFileList = Get-ChildItem -Path $externalBackup -Recurse -File


foreach ($backupFile in $externalBackupFileList)
{
    $found =$false

    foreach ($prodFile in $prodFileList)
    {
        $tempProdName = $prodFile.FullName.Replace($prodShare,'')
        $tempbackupName = $backupFile.FullName.Replace($externalBackup,'')

        if($tempProdName -like $tempbackupName)
        {
            $found = $true
            break
        }
    }
    if((-not $found))
    {
        $missingFileList += @($backupFile)
    }
}


foreach($file in $missingFileList)
{
    $newFileName = "$prodShare$($file.FullName.Replace($externalBackup,''))"

    Copy-Item -Path $file.FullName -Destination $newFileName
}
 
It's a script, easiest way to run it would be to open Powershell ISE and copy the code into an empty .ps1 then hit the green arrow to run it. If you get an execution policy warning you can run the following in the blue section to temporary change the policy
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
 
If you are using a drive letter use
$externalBackup = "G:\" or whatever drive it is.

You can use drive letters instead of the UNC paths.
 
Sorry to be a pain but a test run on one file came back like this..
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    328.6 KB · Views: 347
You're on an old version of powershell which I don't think it's going to work with the script. Probably would have to re-write some of it to work on Win 7
 
Back
Top