How to backup your ARK server to B2 Cloud Storage
I recently setup an ARK server for my friends to play on and came to the point of how I wanted to handle backups. You can apply the following to most Linux servers. I won’t go into details on how to setup the ARK server but I can tell you that I’m using LGSM scripts running on Ubuntu 14.04. I also applied the recommended configuration changes under the Linux section on this page.
Sign up for a free B2 account. Once you have signed in click on “Show Account ID and Application Key” and generate an Application Key. Copy this key to somewhere secure like 1Password because you can not view it again but must generate a new key if you lose it. After you have your Account ID and Application Key create a bucket for your backup files. I have created a bucket for each of my applications but you could just create one bucket called “backups” and have subdirectories inside of that if you prefer.
On the Ubuntu side of things I’m going to assume that you’ve created a user account for the LGSM script to run inside of. In my example I have created a non sudo account named “arkserver”. Run the following command as “arkserver” to authorize the “arkserver” user account to use your B2 Storage account.
b2 authorize_account [accountId] [applicationKey]
Download the b2 command line tool using the following command:
wget https://docs.backblaze.com/public/b2_src_code_bundles/b2
Next you’ll want to create a script to backup your important server files and upload them to your B2 bucket. Type
mkdir backups
to create the temporary directory we will use to store backup files. Type
nano arkserver-backup.sh
You can name this file whatever you want. Now copy and paste the following code in this window:
# !/bin/bash
# ARK Server Backup
# Author: Ryan Christensen
# Description: Creates a .tar.gz file in the backup directory for only the /Saved folder of the ARK server then uploads to B2 storage.
b2="/home/arkserver/b2"
b2_bucket="ark-server-backups"
backup_name="ark-server-$(date '+%Y-%m-%d-%H-%M')" backup_target="/home/arkserver/serverfiles/ShooterGame/Saved"
backup_dir="/home/arkserver/backups"
echo ""
echo "ARK Server Backup"
echo "============================"
echo ""
echo "The following backup will be created:"
echo ""
echo "${backup_dir}/${backup_name}.tar.gz"
echo ""
echo -en "starting backup.r"
sleep 1
echo -en "starting backup..r"
sleep 1
echo -en "starting backup...r"
sleep 1
echo -en "n"
tar -cvzf "${backup_dir}/${backup_name}.tar.gz" -C "${backup_target}" .
echo ""
echo "Backup created: ${backup_dir}/${backup_name}.tar.gz" echo ""
echo ""
echo "Uploading to B2 storage"
echo ""
"${b2}" upload_file "${b2_bucket}" "${backup_dir}/${backup_name}.tar.gz" "${backup_name}.tar.gz"
echo ""
echo "Upload complete"
echo ""
echo ""
echo "Deleting local backup file"
echo ""
rm "${backup_dir}/${backup_name}.tar.gz"
echo ""
echo "Backup and upload complete"
echo ""
Press “Control X” then “Y” and return to save your file. Now run chmod +x arkserver-backup.sh
to make your script executable. If you want to test your script you can do that by running the command:
./arkserver-backup.sh
You may need to change the variable in the script of the b2_bucket to match your B2 bucket name.
Once you are satisfied with your script you need to schedule it to run as frequently as you desire. B2 Cloud Storage offers 10GB free storage with free uploads after that it’s only $0.05/GB/month which is about half of what Amazon charges. I have scheduled my server to backup every six hours but you can set yours to backup as frequently as you’d like. This website is an excellent way to generate crontab commands. Use it to set how frequently you want your server to backup.
After you have your crontab command generated type
crontab -e
to enter the crontab editor. I chose “2” to use the nano editor but you can choose the editor that you prefer. My crontab looks like the following but yours might be different:
0 */6 * * * /home/arkserver/arkserver-backup.sh > /home/arkserver/cronjob.log
After you enter it press “Control X” and “Y” to save your changes (assuming your using nano for the editor). That’s it! You can check your cronjob log file or the B2 Cloud Storage site to verify that your backups are working correctly. Rest easy knowing that your important server files are stored safely on B2 Cloud Storage!