Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ###############################################
- # Minecraft Automated #
- # Backup Script #
- # #
- # Because fuck doing this manually. #
- # #
- # Dependencies: p7zip, rsync #
- # Optional Dependencies: #
- # MYSQL, ftp, sendmail #
- # #
- # All "Enable" options are true or false #
- # #
- # This script assumes all dependencies are #
- # correctly configured. #
- # #
- # #
- ###############################################
- ###############################################
- # User Variables #
- # Modify these variables to suit your needs #
- ###############################################
- ###############################################
- # Email Reporting #
- ###############################################
- # Enable
- EMAIL=true
- # Details
- TO=ryan.walder@gmail.com
- # Email subject " YYY-MM-DD" will be appended
- SUBJECT="Daily Backup Report"
- ###############################################
- # Backup Rotation #
- ###############################################
- # How many days of backups to keep?
- BACKAGE=30
- ###############################################
- # MYSQL Backup
- ###############################################
- # Enable
- MYSQL=true
- # Details
- MYSQLHOST=localhost
- MYSQLPORT=3306
- MYSQLUSER=lolno
- MYSQLPASS=lolno
- # Backup name "-YYYY-MM-DD" will be appended
- MYSQLNAME=mysql
- ###############################################
- # FTP Backup #
- ###############################################
- # Enable
- FTP=true
- # Details
- FTPHOST=lulz.dyndns.org
- FTPUSER=lolno
- FTPPASS=lolno
- # Remote dir
- FTPDIR=Backup/Minecraft
- ###############################################
- # Minecraft Backup #
- ###############################################
- # Do you use a ramdisk?
- RAMDISK=true
- # Full path to hdd copies of ramdisk worlds (if using a ramdisk else leave blank)
- WORLDROOT=/home/minecraft/worlds.hdd
- # Final directory for local backups
- BACKDIR=/home/minecraft/backups
- # Temp dir for coping files (must be it's own directory so /tmp will not do but /tmp/minecraft will)
- TEMPDIR=/home/minecraft/backuptemp
- # Server root directory (assumes individual servers are in this directory)
- SRVROOT=/home/minecraft/multicraft/servers
- ## Server 1 details
- # Name used for final files
- SRV1NAME=tekkit
- # Server instance directory (assumes directly below server root)
- SRV1DIR=CarmaCraftTekkit
- # Server world name base (e.g. world which gives world_nether etc..) - Ignored if not ramdisk enabled
- SRV1WORLDNAME=world_tekkit
- ## Server 2 details
- # Name used for final files
- SRV2NAME=Factions
- # Server instance directory (assumes directly below server root)
- SRV2=CarmaCraftFactions
- # Server world name base (e.g. world which gives world_nether etc..) - Ignored if not ramdisk enabled
- SRV2WORLDNAME=world_factions
- ###############################################
- # Script Variables - DO NOT EDIT #
- ###############################################
- FULLEMAILSUBJECT='$SUBJECT `date +"%Y-%m-%d"`'
- LOGFILE=$BACKDIR/backup.`date +"%Y-%m-%d"`.log
- MYSQLFULLNAME=$MYSQLNAME-`date +"%Y-%m-%d"`.sql.gz
- ###############################################
- # Check backup dir exists, if not create it
- if [ ! -d "$FULLBACKDIR" ]; then
- echo "Creating backup directory..."
- mkdir $BACKDIR
- fi
- touch $LOGFILE
- # Redirect Output to a logfile and screen - Couldnt get tee to work
- #exec 3>&1
- #exec 1>$LOGFILE
- echo " "
- echo "###############################################"
- echo "# Minecraft Full Backup Script #"
- echo "###############################################"
- echo " "
- ###############################################
- # Server 1 #
- # If duplicating for multiple servers #
- # copy this and change the variables below. #
- # So SRVDIR=$SRV1DIR becomes SRVDIR=$SRV2DIR #
- # If only backing up one server ignore this #
- ###############################################
- ############# START SERVER 1 ##################
- SRVDIR=$SRV1DIR
- SRVNAME=$SRV1NAME
- SRVWORLDNAME=$SRV1WORLDNAME
- SRV7Z=$BACKDIR/$SRV1NAME-$TODAY.7z
- ############ Do Not Edit Below! ###############
- # Copy all server files except worlds
- echo "Copying $SRVNAME files..."
- if $RAMDISK ; then
- # Copy all server files except worlds
- rsync -rq --exclude '$SRVWORLDNAME*' $SRVROOT/$SRVDIR/ $TEMPDIR/
- # Copy worlds from hdd copies
- echo "Copying $SRVNAME worlds..."
- rsync -rq $WORLDROOT/$SRVWORLDNAME* $TEMPDIR/
- else
- # Copy all server files including worlds (if no ramdisk)
- rsync -rq $SRVROOT/$SRVDIR/ $TEMPDIR/
- fi
- # Compress server
- echo "Compressing $SRVNAME..."
- 7zr a -mx9 $BACKDIR/$SRV7Z $TEMPDIR/*
- # Test archive
- echo "Testing $SRVNAME archive..."
- 7zr t $BACKDIR/$SRV7Z
- # Cleanup
- rm -rf $TEMPDIR
- #FTP files
- if $FTP ; then
- echo "FTPing $SRVNAME Files..."
- ftp -n $FTPHOST
- quote USER $FTPUSER
- quote PASS $FTPPASS
- cd $FTPDIR
- put $SRV7Z
- exit
- fi
- ############## END SERVER 1 ###################
- ############# START SERVER 2 ##################
- SRVDIR=$SRV2DIR
- SRVNAME=$SRV2NAME
- SRVWORLDNAME=$SRV2WORLDNAME
- SRV7Z=$BACKDIR/$SRV2NAME-$TODAY.7z
- ############ Do Not Edit Below! ###############
- echo "Copying $SRVNAME files..."
- if $RAMDISK ; then
- # Copy all server files except worlds
- rsync -rq --exclude '$SRVWORLDNAME*' $SRVROOT/$SRVDIR/ $TEMPDIR/
- # Copy worlds from hdd copies
- echo "Copying $SRVNAME worlds..."
- rsync -rq $WORLDROOT/$SRVWORLDNAME* $TEMPDIR/
- else
- # Copy all server files including worlds (if no ramdisk)
- rsync -rq $SRVROOT/$SRVDIR/ $TEMPDIR/
- fi
- echo "Compressing $SRVNAME..."
- 7zr a -mx9 $BACKDIR/$SRV7Z $TEMPDIR/*
- # Test archive
- echo "Testing $SRVNAME archive..."
- 7zr t $BACKDIR/$SRV7Z
- # Cleanup
- rm -rf $TEMPDIR
- #FTP files
- if $FTP ; then
- echo "FTPing $SRVNAME Files..."
- ftp -n $FTPHOST
- quote USER $FTPUSER
- quote PASS $FTPPASS
- cd $FTPDIR
- put $SRV7Z
- exit
- fi
- ############## END SERVER 2 ###################
- # Dump MYSQL
- if $MQSQL ; then
- echo "Dumping MYSQL database(s)..."
- if [ ! -d "$BACKDIR/MYSQL" ] ; then
- echo "Creating MYSQL backup directory..."
- mkdir $BACKDIR/MYSQL
- fi
- mysqldump --host=$MYSQLHOST --port=$MYSQLPORT --user=$MYSQLUSER --password=$MYSQLPASS --add-drop-database --all-databases | gzip > $MYSQLFULLNAME
- # FTP MYSQL
- if $FTP ; then
- echo "FTPing MYSQL..."
- ftp -n $FTPHOST
- quote USER $FTPUSER
- quote PASS $FTPPASS
- cd $FTPDIR
- put $SRV7Z
- exit
- fi
- fi
- # Remove backups over specified age
- find $BACKDIR -type f -mtime +$BACKAGE | xargs rm
- echo " "
- echo "###############################################"
- echo "# DONE! #"
- echo "# Check the log! #"
- echo "# Make sure the backup isn't failing! #"
- echo "###############################################"
- # Email
- if $EMAIL ; then
- cat $LOGFILE | mail -s "$FULLEMAILSUBJECT" $TO
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement