Advertisement
kerbo_

RROnline-backup.ps1

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