Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # A simple PowerShell script to backup Railroads Online! saves
- # Twitter: @Kerbo_
- #
- $ErrorActionPreference = 'SilentlyContinue'
- $rronlineDir = $env:LOCALAPPDATA + "\arr\Saved\SaveGames"
- $dateString = $(get-date -f yyy-MM-dd_HH-mm)
- Push-Location $rronlineDir
- If(!(test-path -PathType container "backups"))
- {
- New-Item -ItemType Directory -Path "backups" | Out-Null
- }
- $ignore = "GraphicsOptions.sav", "Options.sav", "settings.sav", "AudioOptions.sav"
- $saves = Get-ChildItem -Filter *.sav
- foreach($save in $saves) {
- $savename = $save.Name
- $basename = $save.BaseName
- if($ignore.Contains($savename)) { continue }
- if($savename -Like "AUTOSAVE_*") { continue }
- 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