PlowmanPlow

Simple rsync MC Backup

May 7th, 2020
2,038
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. mcuser=username
  4. scrname=minecraft
  5. mcb=/mcbackups/sdom/backups_hourly
  6. src=/home/username/server/
  7. screen=/usr/bin/screen
  8. #exclude='backups/*'
  9. #exclude='database.db'
  10. exclude='logs/'
  11. iterations=24
  12.  
  13. mcprocess=$(ps -eaf | grep java | grep sdomserver | 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. cd $mcb
  23. oldest=`printf "%03g" ${iterations}`
  24. if [ -e minecraft.${oldest} ]; then rm -rf minecraft.${oldest}; echo Removing ${oldest}; fi
  25. start=`expr ${iterations} - 1`
  26. for i in `seq -f "%03g" ${start} -1 0`; do
  27.    oneup=`expr ${i} + 1`
  28.    oneup=`printf "%03g" ${oneup}`
  29.    if [ -e minecraft.${i} ]; then mv minecraft.${i} minecraft.${oneup}; echo Moving ${i} to ${oneup}; fi
  30. done
  31. if [ -e minecraft.001 ]; then
  32.    rsync -a --exclude=$exclude --delete --link-dest=$mcb/minecraft.001 $src $mcb/minecraft.000/
  33. else
  34.    rsync -a --exclude=$exclude --delete $src $mcb/minecraft.000/
  35. fi
  36.  
  37. if [ "$mcprocess" == "$mcuser" ]; then
  38.    $screen -d -r $scrname -p 0 -X stuff "save-on $(printf '\r')"
  39. #   $screen -d -r $scrname -p 0 -X stuff "say Hourly backup complete! $(printf '\r')"
  40. fi
RAW Paste Data