Created
June 2, 2019 06:55
-
-
Save jlucktay/16b1fb0645cda175817049b5bcdda584 to your computer and use it in GitHub Desktop.
Back up your Factorio blueprints to Google Cloud Storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference = "Stop" | |
Set-StrictMode -Version Latest | |
$KeepOldRemotes = 10 | |
$SleepIntervalSeconds = 180 | |
$TargetBucket = "jlucktay-factorio-eur4" | |
while ($true) { | |
$Timestamp = Get-Date -Format FileDateTimeUniversal | |
# Compress local file to temp directory | |
$CompressSplat = @{ | |
DestinationPath = "${env:TEMP}\blueprint-storage.dat.${Timestamp}.zip" | |
Path = Join-Path -Path $env:APPDATA -ChildPath "Factorio\blueprint-storage.dat" | |
Verbose = $true | |
} | |
Compress-Archive @CompressSplat | |
# Copy compressed file to Google Cloud Storage | |
$CopySplat = @{ | |
Bucket = $TargetBucket | |
File = $CompressSplat.DestinationPath | |
Verbose = $true | |
} | |
New-GcsObject @CopySplat | |
# Clean up local temporary archive | |
Remove-Item -Path $CopySplat.File -Verbose | |
# Prune old remote file(s) | |
Get-GcsObject -Bucket $TargetBucket | | |
Where-Object { $_.Name -match "^blueprint-storage.dat.*.zip$" } | | |
Sort-Object -Property Name -Descending | | |
Select-Object -Skip $KeepOldRemotes | | |
Remove-GcsObject -Verbose | |
Start-Sleep -Seconds $SleepIntervalSeconds | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment