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 Link { Start-Process -WindowStyle hidden -FilePath "C:\Program Files\Lucid\Resources\Lucid.exe" -ArgumentList "--instance 1 daemon --fs --user root --password --mount-point c:\prod" Start-Process -WindowStyle hidden -FilePath "C:\Program Files\Lucid\Resources\Lucid.exe" -ArgumentList "--instance 2 daemon --fs --user root --password --mount-point c:\dr" } function ProdPath { do { $prod = "c:\prod" $ProdExists = Test-Path $prod If ($ProdExists -eq $False) {sleep 1} } until ($ProdExists -eq $True) } function BkupPath { do { $bkup = "c:\dr" $BkupExists = Test-Path $bkup If ($BkupExists -eq $False) {sleep 1} } until ($BkupExists -eq $True) } function Backup { C:\Windows\System32\Robocopy.exe c:\prod c:\dr /Z /E /R:0 /W:0 /MIR /COPYALL /NP } function Instance1 { do { $dirtyBytes = (lucid --instance 1 perf --cache dirtyBytes --seconds 0) -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 Instance2 { do { $dirtyBytes = (lucid --instance 2 perf --cache dirtyBytes --seconds 0) -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 "--instance 1 sync" -Wait Start-Process -WindowStyle hidden -FilePath "C:\Program Files\Lucid\Resources\Lucid.exe" -ArgumentList "--instance 2 sync" -Wait } function Unlink { Start-Process -WindowStyle hidden -FilePath "C:\Program Files\Lucid\Resources\Lucid.exe" -ArgumentList "--instance 1 unlink" -Wait Start-Process -WindowStyle hidden -FilePath "C:\Program Files\Lucid\Resources\Lucid.exe" -ArgumentList "--instance 2 unlink" -Wait } function LLExit { Start-Process -WindowStyle hidden -FilePath "C:\Program Files\Lucid\Resources\Lucid.exe" -ArgumentList "--instance 1 exit" -Wait Start-Process -WindowStyle hidden -FilePath "C:\Program Files\Lucid\Resources\Lucid.exe" -ArgumentList "--instance 2 exit" -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 "--instance 2 snapshot --create $time --password " } #Check if running $ScriptName = $MyInvocation.MyCommand.Name #Get name of current script CheckRunning -ScriptName $ScriptName #Link Link #Await paths ProdPath BkupPath #Sync Sync #Backup Backup #Sync Sync #Cache flush Instance1 Instance2 #Snapshot DR with basic timestamp #SnapshotDR #Unlink Unlink #Exit LucidLink LLExit