Knoxvilles_joker
Refugee
I looked through linux GSM and there is one thing missing a good backup script. In my case in Ubuntu I will be backing up locally and do a manual backup to a thumb drive and rotate thumb drives. Backup best practices are you have a local backup and an offsite backup a minimum of 50 miles away ( think a nuke goes off you have a clean copy of your files to restore worst case scenario.) In my case the thumb drives will be rotated between home and a separate property with a fireproof safe
first let us make the backup directory:
sudo mkdir /home/backup
now set us make the backup script:
sudo vi /usr/local/bin/backup.sh
Now copy in after hitting i to enter insert mode:
#!/bin/bash
systemctl stop 7days # this stops the server to do the backup
sleep 30 # give the system time to stop the service/server
SOURCE_DIR="/home/7days/7days/saves" # Replace with your game's directory
BACKUP_DIR="/home/backup" # Replace with your backup directory
TIMESTAMP=$(date +%Y%m%d%H%M%S)
BACKUP_NAME="game_backup_$TIMESTAMP"
FULL_BACKUP_PATH="$BACKUP_DIR/$BACKUP_NAME"
# Create backup directory if it doesn't exist
mkdir -p "$FULL_BACKUP_PATH"
# Copy game files using rsync
rsync -av "$SOURCE_DIR/" "$FULL_BACKUP_PATH/"
echo "Backup completed to $FULL_BACKUP_PATH"
# Optional: Remove old backups (e.g., keep only the last 7 days)
find "$BACKUP_DIR" -maxdepth 1 -type d -name "game_backup_*" -mtime +7 -exec rm -rf {} \;
systemctl start 7days # start the server backup after rsync and backup cleanups are done
hit escape to exit insert mode
type:
:wq
type:
chmod +x /usr/local/bin/backup.sh
Now add this as a crontab job to run at a set time. In my case I will do it at 5am as generally I am asleep or generally not playing at that hour:
sudo crontab -e
add in:
0 5 * * * /usr/local/bin/backup.sh
type ctrl+x then hit y then enter to exit.
I will add a later post when I do the USB transfer to show how to find the removable drive and then to copy a set of file to it.
first let us make the backup directory:
sudo mkdir /home/backup
now set us make the backup script:
sudo vi /usr/local/bin/backup.sh
Now copy in after hitting i to enter insert mode:
#!/bin/bash
systemctl stop 7days # this stops the server to do the backup
sleep 30 # give the system time to stop the service/server
SOURCE_DIR="/home/7days/7days/saves" # Replace with your game's directory
BACKUP_DIR="/home/backup" # Replace with your backup directory
TIMESTAMP=$(date +%Y%m%d%H%M%S)
BACKUP_NAME="game_backup_$TIMESTAMP"
FULL_BACKUP_PATH="$BACKUP_DIR/$BACKUP_NAME"
# Create backup directory if it doesn't exist
mkdir -p "$FULL_BACKUP_PATH"
# Copy game files using rsync
rsync -av "$SOURCE_DIR/" "$FULL_BACKUP_PATH/"
echo "Backup completed to $FULL_BACKUP_PATH"
# Optional: Remove old backups (e.g., keep only the last 7 days)
find "$BACKUP_DIR" -maxdepth 1 -type d -name "game_backup_*" -mtime +7 -exec rm -rf {} \;
systemctl start 7days # start the server backup after rsync and backup cleanups are done
hit escape to exit insert mode
type:
:wq
type:
chmod +x /usr/local/bin/backup.sh
Now add this as a crontab job to run at a set time. In my case I will do it at 5am as generally I am asleep or generally not playing at that hour:
sudo crontab -e
add in:
0 5 * * * /usr/local/bin/backup.sh
type ctrl+x then hit y then enter to exit.
I will add a later post when I do the USB transfer to show how to find the removable drive and then to copy a set of file to it.