Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # A simple PowerShell script to backup Archean save files
- # Twitter: @Kerbo_
- #
- # EDIT TO SUIT YOUR INSTALL AND PREFERRED BACKUP LOCATION
- $archeanDir = "C:\Program Files (x86)\Steam\steamapps\common\Archean\Archean-data\server\worlds"
- $archeanBackupDir = "C:\savegames\Archean"
- # Keep this many backups
- $maxBackups = 10
- $dateString = $(get-date -f yyy-MM-dd_HH-mm)
- # Create backup directory if it doesn't exist
- New-Item -ItemType Directory -Force -Path $archeanBackupDir | Out-Null
- Push-Location $archeanDir
- $saves = Get-ChildItem -Directory
- foreach($save in $saves) {
- # Examine latest backup
- Push-Location $archeanBackupDir
- $backup = gci "$save-*" | select -last 1
- if (-not ([string]::IsNullOrEmpty($backup))) {
- # New temp dir
- $parent = [System.IO.Path]::GetTempPath()
- [string] $name = [System.Guid]::NewGuid()
- $tempDir = New-Item -ItemType Directory -Path (Join-Path $parent $name)
- # Extract and get hash
- Expand-Archive -Path $backup -DestinationPath $tempDir
- $backup_hash = Get-FileHash $tempDir\state.worldstate
- # Remove temp dir
- Remove-Item -LiteralPath $tempDir -Force -Recurse
- }
- Pop-Location
- if(Test-Path -Path "$save\state.worldstate" -PathType Leaf) {
- $current_hash = Get-FileHash "$save\state.worldstate"
- if ( $backup_hash.Hash -eq $current_hash.Hash ) {
- Write-Host "$save matches latest backup, no backup needed"
- } else {
- Write-Host "Backing up to $archeanBackupDir\$save-$dateString.zip"
- Compress-Archive -Path $save\* -DestinationPath "$archeanBackupDir\$save-$dateString.zip"
- }
- }
- # Keep only latest $maxBackups backups
- Push-Location $archeanBackupDir
- $c = Get-ChildItem "$save-*" | measure
- $count = $c.Count
- Write-Host "Using $count out of $maxBackups backups for $save"
- If($count -gt $maxBackups) {
- $delcount = $count - $maxBackups
- Write-Host "Cleaning up $delcount old backups for $save"
- Get-ChildItem "$save-*" -Recurse | sort CreationTime -desc | select -Skip $maxBackups | Remove-Item -Force
- }
- Pop-Location
- }
- Pop-Location
- Write-Host "Done"
- Start-Sleep -Seconds 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement