Skip to content

Commit

Permalink
feat: Custom backup
Browse files Browse the repository at this point in the history
  • Loading branch information
vinanrra committed Jun 28, 2024
1 parent 317509b commit bcfb39c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
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
26 changes: 23 additions & 3 deletions scripts/server_backup.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
#!/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/"

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

Expand Down
17 changes: 17 additions & 0 deletions scripts/utils/crontab.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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 bcfb39c

Please sign in to comment.