Skip to content

Commit

Permalink
fix: Use of new backup system
Browse files Browse the repository at this point in the history
  • Loading branch information
vinanrra committed Jun 29, 2024
1 parent bcfb39c commit 80de1be
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
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 sudo 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
```
2 changes: 1 addition & 1 deletion 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 > /dev/null 2>&1" >> crontab.txt

echo "[INFO] Activated automatic backup at 5AM"
23 changes: 23 additions & 0 deletions scripts/server_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,26 @@ echo "Backup completed. Backup file: $BACKUP_FILE"
sleep 3s

echo "[INFO] Backup complete"

# Find all .tar.gz files in the backup directory
backups=( "$BACKUP_DESTINATION"/*.tar.gz )

if [[ ${#backups[@]} -eq 0 ]]; then
echo "No backup files found in $BACKUP_DESTINATION"
exit 0
fi

# Sort backups by modification time (newest first)
shopt -s nullglob # Allow sorting empty arrays
backups=($(sort -r --key='{}' <<< "${backups[@]}")) # Double quotes for filenames with spaces

# Keep only the most recent 7 backups
backups_to_keep=("${backups[@]:0:$BACKUP_MAX}")

# Delete remaining backups
for backup in "${backups[@]:$BACKUP_MAX}"; do
rm -f "$backup"
echo "Deleted backup: $backup"
done

echo "Kept ${#backups_to_keep[@]} backups and deleted ${#backups[@]} - ${#backups_to_keep[@]} older ones."

0 comments on commit 80de1be

Please sign in to comment.