Powershell Directory Sychronization

New Member
New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)
Group: Forum Members
Posts: 1, Visits: 4
I like the new Powershell script feature but....

I can't use the directory synchronization feature as it is implemented. This is NOT a complaint, I am just proposing an alternative solution that I will be using.

I back up three PCs to a 4TB NAS device and can retain 4 full sets of backups. I do a full backup on each PC once a week followed by 6 daily backups. In V 5.0 I used a VBScript to copy the latest file in the set to a second hard-drive in a USB mountable holder. This hard drive is cycled weekly and taken offsite for disaster recovery purposes. I rotate a set of three hard-drives, each 1.5TB in size. Each PC puts its backup images in seperate directories.

the default generated Powershell code uses Robocopy or XCopy to copy the entire contents of the backup directory to the alternate directory. In my case this would cause all 4 weeks of images to be copied to the second drive. This ust won't work because of capacity issues.

I altered the SynchroniseDirectories routine to only synchronize files in the current ImageID set. I borrowed the code used in GetLastBackupPath to get the IMAGEID from the registry. Then I modified the copy parameters to only synchronize file with the same prefix. Here is the revised routine.

#* Func: SynchroniseDirectories
#* Desc: Copies all Macrium Reflect files to a supplied directory.
function SynchroniseDirectories($strSrcDir, $strDstDir)
Write-Host ' * Synchronising directories... ' -NoNewLine;
$strRegPath = 'HKCU:\Volatile Environment';
$strName = 'MACRIUM_PREFIX';
$strPrefix = (Get-ItemProperty -Path $strRegPath -Name $strName -ErrorAction Stop).$strName;
$strName = $($strPrefix + '_IMAGEID');
$strImageID = (Get-ItemProperty -Path $strRegPath -Name $strName -ErrorAction Stop).$strName;
Write-Host ' ImageID ' + $strImageID + ' ..' -NoNewLine;

if (Get-Command robocopy -ErrorAction SilentlyContinue)
  # robocopy is available...
  # /copy:DATSO - D:Data
  #     A:Attributes
  #     T:Time stamps
  #     S:NTFS access control list (ACL)
  #     O:Owner information
  # /e    - Copies subdirectories (incl. empty)
  &robocopy $strSrcDir $strDstDir $strImageID*.mr* /copy:DATSO /e  /r:0 | Out-Null
  # Fall back to xcopy...
  # /c - Continues copying even if errors occur.
  # /d - Date check; only copies if file does not exist or is older.
  # /e - Copies any subfolder, even if it is empty.
  # /h - Copies hidden and system files.
  # /i - If the destination does not exist, and you are copying more than one
  #   file, this switch assumes that the destination is a folder.
  # /v - Verifies each new file.
  # /y - Overwrites existing files without prompting.
  &xcopy $strSrcDir\$strImageID*.mr* $strDstDir /c /d /e /h /i /v /y | Out-Null
Write-Host 'Done.';


Edited 23 February 2015 2:17 PM by CharlesG

Merge Selected

Merge into selected topic...

Merge into merge target...

Merge into a specific topic ID...

Reading This Topic