Example PowerShell script to perform a DR operation from a local directory data source to a Filespace mount-point. This particular scripting example can be adapted.
It relies on LucidLink client installed as a service with an unmounted mount-point and ensures it is only running once.
Once initiated, it mounts the Filespace to Z:, confirms the mount exists and performs a Robocopy from example path C:\Data to Z:\Data, awaits upload completion, syncs metadata and file data before unmounting.
Setup:
lucid service --install lucid service --start lucid link --fs <filespace.domain>
Schedule:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "dr_sync.ps1"
Script:
Function CheckRunning { [CmdletBinding()] Param ( [Parameter(Mandatory=$true)] [ValidateNotNullorEmpty()] [String]$ScriptName ) $PsScriptsRunning = get-wmiobject win32_process | where{$_.processname -eq 'powershell.exe'} | select-object commandline,ProcessId ForEach ($PsCmdLine in $PsScriptsRunning){ [Int32]$OtherPID = $PsCmdLine.ProcessId [String]$OtherCmdLine = $PsCmdLine.commandline If (($OtherCmdLine -match $ScriptName) -And ($OtherPID -ne $PID) ){ Write-host "[$ScriptName] already running" Start-Sleep -Second 5 Exit } } } function LLMount { Start-Process -WindowStyle hidden -FilePath "C:\Program Files\Lucid\Resources\Lucid.exe" -ArgumentList "mount --mount-point z:" } function DrPath { do { $Dr = "z:" $DrExists = Test-Path $Dr If ($DrExists -eq $False) {sleep 1} } until ($DrExists -eq $True) } function Backup { C:\Windows\System32\Robocopy.exe c:\data z:\data /Z /E /R:0 /W:0 /MIR /COPYALL /NP } function DirtyBytes { do { $dirtyBytes = (lucid perf --cache dirtyBytes --seconds 0 --no-timestamp) -replace '[^0-9]' #get dirtyBytes, reduce to number value If ($? -ne "True") {Break} #break do if invoke-restmethod errors sleep 1 #reduce CPU load } until ($dirtyBytes -eq 0) #exit when dirtyBytes=0 } function Sync { Start-Process -WindowStyle hidden -FilePath "C:\Program Files\Lucid\Resources\Lucid.exe" -ArgumentList "sync" -Wait } function Unmount { Start-Process -WindowStyle hidden -FilePath "C:\Program Files\Lucid\Resources\Lucid.exe" -ArgumentList "unmount" -Wait } function SnapshotDR { $time = (get-date).ToString('T') $time = $time -replace '[a-z,:]' Start-Process -WindowStyle hidden -FilePath "C:\Program Files\Lucid\Resources\Lucid.exe" -ArgumentList "snapshot --create $time --password <rootpassword>" } #Check if running $ScriptName = $MyInvocation.MyCommand.Name #Get name of current script CheckRunning -ScriptName $ScriptName #Mount LLMount #Await paths DrPath #Sync Sync #Backup Backup #Sync Sync #Cache flush DirtyBytes #Snapshot DR with basic timestamp #SnapshotDR #Unlink Unmount
optional: uncomment "SnapshotDR" function to snapshot the Filespace. you must provide your 'root' password. update <rootpassword> accordingly
- dr_sync.ps12 KB