Commit ec7b487f authored by filips's avatar filips
Browse files

init

parent ff3e08d4
## Script request:
https://forum.shell5.dev/topic/13/remote-live-backing-up-custom-game-server-with-sqlite3-databases/5
## Content:
backup.sh - Script used for backing up sqlite3 database and game server files
## Requirements:
Installed packages:
- zip
- rsync
-mailx
Obtain them by running:
Debian based OS(Ubuntu or similar) `apt-get install zip rsync mailx`
RHEL based OS (CentOS or similar) `yum install zip rsync mailx`
#!/bin/bash -
#title :backup.sh
#description :Backup sqlite db and game files
#author :filips ([email protected])
#date :Nov. 7th 2019
#version :0.1
#usage :bash backup.sh
#notes :Enjoy
#bash_version :GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)
#website :https://shell5.dev
#==============================================================================
#PATHS
dbpath=/path/to/game.db # Path to your .db file
backup_location=/path/to/backup/directory # Location of where backup will be stored
server_files=/path/to/game_server_files # Location of game server files
backup_server="[email protected]:/backup/location" #Server where to send the backups
#MAIL
smtp_server=smtps://smtp.example.com:465 # SMTP server >>> notice the smtp(S) and port number, (S) stands for encrytion.
user_pass='[email protected]:12345678' # Username and password in format user:password
from=[email protected] # From parameter (from which email address are you sending)
to=[email protected] # To parameter (to who you are sending)
backup_status=/tmp/status.txt #Temporal status of backup message
#Check requirements
## zip
if ! [ -x "$(command -v zip)" ]; then
echo 'Error: zip is not installed.' >&2
exit 1
fi
## rsync
if ! [ -x "$(command -v rsync)" ]; then
echo 'Error: rsync is not installed.' >&2
exit 1
fi
## mailx
if ! [ -x "$(command -v mailx)" ]; then
echo 'Error: mailx is not installed.' >&2
exit 1
fi
#Make DB Backup
sqlite3 $dbpath ".backup '$backup_location/backup.$(date +"%d-%m-%y").db'"
# Make files backup
zip -r $backup_location/serverfiles.(date +"%d-%m-%y").zip $server_files
# Send backups to the server
rsync -r -z -c $backup_location/* $backup_server
if [ "$?" -eq "0" ]
then
rm -rf $backup_location/backup.$(date +"%d-%m-%y").db #Delete DB for current day
rm -rf $backup_location/serverfiles.(date +"%d-%m-%y").zip #Delete files for current day
echo "Done"
echo "Subject: Success" > $backup_status
else
echo "Error while transfering"
echo "Subject: Error while transfering" > $backup_status
curl --url "$smtp_server" --ssl-reqd \
--mail-from "$from" --mail-rcpt "$to" \
--upload-file $backup_status --user $user_pass
fi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment