Advertisement
kerbo_

MoE-backup.ps1

Dec 7th, 2021
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # A simple PowerShell script to backup Myth of Empires single player save file
  2. # Backups are stored in My Documents\MoEBackup
  3. # Twitter: @Kerbo_
  4. #
  5.  
  6. ###################################################
  7. # Change this to your Steam path to MoE SaveGames #
  8. $moeDir = "N:\SteamLibrary\steamapps\common\Myth of Empires\WindowsPrivateServer\MOE\Saved\SaveGames"
  9. ###################################################
  10.  
  11. $moeBackupDir = [Environment]::GetFolderPath("MyDocuments") + "\MoEBackup"
  12. $dateString = $(get-date -f yyy-MM-dd_HH-mm)
  13.  
  14. # Create backup directory if it doesn't exist
  15. New-Item -ItemType Directory -Force -Path $moeBackupDir | Out-Null
  16.  
  17. # Examine latest backup
  18. Push-Location $moeBackupDir
  19. $backup = gci SaveGames-* | select -last 1
  20. # New temp dir
  21. $parent = [System.IO.Path]::GetTempPath()
  22. [string] $name = [System.Guid]::NewGuid()
  23. $tempDir = New-Item -ItemType Directory -Path (Join-Path $parent $name)
  24. # Extract and get hash
  25. Expand-Archive -Path $backup -DestinationPath $tempDir
  26. $backup_hash = Get-FileHash $tempDir\World\LargeTerrain_Central_Main_100.sav
  27. # Remove temp dir
  28. Remove-Item -LiteralPath $tempDir -Force -Recurse
  29. Pop-Location
  30.  
  31. Push-Location $moeDir
  32. $current_hash = Get-FileHash World\LargeTerrain_Central_Main_100.sav
  33. if ( $backup_hash.Hash -eq $current_hash.Hash ) {
  34.     Write-Host "Save matches latest backup, no backup needed"
  35. } else {
  36.     Write-Host "Backing up to $moeBackupDir\SaveGames-$dateString.zip"
  37.     Compress-Archive -Path $moeDir\* -DestinationPath $moeBackupDir\SaveGames-$dateString.zip
  38.     Write-Host "Done"
  39. }
  40. Pop-Location
  41.  
  42. Start-Sleep -Seconds 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement