Skip to content

Commit

Permalink
feat: Custom backup and save only world (#250)
Browse files Browse the repository at this point in the history
* feat: Custom backup

* fix: Use of new backup system

* fix: Remove usage of sudo

* fix: Correct scriptDir

* fix: Correct deletion

* fix: Show log at console

* fix: Correct timestamp for backups

* fix: Update versions for actions

* docs: Update docs
  • Loading branch information
vinanrra authored Jul 1, 2024
1 parent 317509b commit d5816a2
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 113 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/docker-publish-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ jobs:
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3.0.0
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3.0.0
-
name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v3.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5.1.0
with:
push: true
tags: |
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ RUN dpkg --add-architecture i386 && \
distro-info \
git \
uuid-runtime \
pigz
pigz

# Install NodeJS
RUN curl -SLO https://deb.nodesource.com/nsolid_setup_deb.sh; \
Expand Down Expand Up @@ -87,14 +87,18 @@ RUN apt clean && \

#####Dependencies####

# Remove default user ubuntu
RUN deluser --remove-home ubuntu

# Create user and fix permissions - chown shouldn't be necessary check adduser command
RUN adduser --home /home/sdtdserver --disabled-password --shell /bin/bash --disabled-login --gecos "" sdtdserver \
&& chown -R sdtdserver:sdtdserver /home/sdtdserver

##Need use xterm for LinuxGSM##
ENV PUID=1000 PGID=1000 \
START_MODE=0 \
TEST_ALERT=no MONITOR=no BACKUP=no\
TEST_ALERT=no MONITOR=no \
BACKUP=no BACKUP_HOUR=5 BACKUP_MAX=7 \
VERSION=stable \
UPDATE_MODS=no \
ALLOC_FIXES=no ALLOC_FIXES_UPDATE=no \
Expand Down
11 changes: 4 additions & 7 deletions docs/backups.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@

# Backups

The backup command allows the creation of .tar.gz archives of a game server, alter these three settings by editing LinuxGSM Config
The backup command allows the creation of .tar.gz archives of the world of the server, alter these three settings by changing the following environments

* maxbackups
* maxbackupdays
* stoponbackup

Backups settings can be changed in */path/to/LGSM-Config/common.cfg*
* BACKUP_HOUR -> Must be 0-23
* BACKUP_MAX

If you wants to force a backup run this command:

```bash
docker-compose exec 7dtdserver ./sdtdserver backup
docker-compose exec 7dtdserver ./scripts/server_backup.sh
```
105 changes: 32 additions & 73 deletions docs/usage.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,6 @@
# Usage

Examples with all parameters supported

## Docker

```bash
docker run -d \
--name 7dtdserver \
--restart unless-stopped \
-v "/path/to/folder/7DaysToDie:/home/sdtdserver/.local/share/7DaysToDie/" \
-v "/path/to/folder/ServerFiles:/home/sdtdserver/serverfiles/" \
-v "/path/to/folder/LogFolder:/home/sdtdserver/log/" \
-v "/path/to/folder/BackupFolder:/home/sdtdserver/lgsm/backup/" \
-v "/path/to/folder/LGSM-Config:/home/sdtdserver/lgsm/config-lgsm/sdtdserver/" \
-p 26900:26900/tcp \
-p 26900:26900/udp \
-p 26901:26901/udp \
-p 26902:26902/udp \
-p 8080:8080/tcp \
-p 8081:8081/tcp \
-p 8082:8082/tcp \
-e START_MODE=1 \
-e VERSION=stable \
-e TEST_ALERT=NO \
-e UPDATE_MODS=NO \
-e MODS_URLS="" \
-e ALLOC_FIXES=NO \
-e ALLOC_FIXES_UPDATE=NO \
-e UNDEAD_LEGACY=NO \
-e UNDEAD_LEGACY_VERSION=stable \
-e DARKNESS_FALLS=NO \
-e DARKNESS_FALLS_UPDATE=NO \
-e DARKNESS_FALLS_URL=False \
-e UNDEAD_LEGACY_UPDATE=NO \
-e CPM=NO \
-e CPM_UPDATE=NO \
-e BEPINEX=NO \
-e BEPINEX_UPDATE=NO \
-e BACKUP=NO \
-e MONITOR=NO \
-e PUID=1000 \
-e PGID=1000 \
-e TimeZone=Europe/Madrid \
vinanrra/7dtd-server
```
Example with all parameters supported

## docker-compose

Expand All @@ -54,41 +11,43 @@ services:
image: vinanrra/7dtd-server
container_name: 7dtdserver
environment:
- START_MODE=1 #Change between START MODES
- VERSION=stable # Change between 7 days to die versions
- PUID=1000 # Remember to use same as your user
- PGID=1000 # Remember to use same as your user
- TimeZone=Europe/Madrid # Optional - Change Timezone
- TEST_ALERT=NO # Optional - Send a test alert
- UPDATE_MODS=NO # Optional - This will allow mods to be update on start, each mod also need to have XXXX_UPDATE=YES to update on start
- MODS_URLS="" # Optional - Mods urls to install, must be ZIP or RAR.
- ALLOC_FIXES=NO # Optional - Install ALLOC FIXES
- ALLOC_FIXES_UPDATE=NO # Optional - Update Allocs Fixes before server start
- UNDEAD_LEGACY=NO # Optional - Install Undead Legacy mod, if DARKNESS_FALLS it's enable will not install anything
- START_MODE=1 # Change between START MODES
- VERSION=stable # Change between 7 days to die versions
- PUID=1000 # Remember to use same as your user
- PGID=1000 # Remember to use same as your user
- TimeZone=Europe/Madrid # Optional - Change Timezone
- TEST_ALERT=NO # Optional - Send a test alert
- UPDATE_MODS=NO # Optional - This will allow mods to be update on start, each mod also need to have XXXX_UPDATE=YES to update on start
- MODS_URLS="" # Optional - Mods urls to install, must be ZIP or RAR.
- ALLOC_FIXES=NO # Optional - Install ALLOC FIXES
- ALLOC_FIXES_UPDATE=NO # Optional - Update Allocs Fixes before server start
- UNDEAD_LEGACY=NO # Optional - Install Undead Legacy mod, if DARKNESS_FALLS it's enable will not install anything
- UNDEAD_LEGACY_VERSION=stable # Optional - Undead Legacy version
- UNDEAD_LEGACY_UPDATE=NO # Optional - Update Undead Legacy mod before server start
- DARKNESS_FALLS=NO # Optional - Install Darkness Falls mod, if UNDEAD_LEGACY it's enable will not install anything
- DARKNESS_FALLS_UPDATE=NO # Optional - Update Darkness Falls mod before server start
- DARKNESS_FALLS_URL=False # Optional - Install the provided Darkness Falls url
- CPM=NO # Optional - CSMM Patron's Mod (CPM)
- CPM_UPDATE=NO # Optional - Update CPM before server start
- BEPINEX=NO # Optional - BepInEx
- BEPINEX_UPDATE=NO # Optional - Update BepInEx before server start
- BACKUP=NO # Optional - Backup server at 5 AM
- MONITOR=NO # Optional - Keeps server up if crash
- UNDEAD_LEGACY_UPDATE=NO # Optional - Update Undead Legacy mod before server start
- DARKNESS_FALLS=NO # Optional - Install Darkness Falls mod, if UNDEAD_LEGACY it's enable will not install anything
- DARKNESS_FALLS_UPDATE=NO # Optional - Update Darkness Falls mod before server start
- DARKNESS_FALLS_URL=False # Optional - Install the provided Darkness Falls url
- CPM=NO # Optional - CSMM Patron's Mod (CPM)
- CPM_UPDATE=NO # Optional - Update CPM before server start
- BEPINEX=NO # Optional - BepInEx
- BEPINEX_UPDATE=NO # Optional - Update BepInEx before server start
- BACKUP=NO # Optional - Backup server
- BACKUP_HOUR=5 # Optional - Backup hour 0-23
- BACKUP_MAX=7 # Optional - Max backups to keep
- MONITOR=NO # Optional - Keeps server up if crash
volumes:
- /path/to/folder/7DaysToDie:/home/sdtdserver/.local/share/7DaysToDie/
- /path/to/folder/LGSM-Config:/home/sdtdserver/lgsm/config-lgsm/sdtdserver
- /path/to/folder/ServerFiles:/home/sdtdserver/serverfiles/ # Optional - serverfiles folder
- /path/to/folder/log:/home/sdtdserver/log/ # Optional - Logs folder
- /path/to/folder/backups:/home/sdtdserver/lgsm/backup/ # Optional - If BACKUP=NO, backups folder
- /path/to/folder/7DaysToDie:/home/sdtdserver/.local/share/7DaysToDie/ # 7 Days To Die world saves
- /path/to/folder/LGSM-Config:/home/sdtdserver/lgsm/config-lgsm/sdtdserver # LGSM config folder
- /path/to/folder/ServerFiles:/home/sdtdserver/serverfiles/ # Optional - serverfiles folder
- /path/to/folder/log:/home/sdtdserver/log/ # Optional - Logs folder
- /path/to/folder/backups:/home/sdtdserver/lgsm/backup/ # Optional - If BACKUP=NO, backups folder
ports:
- 26900:26900/tcp # Default game ports
- 26900:26900/udp # Default game ports
- 26901:26901/udp # Default game ports
- 26902:26902/udp # Default game ports
- 8080:8080/tcp # OPTIONAL - WEBADMIN
- 8081:8081/tcp # OPTIONAL - TELNET
- 8082:8082/tcp # OPTIONAL - WEBSERVER https://7dtd.illy.bz/wiki/Server%20fixes
- 8080:8080/tcp # OPTIONAL - WEBADMIN
- 8081:8081/tcp # OPTIONAL - TELNET
- 8082:8082/tcp # OPTIONAL - WEBSERVER https://7dtd.illy.bz/wiki/Server%20fixes
restart: unless-stopped # INFO - NEVER USE WITH START_MODE=4 or START_MODE=0
```
23 changes: 1 addition & 22 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,6 @@ test_alert () {
fi
}

crontab_func (){
# Crontab
echo "# Crontab file" > crontab.txt

if [ "${BACKUP,,}" == 'yes' ]; then
source "$scriptsDir/crontab/backup.sh"
fi

if [ "${MONITOR,,}" == 'yes' ]; then
source "$scriptsDir/crontab/monitor.sh"
fi

echo "# Don't remove the empty line at the end of this file. It is required to run the cron job" >> crontab.txt

# Add crontab
crontab crontab.txt

# Cleanup junk file
rm crontab.txt
}

# Check requeriments

# Check if script is missing
Expand All @@ -57,7 +36,7 @@ if [ -f serverfiles/MOD_BLOCK.txt ] ; then
rm serverfiles/MOD_BLOCK.txt
fi

crontab_func
source "$scriptsDir/utils/crontab.sh"

# Use of case to avoid errors if used wrong START_MODE
case $START_MODE in
Expand Down
4 changes: 2 additions & 2 deletions scripts/crontab/backup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
echo "0 5 * * * /home/sdtdserver/sdtdserver backup > /dev/null 2>&1" >> crontab.txt
echo "0 $BACKUP_HOUR * * * /home/sdtdserver/scripts/server_backup.sh >> /home/sdtdserver/log/sdtdserver-console.log 2>&1" >> crontab.txt

echo "[INFO] Activated automatic backup at 5AM"
echo "[INFO] Activated automatic backup at $BACKUP_HOUR"
29 changes: 26 additions & 3 deletions scripts/server_backup.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
#!/bin/bash
echo "[INFO] Starting backup, this backup will create a complete tar bzip2 archive of the whole server"

echo "[INFO] Starting backup, this backup will create a backup in a .tar.gz archive of your worlds"
sleep 3s

./sdtdserver backup
BACKUP_FOLDER="/home/sdtdserver/.local/share/7DaysToDie/"
BACKUP_DESTINATION="/home/sdtdserver/lgsm/backup/"
scriptsDir="/home/sdtdserver/scripts"

echo "Stopping 7 Days To Die"
./sdtdserver stop

# Disable crontab and montoring if enabled
crontab -r

# Backup the specified folder
echo "Backing up folder: $BACKUP_FOLDER"
TIMESTAMP=$(date +"%Y-%m-%d-%H%M%S")
BACKUP_FILE="$BACKUP_DESTINATION/sdtdserver-$TIMESTAMP.tar.gz"
tar -czvf $BACKUP_FILE $BACKUP_FOLDER

# Enable crontab and monitoring
source "$scriptsDir/utils/crontab.sh"

echo "Starting 7 Days To Die"
./sdtdserver start

echo "Backup completed. Backup file: $BACKUP_FILE"

sleep 3s

echo "[INFO] Backup complete"

find "$BACKUP_DESTINATION" -type f -name "*.tar.gz" -mtime +7 -delete
19 changes: 19 additions & 0 deletions scripts/utils/crontab.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
scriptsDir="/home/sdtdserver/scripts"

echo "# Crontab file" > crontab.txt

if [ "${BACKUP,,}" == 'yes' ]; then
source "$scriptsDir/crontab/backup.sh"
fi

if [ "${MONITOR,,}" == 'yes' ]; then
source "$scriptsDir/crontab/monitor.sh"
fi

echo "# Don't remove the empty line at the end of this file. It is required to run the cron job" >> crontab.txt

# Add crontab
crontab crontab.txt

# Cleanup junk file
rm crontab.txt

0 comments on commit d5816a2

Please sign in to comment.