lloesche / valheim-server-docker

Valheim dedicated gameserver with automatic update, World backup, BepInEx and ValheimPlus mod support
https://hub.docker.com/r/lloesche/valheim-server
Apache License 2.0
1.89k stars 269 forks source link

Restoring Backups in k8s #644

Open kubelize opened 9 months ago

kubelize commented 9 months ago

Using microk8s on Ubuntu 22.04.03 LTS Dockerimage version: latest / Digest:sha256:4e89eba8d2135ab5924ea65f551a06966a7cf34ea90e2e7434ecad6c0a21e2c0

I struggled for the last couple hours to restore a backup of a world save, These are the steps I took to restore: Using hostpath-storage navigate to the directory where the backups are stored.

cd /path/to/hostpath-storage/valheim-valheim-server-world-data-pvc-42f60004-5d4b-491c-a805-e53f53feeb54/backup
# delete worlds_local
sudo rm -r worlds_local

# copy the zip to world_local
sudo cp worlds-20230923-140004.zip ../

# unzip
sudo unzip worlds-20230923-140004.zip

# move the contents to the correct location
cd config
sudo mv * ../

# remove directory config 
sudo rm -r config

this results in following files:

ls -lah
-rw-r--r-- 1 root root 4.9M Sep 23 16:44 ThePromisedLand.db
-rw-r--r-- 1 root root 4.9M Sep 23 16:14 ThePromisedLand.db.old
-rw-r--r-- 1 root root   56 Sep 23 16:44 ThePromisedLand.fwl
-rw-r--r-- 1 root root   56 Sep 23 16:14 ThePromisedLand.fwl.old
-rw-r--r-- 1 root root 4.9M Sep 23 15:44 ThePromisedLand_backup_auto-20230923134438.db
-rw-r--r-- 1 root root   56 Sep 23 15:44 ThePromisedLand_backup_auto-20230923134438.fwl

The expected behavior now would be that when i restart the container, that the current .db and .fwl files will be used, instead on running k delete pod valheim-server-747d78876f-xrjlb the current .db and .fwl files are overwritten and turned into .db.old and .fwl.old and new save files are generated

I assume this is a result of the server creating backups every time it is shutdown. Deleting the pod/container with k delete causes the restored backups to be overwritten, thus we need to restart the server within the container without shutting it down.

This is how i solved the problem:

  1. Delete worlds_local
  2. Delete the Container k delete pod valheim-server-747d78876f-xrjlb
  3. Execute into the new container k exec -it valheim-server-633d78834f-cjjda -- bash
  4. There should be no worlds_local directory under /config
  5. Using supervisor stop the service "valeim-server": supervisorctl stop valheim-server
  6. From your backup.zip move the directory worlds_local to the hostpath-storage directory
  7. Start the service "valheim-server": supervisorctl start valheim-server

And that's it the server will correctly start using the restored backup

I turned off the backup functionality while troubleshooting so it wouldn't continuously create new backups of the new saves on every restart, this shouldnt be necessary by following the steps described above. But if you run into difficulties you might want to try it.

kubelize commented 9 months ago

Perhaps we could expand the Documentation to include how to restore a backup with the steps I described above?