-
-
Notifications
You must be signed in to change notification settings - Fork 117
How to set automatic backups for Valheim Server World Data in Ubuntu
Zerobandwidth edited this page Sep 5, 2023
·
5 revisions
- Make backup startup files
sudo touch /usr/local/bin/valheimbackup && sudo chmod +x /usr/local/bin/valheimbackup
- Make backup directory in steam home folder called backups
sudo mkdir /home/steam/backups
- Edit backup file for Valheim
vi /usr/local/bin/valheimbackup
#!/bin/bash
## Get the current date as variable.
TODAY="$(date +%Y-%m-%d)"
## Clean up files older than 2 weeks. Create a new backup.
find /home/steam/backups/ -mtime +14 -type f -delete
## replace *yourWorldName* with your world name
systemctl stop valheimserver*yourWorldName*.service
#Wait for RAM to offload to .db and .db.old
#allows for the closing of the databases.
sleep 20
## replace *yourWorldName* with your world name
systemctl start valheimserver_*yourWorldName*.service
## Tar Section. Create a backup file, with the current date in its name.
## Add -h to convert the symbolic links into a regular files.
## Backup some system files, also the entire `/home` directory, etc.
## --exclude some directories, for example the the browser's cache, `.bash_history`, etc.
tar zcvf "/home/steam/backups/valheim-backup-$TODAY.tgz" /home/steam/.config/unity3d/IronGate/Valheim/(Your World Name)/*
chown steam:steam /home/steam/backups/valheim-backup-$TODAY.tgz
Conduct manual backup
type
valheimbackup
Now to set automatically.... which I dont know if this is bad or good but whatever... I would shutdown the server with nobody on it and then do the backup... I am unclear on the amount of possible data loss... or corrupter evil demons that can happen to server world data.... still testing... and playing around
Make a crontab:
This is for hourly backups
0 * * * * /usr/local/bin/valheimbackup > /var/log/valheimbackup-cron.log 2>&1
This is for nightly backups, if you want to increase or decrease time, research making crontabs....
15 1 * * * /usr/local/bin/valheimbackup > /var/log/valheimbackup-cron.log 2>&1
If you want more examples:
Add Windows Section Add Linux Section