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) -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 " } #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