Advertisement
kerbo_

OutOfOre-backup.ps1

Jul 15th, 2023 (edited)
2,181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # A simple PowerShell script to backup Out of Ore saves
  2. # Twitter: @Kerbo_
  3. #
  4. $ErrorActionPreference = 'SilentlyContinue'
  5. $oooDir = $env:LOCALAPPDATA + "\OutOfOre\Saved\SaveGames"
  6. $dateString = $(get-date -f yyy-MM-dd_HH-mm)
  7. Push-Location $oooDir
  8.  
  9. If(!(test-path -PathType container "backups"))
  10. {
  11.       New-Item -ItemType Directory -Path "backups" | Out-Null
  12. }
  13.  
  14. $saves = Get-ChildItem -Filter *.sav
  15.  
  16. foreach($save in $saves) {
  17.     $savename = $save.Name
  18.     $basename = $save.BaseName
  19.    
  20.     if($savename -Match ".*-[0-9]{4}-[0-9]{2}-[0-9]{2}") { continue }
  21.    
  22.     $save_hash = Get-FileHash $save
  23.     $backup = gci "backups\$basename-*" | select -last 1
  24.     $backup_hash = Get-FileHash $backup -EV Err -EA SilentlyContinue
  25.     if ( $backup_hash.Hash -eq $save_hash.Hash ) {
  26.         Write-Host "$savename matches latest backup, no backup needed" -ForegroundColor green
  27.     } else {
  28.         cp $savename "backups\$basename-$dateString.sav"
  29.         $RET=$?
  30.         if ($RET) {
  31.             Write-Host "Copied $basename.sav to backups\$basename-$dateString.sav" -ForegroundColor yellow
  32.         } else {
  33.             Write-Host "Error! cp returned $RET for $basename.sav" -ForegroundColor red
  34.         }
  35.     }
  36. }
  37. Pop-Location
  38. # Sleep to show screen output before exiting
  39. Start-Sleep -Seconds 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement