Advertisement
Guest User

Untitled

a guest
Jul 29th, 2018
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.42 KB | None | 0 0
  1. #!/bin/bash
  2. ###############################################
  3. #             Minecraft Automated             #
  4. #                Backup Script                #
  5. #                                             #
  6. #       Because fuck doing this manually.     #
  7. #                                             #
  8. # Dependencies: p7zip, rsync                  #
  9. # Optional Dependencies:                      #
  10. # MYSQL, ftp, sendmail                        #
  11. #                                             #
  12. # All "Enable" options are true or false      #
  13. #                                             #
  14. # This script assumes all dependencies are    #
  15. # correctly configured.                       #
  16. #                                             #
  17. #                                             #
  18. ###############################################
  19.  
  20. ###############################################
  21. #              User Variables                 #
  22. #  Modify these variables to suit your needs  #
  23. ###############################################
  24.  
  25. ###############################################
  26. #              Email Reporting                #
  27. ###############################################
  28. # Enable
  29. EMAIL=true
  30. # Details
  31. TO=ryan.walder@gmail.com
  32. # Email subject " YYY-MM-DD" will be appended
  33. SUBJECT="Daily Backup Report"
  34.  
  35. ###############################################
  36. #              Backup Rotation                #
  37. ###############################################
  38. # How many days of backups to keep?
  39. BACKAGE=30
  40.  
  41. ###############################################
  42. #                MYSQL Backup
  43. ###############################################
  44. # Enable
  45. MYSQL=true
  46. # Details
  47. MYSQLHOST=localhost
  48. MYSQLPORT=3306
  49. MYSQLUSER=lolno
  50. MYSQLPASS=lolno
  51. # Backup name "-YYYY-MM-DD" will be appended
  52. MYSQLNAME=mysql
  53.  
  54. ###############################################
  55. #                 FTP Backup                  #
  56. ###############################################
  57. # Enable
  58. FTP=true
  59. # Details
  60. FTPHOST=lulz.dyndns.org
  61. FTPUSER=lolno
  62. FTPPASS=lolno
  63. # Remote dir
  64. FTPDIR=Backup/Minecraft
  65.  
  66. ###############################################
  67. #              Minecraft Backup               #
  68. ###############################################
  69. # Do you use a ramdisk?
  70. RAMDISK=true
  71. # Full path to hdd copies of ramdisk worlds (if using a ramdisk else leave blank)
  72. WORLDROOT=/home/minecraft/worlds.hdd
  73. # Final directory for local backups
  74. BACKDIR=/home/minecraft/backups
  75. # Temp dir for coping files (must be it's own directory so /tmp will not do but /tmp/minecraft will)
  76. TEMPDIR=/home/minecraft/backuptemp
  77. # Server root directory (assumes individual servers are in this directory)
  78. SRVROOT=/home/minecraft/multicraft/servers
  79.  
  80. ## Server 1 details
  81. # Name used for final files
  82. SRV1NAME=tekkit
  83. # Server instance directory (assumes directly below server root)
  84. SRV1DIR=CarmaCraftTekkit
  85. # Server world name base (e.g. world which gives world_nether etc..) - Ignored if not ramdisk enabled
  86. SRV1WORLDNAME=world_tekkit
  87.  
  88. ## Server 2 details
  89. # Name used for final files
  90. SRV2NAME=Factions
  91. # Server instance directory (assumes directly below server root)
  92. SRV2=CarmaCraftFactions
  93. # Server world name base (e.g. world which gives world_nether etc..) - Ignored if not ramdisk enabled
  94. SRV2WORLDNAME=world_factions
  95.  
  96. ###############################################
  97. #        Script Variables -  DO NOT EDIT      #
  98. ###############################################
  99. FULLEMAILSUBJECT='$SUBJECT `date +"%Y-%m-%d"`'
  100. LOGFILE=$BACKDIR/backup.`date +"%Y-%m-%d"`.log
  101. MYSQLFULLNAME=$MYSQLNAME-`date +"%Y-%m-%d"`.sql.gz
  102.  
  103. ###############################################
  104.  
  105. # Check backup dir exists, if not create it
  106. if [ ! -d "$FULLBACKDIR" ]; then
  107.     echo "Creating backup directory..."
  108.     mkdir $BACKDIR
  109. fi
  110.  
  111. touch $LOGFILE
  112.  
  113. # Redirect Output to a logfile and screen - Couldnt get tee to work
  114. #exec 3>&1
  115. #exec 1>$LOGFILE
  116.  
  117. echo " "
  118. echo "###############################################"
  119. echo "#        Minecraft Full Backup Script         #"
  120. echo "###############################################"
  121. echo " "
  122.  
  123. ###############################################
  124. # Server 1                                    #
  125. # If duplicating for multiple servers         #
  126. # copy this and change the variables below.   #
  127. # So SRVDIR=$SRV1DIR becomes SRVDIR=$SRV2DIR  #
  128. # If only backing up one server ignore this   #
  129. ###############################################
  130. ############# START SERVER 1 ##################
  131. SRVDIR=$SRV1DIR
  132. SRVNAME=$SRV1NAME
  133. SRVWORLDNAME=$SRV1WORLDNAME
  134. SRV7Z=$BACKDIR/$SRV1NAME-$TODAY.7z
  135. ############ Do Not Edit Below! ###############
  136. # Copy all server files except worlds
  137. echo "Copying $SRVNAME files..."
  138. if $RAMDISK ; then
  139.     # Copy all server files except worlds
  140.     rsync -rq --exclude '$SRVWORLDNAME*' $SRVROOT/$SRVDIR/ $TEMPDIR/
  141.     # Copy worlds from hdd copies
  142.     echo "Copying $SRVNAME worlds..."
  143.     rsync -rq $WORLDROOT/$SRVWORLDNAME* $TEMPDIR/
  144. else
  145.     # Copy all server files including worlds (if no ramdisk)
  146.     rsync -rq $SRVROOT/$SRVDIR/ $TEMPDIR/
  147. fi
  148. # Compress server
  149. echo "Compressing $SRVNAME..."
  150. 7zr a -mx9 $BACKDIR/$SRV7Z $TEMPDIR/*
  151. # Test archive
  152. echo "Testing $SRVNAME archive..."
  153. 7zr t $BACKDIR/$SRV7Z
  154. # Cleanup
  155. rm -rf $TEMPDIR
  156. #FTP files
  157. if $FTP ; then
  158.     echo "FTPing $SRVNAME Files..."
  159.     ftp -n $FTPHOST
  160.     quote USER $FTPUSER
  161.     quote PASS $FTPPASS
  162.     cd $FTPDIR
  163.     put $SRV7Z
  164.     exit
  165. fi
  166. ############## END SERVER 1 ###################
  167.  
  168. ############# START SERVER 2 ##################
  169. SRVDIR=$SRV2DIR
  170. SRVNAME=$SRV2NAME
  171. SRVWORLDNAME=$SRV2WORLDNAME
  172. SRV7Z=$BACKDIR/$SRV2NAME-$TODAY.7z
  173. ############ Do Not Edit Below! ###############
  174. echo "Copying $SRVNAME files..."
  175. if $RAMDISK ; then
  176.     # Copy all server files except worlds
  177.     rsync -rq --exclude '$SRVWORLDNAME*' $SRVROOT/$SRVDIR/ $TEMPDIR/
  178.     # Copy worlds from hdd copies
  179.     echo "Copying $SRVNAME worlds..."
  180.     rsync -rq $WORLDROOT/$SRVWORLDNAME* $TEMPDIR/
  181. else
  182.     # Copy all server files including worlds (if no ramdisk)
  183.     rsync -rq $SRVROOT/$SRVDIR/ $TEMPDIR/
  184. fi
  185. echo "Compressing $SRVNAME..."
  186. 7zr a -mx9 $BACKDIR/$SRV7Z $TEMPDIR/*
  187. # Test archive
  188. echo "Testing $SRVNAME archive..."
  189. 7zr t $BACKDIR/$SRV7Z
  190. # Cleanup
  191. rm -rf $TEMPDIR
  192. #FTP files
  193. if $FTP ; then
  194.     echo "FTPing $SRVNAME Files..."
  195.     ftp -n $FTPHOST
  196.     quote USER $FTPUSER
  197.     quote PASS $FTPPASS
  198.     cd $FTPDIR
  199.     put $SRV7Z
  200.     exit
  201. fi
  202. ############## END SERVER 2 ###################
  203.  
  204. # Dump MYSQL
  205. if $MQSQL ; then
  206.     echo "Dumping MYSQL database(s)..."
  207.     if [ ! -d "$BACKDIR/MYSQL" ] ; then
  208.         echo "Creating MYSQL backup directory..."
  209.         mkdir $BACKDIR/MYSQL
  210.     fi
  211.     mysqldump --host=$MYSQLHOST --port=$MYSQLPORT --user=$MYSQLUSER --password=$MYSQLPASS --add-drop-database --all-databases | gzip > $MYSQLFULLNAME
  212.     # FTP MYSQL
  213.     if $FTP ; then
  214.         echo "FTPing MYSQL..."
  215.         ftp -n $FTPHOST
  216.         quote USER $FTPUSER
  217.         quote PASS $FTPPASS
  218.         cd $FTPDIR
  219.         put $SRV7Z
  220.         exit
  221.     fi
  222. fi
  223.  
  224. # Remove backups over specified age
  225. find $BACKDIR -type f -mtime +$BACKAGE | xargs rm
  226.  
  227. echo " "
  228. echo "###############################################"
  229. echo "#                   DONE!                     #"
  230. echo "#              Check the log!                 #"
  231. echo "#     Make sure the backup isn't failing!     #"
  232. echo "###############################################"
  233.  
  234. # Email
  235. if $EMAIL ; then
  236.     cat $LOGFILE | mail -s "$FULLEMAILSUBJECT" $TO
  237. fi
  238.  
  239. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement