Skip to content

Instantly share code, notes, and snippets.

@joeharrison714
Created July 7, 2017 00:17
Show Gist options
  • Save joeharrison714/86d0c0fde5080474194d24d6bbc03471 to your computer and use it in GitHub Desktop.
Save joeharrison714/86d0c0fde5080474194d24d6bbc03471 to your computer and use it in GitHub Desktop.
Script to backup Minecraft maps to Amazon S3 and render MapCrafter maps
$baseDir = "d:\minecraft-servers"
$backupDir = "$baseDir\backup"
$mapsOutput = "$baseDir\mapcrafter-output"
$awsProfileName = "minecraft-backup-script"
$s3BackupBucketName = "joeharrison-minecraft-backups"
$s3MapsBucketName = "minecraft.joeharrison.com"
$servers = @{}
$servers.Add("minecraft-creative","$baseDir\creative")
$servers.Add("minecraft-survival","$baseDir\survival")
function StopService($serviceName)
{
Write-Host "Getting service info for $serviceName"
$svc1 = Get-Service $serviceName
$state = $svc1.Status
Write-Host "Service Status: $state"
Write-Host "Attempting to stop $serviceName"
Stop-Service $serviceName
Write-Host "Waiting for service to stop"
$svc1.WaitForStatus('Stopped')
$state = $svc1.Status
Write-Host "Service Status: $state"
}
function BackupMap($serviceName, $serviceDir)
{
Write-Host "Zipping folder"
$zipPath = "$backupDir\$serviceName.zip"
Compress-Archive -Path $serviceDir -DestinationPath $zipPath -Force
Write-Host "Uploading to S3"
$s3Key = "backups/$serviceName.zip"
aws s3 cp $zipPath s3://$s3BackupBucketName/$s3Key --profile $awsProfileName
}
function StartService($serviceName)
{
Write-Host "Attempting to start $serviceName"
Start-Service $serviceName
}
function MapCrafter(){
cd "$baseDir"
.\mapcrafter\mapcrafter.exe -c render.conf -j 2
}
function UploadRedners(){
Write-Host "Uploading renders to S3"
aws s3 sync $baseDir\mapcrafter-output s3://$s3MapsBucketName --acl public-read --profile $awsProfileName
}
New-Item -ItemType Directory -Force -Path $backupDir
foreach ($h in $servers.GetEnumerator()) {
StopService $($h.Name)
}
Write-Host "Sleeping for a bit"
Start-Sleep -s 5
foreach ($h in $servers.GetEnumerator()) {
BackupMap $($h.Name) $($h.Value)
}
MapCrafter
foreach ($h in $servers.GetEnumerator()) {
StartService $($h.Name)
}
UploadRedners
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment