Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # A simple PowerShell script to backup Out of Ore saves
- # Twitter: @Kerbo_
- #
- $ErrorActionPreference = 'SilentlyContinue'
- $oooDir = $env:LOCALAPPDATA + "\OutOfOre\Saved\SaveGames"
- $dateString = $(get-date -f yyy-MM-dd_HH-mm)
- Push-Location $oooDir
- If(!(test-path -PathType container "backups"))
- {
- New-Item -ItemType Directory -Path "backups" | Out-Null
- }
- $saves = Get-ChildItem -Filter *.sav
- foreach($save in $saves) {
- $savename = $save.Name
- $basename = $save.BaseName
- if($savename -Match ".*-[0-9]{4}-[0-9]{2}-[0-9]{2}") { continue }
- $save_hash = Get-FileHash $save
- $backup = gci "backups\$basename-*" | select -last 1
- $backup_hash = Get-FileHash $backup -EV Err -EA SilentlyContinue
- if ( $backup_hash.Hash -eq $save_hash.Hash ) {
- Write-Host "$savename matches latest backup, no backup needed" -ForegroundColor green
- } else {
- cp $savename "backups\$basename-$dateString.sav"
- $RET=$?
- if ($RET) {
- Write-Host "Copied $basename.sav to backups\$basename-$dateString.sav" -ForegroundColor yellow
- } else {
- Write-Host "Error! cp returned $RET for $basename.sav" -ForegroundColor red
- }
- }
- }
- Pop-Location
- # Sleep to show screen output before exiting
- Start-Sleep -Seconds 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement