PlowmanPlow

Ghetto MC Backups

Dec 26th, 2017
153
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. scrname=minecraft
  4. mcuser=minecraft
  5. mcb=/home/minecraft/backups/servername/backups_hourly
  6. src=/ssd/servername/
  7. screen=/usr/bin/screen
  8. #exclude='backups/*'
  9. #exclude='database.db'
  10. exclude='playerlogger.*'
  11. iterations=12
  12.  
  13. mcprocess=$(ps -eaf | grep java | grep cauldron | awk '{print $1}')
  14. if [ "$mcprocess" == "$mcuser" ]; then
  15.    $screen -d -r $scrname -p 0 -X stuff "$(printf '\r')"
  16. #   $screen -d -r $scrname -p 0 -X stuff "say Initiating Hourly backup! $(printf '\r')"
  17.    $screen -d -r $scrname -p 0 -X stuff "save-off $(printf '\r')"
  18.    $screen -d -r $scrname -p 0 -X stuff "save-all $(printf '\r')"
  19.    sleep 1
  20. fi
  21.  
  22. # Backup Database
  23. mysqldump --opt --user=root gpp_servername > $src/gpp_servername.sql
  24.  
  25. cd $mcb
  26. oldest=`printf "%03g" ${iterations}`
  27. if [ -e minecraft.${oldest} ]; then rm -rf minecraft.${oldest}; echo Removing ${oldest}; fi
  28. start=`expr ${iterations} - 1`
  29. for i in `seq -f "%03g" ${start} -1 0`; do
  30.    oneup=`expr ${i} + 1`
  31.    oneup=`printf "%03g" ${oneup}`
  32.    if [ -e minecraft.${i} ]; then mv minecraft.${i} minecraft.${oneup}; echo Moving ${i} to ${oneup}; fi
  33. done
  34. if [ -e minecraft.001 ]; then
  35.    rsync -a --exclude=$exclude --delete --link-dest=$mcb/minecraft.001 $src $mcb/minecraft.000/
  36. else
  37.    rsync -a --exclude=$exclude --delete $src $mcb/minecraft.000/
  38. fi
  39.  
  40. if [ "$mcprocess" == "$mcuser" ]; then
  41.    $screen -d -r $scrname -p 0 -X stuff "save-on $(printf '\r')"
  42. #   $screen -d -r $scrname -p 0 -X stuff "say Hourly backup complete! $(printf '\r')"
  43. fi
RAW Paste Data