
10 changed files with 190 additions and 2 deletions
@ -0,0 +1,48 @@ |
|||
#!/bin/bash |
|||
|
|||
rm_ife() { |
|||
if [[ -e "$1" ]]; then |
|||
rm -r "$1" |
|||
fi |
|||
} |
|||
|
|||
# Check if server is started |
|||
status=$(systemctl show valheim -p ActiveState --value) |
|||
if [[ $status != active ]]; then |
|||
echo "valheim.service is inactive. Exiting." |
|||
exit 1 |
|||
fi |
|||
|
|||
# get time |
|||
hour=$(date +%H) |
|||
day=$(date +%d) |
|||
month=$(date +%m) |
|||
year=$(date +%Y) |
|||
|
|||
# hour at which to do daily tasks |
|||
dailyhour=4 |
|||
|
|||
# cd to backup dir |
|||
cd /vol/data/backup |
|||
|
|||
if [[ 10#$hour -eq $dailyhour ]]; then |
|||
systemctl stop valheim |
|||
sleep 1 |
|||
fi |
|||
|
|||
# hourly backup |
|||
rm_ife worlds-hourly-$hour |
|||
vh-backup worlds-hourly-$hour |
|||
|
|||
if [[ 10#$hour -eq $dailyhour ]]; then |
|||
systemctl start valheim |
|||
|
|||
# save daily and longterm backups |
|||
rm_ife worlds-daily-$day.zip |
|||
zip -rT worlds-daily-$day.zip worlds-hourly-$hour |
|||
chown "$(stat -c '%U:%G' worlds-hourly-$hour)" worlds-daily-$day.zip |
|||
touch -d "$(stat -c '%y' worlds-hourly-$hour)" worlds-daily-$day.zip |
|||
if [[ 10#$day -eq 1 ]]; then |
|||
cp -a worlds-daily-$day.zip worlds-$year-$month-$day.zip |
|||
fi |
|||
fi |
@ -0,0 +1,2 @@ |
|||
#!/bin/sh |
|||
sudo -u vhadmin /usr/games/steamcmd "$@" |
@ -0,0 +1,20 @@ |
|||
#!/bin/bash |
|||
|
|||
worlds_dir="/home/vhadmin/.config/unity3d/IronGate/Valheim/worlds" |
|||
|
|||
if [[ -z $1 ]]; then |
|||
echo "Usage: $0 backup_dir" |
|||
exit 2 |
|||
fi |
|||
backup_dir="$1" |
|||
|
|||
# Check if backup dir already exists |
|||
if [[ -e "$backup_dir" ]]; then |
|||
echo "Error: backup dir already exists. Delete directory before proceeding or use another directory name." |
|||
exit 1 |
|||
fi |
|||
echo "Creating directory \"$backup_dir\"..." |
|||
mkdir -p "$backup_dir" |
|||
|
|||
# copy files |
|||
rsync -aSH $worlds_dir/ "$backup_dir/" |
@ -0,0 +1,2 @@ |
|||
#!/bin/bash |
|||
steamcmd +login anonymous +force_install_dir /home/vhadmin/ +app_update 896660 validate +exit |
@ -0,0 +1,49 @@ |
|||
#!/bin/bash |
|||
|
|||
worlds_dir="/home/vhadmin/.config/unity3d/IronGate/Valheim/worlds" |
|||
|
|||
if [[ -z $1 ]]; then |
|||
echo "Usage: $0 backup_dir" |
|||
exit 2 |
|||
fi |
|||
backup_dir="$1" |
|||
|
|||
# Check if directory exists |
|||
if [[ ! -d "$backup_dir" ]]; then |
|||
echo "Error: directory \"$backup_dir\" not found." |
|||
exit 1 |
|||
fi |
|||
|
|||
# Check if server is active |
|||
status=$(systemctl show valheim -p ActiveState --value) |
|||
# shutdown server if it is active |
|||
if [[ $status == active ]]; then |
|||
echo "Server is active: executing shutdown..." |
|||
systemctl stop valheim |
|||
sleep 1 |
|||
fi |
|||
|
|||
worlds_dir=/home/mcadmin/worlds |
|||
# if worlds dir is non-empty, save it as worlds.bak |
|||
if [[ ! -z $(ls $worlds_dir) ]]; then |
|||
echo "Worlds directory is nonempty: saving backup as $worlds_dir.bak" |
|||
if [[ -e $worlds_dir.bak ]]; then |
|||
rm -r $worlds_dir.bak |
|||
fi |
|||
mv $worlds_dir $worlds_dir.bak |
|||
mkdir $worlds_dir |
|||
chown $(stat -c %U:%G $worlds_dir.bak) $worlds_dir |
|||
fi |
|||
|
|||
# copy backup to worlds_dir |
|||
echo "Copying worlds from backup directory..." |
|||
rsync -aSH "$backup_dir/" $worlds_dir/ |
|||
|
|||
# start server back up if it was active |
|||
if [[ $status == active ]]; then |
|||
echo "Server was active: starting server again..." |
|||
systemctl start valheim |
|||
sleep 5 |
|||
fi |
|||
|
|||
echo "Done!" |
@ -0,0 +1,15 @@ |
|||
#!/bin/bash |
|||
export templdpath=$LD_LIBRARY_PATH |
|||
export LD_LIBRARY_PATH=./linux64:$LD_LIBRARY_PATH |
|||
export SteamAppId=892970 |
|||
|
|||
echo "Starting server" |
|||
|
|||
# Load Config |
|||
. /vol/data/config |
|||
|
|||
# NOTE: Minimum password length is 5 characters & Password cant be in the server name. |
|||
# NOTE: You need to make sure the ports 2456-2458 is being forwarded to your server through your local router & firewall. |
|||
./valheim_server.x86_64 -name "$vh_name" -port 2456 -world "$vh_world" -password "$vh_pass" |
|||
|
|||
export LD_LIBRARY_PATH=$templdpath |
@ -0,0 +1,25 @@ |
|||
[Unit] |
|||
# Implicit needs are explicitly needed to survive shutdown till stop finishes |
|||
After=network.target |
|||
Description=Valheim server |
|||
|
|||
[Service] |
|||
ExecStart=/usr/local/bin/vh-start |
|||
ExecReload=/bin/kill -s HUP $MAINPID |
|||
KillSignal=SIGINT |
|||
User=vhadmin |
|||
WorkingDirectory=/home/vhadmin |
|||
Restart=on-failure |
|||
StandardOutput=journal |
|||
StandardError=journal |
|||
Type=simple |
|||
# security |
|||
PrivateUsers=true |
|||
ProtectHome=true |
|||
ProtectControlGroups=true |
|||
ProtectKernelModules=true |
|||
ProtectKernelTunables=true |
|||
ProtectSystem=full |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,11 @@ |
|||
[Unit] |
|||
After=valheim.service |
|||
Description=Valheim Server Auto-backup |
|||
Requisite=valheim.service |
|||
|
|||
[Service] |
|||
ExecStart=/usr/local/bin/maint |
|||
StandardOutput=journal |
|||
StandardError=journal |
|||
KillMode=none |
|||
Type=oneshot |
@ -0,0 +1,8 @@ |
|||
[Unit] |
|||
Description=Backup Valheim Server every hour |
|||
|
|||
[Timer] |
|||
OnCalendar=0/1:00:00 |
|||
|
|||
[Install] |
|||
WantedBy=timers.target |
Loading…
Reference in new issue