kevinoffsite
New Member
- Joined
- Mar 21, 2017
- Messages
- 9
- Thread Author
-
- #1
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?
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?
Solution
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)
}
}...
- Joined
- Jul 4, 2015
- Messages
- 8,998
A simple powershell script could handle this
sudo code
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
kevinoffsite
New Member
- Joined
- Mar 21, 2017
- Messages
- 9
- Thread Author
-
- #3
Not super efficient with PS, and we are talking 2TB of data...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
- Joined
- Jul 4, 2015
- Messages
- 8,998
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
}
Solution
kevinoffsite
New Member
- Joined
- Mar 21, 2017
- Messages
- 9
- Thread Author
-
- #5
Ok.. I'll give it a try
kevinoffsite
New Member
- Joined
- Mar 21, 2017
- Messages
- 9
- Thread Author
-
- #6
Sorry dumb question, are these individual commands? Which ones are run together..
- Joined
- Jul 4, 2015
- Messages
- 8,998
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
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
kevinoffsite
New Member
- Joined
- Mar 21, 2017
- Messages
- 9
- Thread Author
-
- #8
Ok easy enough, so the script should compare copies and only add files that are missing correct?
kevinoffsite
New Member
- Joined
- Mar 21, 2017
- Messages
- 9
- Thread Author
-
- #9
Is the command for the external drive \\servername\drive letter\share?
kevinoffsite
New Member
- Joined
- Mar 21, 2017
- Messages
- 9
- Thread Author
-
- #10
In other words if the command is run from the share server c:\data\active would be my actual share on my server
kevinoffsite
New Member
- Joined
- Mar 21, 2017
- Messages
- 9
- Thread Author
-
- #12
ok
kevinoffsite
New Member
- Joined
- Mar 21, 2017
- Messages
- 9
- Thread Author
-
- #13
Similar threads
- Replies
- 0
- Views
- 131