Incremental Server Backups on Linux

magnifikus

New Member
Jul 29, 2019
12
7
1
I want to show you a short tutorial how to make incremental backups on your minecraft server.
The incremental means that only differed files are actually saved and you can make frequently backups without wasting much diskspace.

this is based on the linux tool rsnapshot, i will show the way to go on debian here:

1. Step
Install the tool itself (may differ on different distributions)
Code:
sudo apt-get install rsnapshot

2. Step

now we need a backup directory i choosed /home/biocraft/backup that is actually on a different harddisk
first of you need to copy the existing example config here:
Code:
cd /home/biocraft/backup
cp /etc/rsnapshot.conf ./

after this we need some parts of the config:

the actually directory where the backups go to
Code:
snapshot_root  /home/biocraft/backup/

move the pid file somewhere else because we are running in user mode
Code:
lockfile        /tmp/biorsnapshot.pid

scripts that are executed before and after the backup
Code:
cmd_preexec    /home/biocraft/backup/pre.sh
cmd_postexec    /home/biocraft/backup/post.sh

amount of backups to keep, this means:
hourly 24 single hourly backups are kept before the old ones are deleted (you may want to decrease this)
daily 4 single daily backups are kept
weekly 1 only one daily backup is kept

you need to try out here so you dont mess your diskspace

Code:
interval        hourly  24
interval        daily  4
interval        weekly  1
#interval      monthly 3
MAKE SURE HERE TO COMMENT OUT THE DEFAULT DESTINATIONS!
This will configure what directory to create backups off
Code:
###############################
### BACKUP POINTS / SCRIPTS ###
###############################
 
# LOCALHOST
backup  /home/biocraft/srv_live/        localhost/
#backup /etc/          localhost/
#backup /usr/local/    localhost/
#backup /var/log/rsnapshot              localhost/



3. Step

creating pre and post scripts:
This will inform the users and stop the server from writing to the world folder while the backup is running.
keep in mind that you need to start your server in a screen named biocraft or whatelse ;)

pre.sh

Code:
screen -S biocraft -X stuff "say Starting backup. World is Readonly! $(printf '\r')"
screen -S biocraft -X stuff "save-off $(printf '\r')"
screen -S biocraft -X stuff "save-all $(printf '\r')"


post.sh

Code:
screen -S biocraft -X stuff "save-on $(printf '\r')"
screen -S biocraft -X stuff "say Backup complete. World back to Readwrite $(printf '\r')"

4. step

you can now do a simple testrun by invoking
Code:
rsnapshot -c /home/biocraft/backup/rsnapshot.conf hourly
if where is no error your server should show some messages in the console (from pre and post scripts)
also note that first backup will take some time, later ones will go in seconds.


5. step
ensuring your backup is correct:
in the backup directory should now a directory named "hourly.0", this has always the most recent backup in it, go check if anything you want is in where so you dont get a herpaderp when you need the backup.

6. step cronjob

next you can configure a cronjob to make the backups automatic (crontab -e):
Code:
0 * * * * /usr/bin/rsnapshot -c /home/biocraft/backup/rsnapshot.conf hourly
1 0 * * * /usr/bin/rsnapshot -c /home/biocraft/backup/rsnapshot.conf daily
2 0 * * 1 /usr/bin/rsnapshot -c /home/biocraft/backup/rsnapshot.conf weekly


now you should be good to go!


some notes:

- you can even execute your daily script every 30 minutes to get a finer backup history
- this is not good if you want to pull your backups often from your box, because when you need to zip them every time, some other tool like rdiff-backup may fit better for this task.
- do not zip the backups or something you will screw the tool over