Search This Blog

Showing posts with label Minecraft. Show all posts
Showing posts with label Minecraft. Show all posts

Wednesday, May 1, 2024

PowerShell: Managing your Minecraft Server

My Minecraft server is running on a separate computer, simply to offset the resource requirements to a separate device.

When managing this server I use RDP to access the GUI and while on the management server I have simplified the management through some PowerShell scripts.

Here are the general outline of the scripts I have connected at this stage.

Currently in development:

Minecraft server start, a script that checks if the .exe is existing and if the process is running. If .exe exists but the process is not running, it starts the process.

Minecraft server stop, basically the reverse. It checks if the process is running, and if so, it issues a stop command to the server.

Minecraft server upgrade, this script is more advanced. It brings home the latest version (at this point hardcoded) and then performs a replacement action, making sure the properties and the world is not lost. Finally it inserts the backed up files again. Lastly it performs cleanup.

Scripts that are tried and tested:

Minecraft diagnostics, a script that performs a general health check. Are all files presents? Is the process running? What is the size of the Minecraft folder?

Minecraft backup, stops the server process, performs copies of the properties and the world, places them on a separate drive and then starts the process again. This is a vital component, because you need a regular backup and in theory you could add this to a schedule and include cleanup functionality.


Future script ideas:

Another project I am considering is a restore script, that combines functions from the backup, diagnostic and the upgrade, basically a script that checks for damage to the folder and perhaps compares with a baseline. Then perform basic replacement and cleanup actions to restore the folder to the best of its ability.

You can also use compare-object to check the contents of the properties for example, to check for corruption.

Last but not least, perhaps there is a way to perform a hashing fingerprint of the world.

Sunday, March 10, 2024

PowerShell: File backup script

This simple script allows you to backup a chosen folder to a set destination.

This script contains the main engine so to speak, but you can build further using this as a base. Some suggestions might be to add failsafe features or a GUI.

You can also add options to delete/manage existing backups as they exists as simple .zip-files.
Another option you might want to look into is how to revert to an older backup.

I used this script for backing up my Minecraft world, on my MC server. Basically I customized the base script to stop the bedrock_server service as well, as it was blocking the compression. Then it saved the world as a .zip file on a separate disk. This script checks if there was a backup already made today, but of course you can change this to perhaps create a more granular filename to avoid collisions 

Param(

  [string]$Path = 'C:\Temp\App',

  [string]$DestinationPath = 'D:\Backup\'

)

If (-Not (Test-Path $Path)) 

{

  Throw "The source directory $Path does not exist, please specify an existing directory"

}

$date = Get-Date -format "yyyy-MM-dd"

$DestinationFile = "$($DestinationPath + 'backup-' + $date + '.zip')"

If (-Not (Test-Path $DestinationFile)) 

{

  Compress-Archive -Path $Path -CompressionLevel 'Fastest' -DestinationPath "$($DestinationPath + 'backup-' + $date)"

  Write-Host "Created backup at $($DestinationPath + 'backup-' + $date + '.zip')"

} Else {

  Write-Error "Today's backup already exists"

}

Friday, January 19, 2024

Windows 11: Hosting a Minecraft Bedrock server

This post will cover various steps to get a Minecraft server running on Windows 11.

For my experiment I was running it on an old laptop with x64 processor, it can also run bedrock server on the ARM-architecture and Ubuntu Server. For the sake of this post we will in other words just assume that you are running Win 11 and want to install the Bedrock server.

Prerequisites

I downloaded the server first and noticed that I was missing the Visual C++ Redistributable.
So my recommendation is to download both.



Once both are installed you need extract the bedrock zip-file as well, and place the extracted folder in a place that you are familiar with. I created a C:\Minecraft\ folder in which I placed it.

Configuring your server

As I already have a world on another computer, I wanted to transfer this world and keep it on the server instead.

To find your world, go to %localappdata% then go to 

...\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang\minecraftWorlds

Within this directory each world has its own folder. Move this folder to your server computer.
You will have configuration file in your bedrock server folder in which you can point towards this world.

Getting your server online and available

If you don't make any changes and just run the bedrock_server.exe right of the bat, it becomes instantly available in the Minecraft client on another computer on the same network. Basically it is considered a LAN server and it is not available online for others to join.

Joining the server

To join the server on regular LAN, just open your Minecraft Bedrock client on the computer you intend to play from and make sure you are on the same network. Then you should find the world in the "server" section in the game.