Tobias Solem

Linux database backup system

3 posts in this topic

Pre-requirements:

- mysqldump  (apt-get install mysqldump or dpkg -i mysqldump if you have the package, other dists to debian/ubuntu may be different)
 

##

These are some simple instructions how you can setup a backup script for your exile database, and have it running, and cleaning out old backups every X days:

 

Step 1:

Make a backup folder somewhere, I use: /home/steam/exile/backups/ (note, I use a symlink to a backup harddrive)
Make a subfolder to the backup folder for database entries, I use: /home/steam/exile/backups/db/
Make sure these folders are not readable by anyone but your user that handles arma (should never be root), for me the username is steam:

# chmod 600 /home/steam/exile/backups        // This line prevents access to the folder from anyone but the owner of the folder
# chown steam /home/steam/exile/backups         // This line changes ownership to the steam-user who is used to run the arma3server binary
# chgrp steam /home/steam/exile/backups         // This line changes group ownership to the steam-user who is used to run the arma3server binary

 

Step 2:

Using your favourite editor, mine is nano, create a file in your /home/steam/exile/backups/ called backup.sh with the following two lines:


find /home/steam/exile/backups/db/* -mtime +5 -exec rm {} \;

mysqldump -u exile -pYOURPASSWORD exile | gzip > /home/steam/exile/backups/db/database_"$(date +%Y%m%d-%H%M%S)".sql.gz

 

Do not forget to:

chmod 700 backup.sh

This gives only the owner execution permission of the file, if you are logged in as root, don't forget to change group/ownership of the file to the steam user.

The first line looks for all files (*) in the directory specified and removes the files that are -mtime +X days old. 
The second line using the user exile, with password: YOURPASSWORD and dumps the exile database to the backups-folder using todays date and time, and tar+gzips it. 

 

Step 3:

Edit your crontab (ie. crontab -e) and insert the following line:

*/5 *   * * *       /home/steam/exile/backups/backup.sh 

This runs the backup command every 5 minutes. 

 

Step 4:

As root, reload your crontabs

sudo /etc/init.d/cron reload

Edited by Tobias Solem
  • Like 1

Share this post


Link to post
Share on other sites

Easier way may be the automysqlbackup tool. You install it on your linux server, automatic cron job setup and makes daily, weekly and monthly backups. 

Its what we use, its then compressed and uploaded to our backup server. 

Edit: Good guide however, i like the extra bits on making sure the directories are secure (The chmod)

Edited by QGS

Share this post


Link to post
Share on other sites

Easier way may be the automysqlbackup tool. You install it on your linux server, automatic cron job setup and makes daily, weekly and monthly backups. 

Its what we use, its then compressed and uploaded to our backup server. 

Edit: Good guide however, i like the extra bits on making sure the directories are secure (The chmod)

Whatever works man. :)

Thanks for the props.

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.