Posted On January 20, 2020

PowerShell: Hobocopy Backup Software

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Hobocopy Backup Software
# hobocopy-backup.ps1
# Note: this is a quick snippet to demonstrate the use of this utility.
# The good: this software can backup locked/open files using VSS, and its speed is impressive.
# The bad: "incremental" copy does not regenerate files that have been deleted at the destination


# Input variables
$source="C:\temp"
$destination="C:\tempcopy"
$logFolder="C:\logs"

# Autogen variables
$logFile="$logFolder\hobocopy-log-$(get-date -Format 'yyyy-MM-dd-hh-mm-ss').log"
$stateFile="$logFolder\hobocopy-statefile.log"
$hobocopyFullSwitches="/statefile=$stateFile /ignorepattern='System Volume Information|\$RECYCLE.BIN' /full /skipdenied /r /y"
$hobocopyIncrementalSwitches="/statefile=$stateFile /ignorepattern='System Volume Information|\$RECYCLE.BIN' /incremental /skipdenied /r /y"

# Include prerequisites
.{
if (!(get-command hobocopy)){
if (!(Get-Command choco.exe -ErrorAction SilentlyContinue)) {
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
}
choco install hobocopy -y;
}
}

if (test-path $stateFile){
$hobocopyCommand="hobocopy $source $destination $hobocopyIncrementalSwitches"
}else{
$hobocopyCommand="hobocopy $source $destination $hobocopyFullSwitches"
}
$output=invoke-expression $hobocopyCommand;

write-host $output
Add-Content $logFile $output;

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

How To Modify a Windows Service

Here's the freebie code: # Version 0.02 $serviceName='Windows_Exporter' $newExePath=$false $newSwitches=" --log.format logger:eventlog?name=$serviceName --collectors.enabled os,cpu,cs,logical_disk,net,tcp,service,textfile" function…

PowerShell: Snippet to Detect and Disconnect Active PS Sessions

# Manual DetectionPS C:\Windows\system32> get-pssession Id Name ComputerName ComputerType State ConfigurationName Availability -- ---- ------------…

PowerShell: Quickly Test Connectivity from a List of Sources toward a Destination on a Specific Port

# testRemotePort.ps1 $connectFrom=@' windows1 windows2 '@ $connectTo=@' \\servername\sharename '@ $testPort=445 $sources=@($connectFrom -split "`n")|%{$_.Trim()} $destinations=@($connectTo -split…