command_backup.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. # LGSM command_backup.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. lgsm_version="210516"
  6. # Description: Creates a .tar.gz file in the backup directory.
  7. modulename="Backup"
  8. function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  9. check.sh
  10. info_distro.sh
  11. backupname="${servicename}-$(date '+%Y-%m-%d-%H%M%S')"
  12. echo ""
  13. fn_print_info_nl "A total of ${rootdirduexbackup} will be compressed into the following backup:"
  14. echo "${backupdir}/${backupname}.tar.gz"
  15. echo ""
  16. while true; do
  17. read -p "Continue? [Y/N]" yn
  18. case $yn in
  19. [Yy]* ) break;;
  20. [Nn]* ) echo Exiting; return;;
  21. * ) echo "Please answer yes or no.";;
  22. esac
  23. done
  24. echo ""
  25. check_status.sh
  26. if [ "${status}" != "0" ]; then
  27. echo ""
  28. fn_print_warning_nl "${servicename} is currently running."
  29. sleep 1
  30. while true; do
  31. read -p "Stop ${servicename} while running the backup? [Y/N]" yn
  32. case $yn in
  33. [Yy]* ) command_stop.sh; break;;
  34. [Nn]* ) break;;
  35. * ) echo "Please answer yes or no.";;
  36. esac
  37. done
  38. fi
  39. fn_print_dots "Backup in progress, please wait..."
  40. fn_script_log_info "Started backup"
  41. sleep 2
  42. if [ ! -d "${backupdir}" ]; then
  43. mkdir "${backupdir}"
  44. fi
  45. tar -czf "${backupdir}/${backupname}.tar.gz" -C "${rootdir}" --exclude "backups" ./*
  46. # NOTE: Need to add error checking for tar.
  47. fn_print_ok_nl "Backup created: ${backupname}.tar.gz is $(du -sh "${backupdir}/${backupname}.tar.gz" | awk '{print $1}') size"
  48. fn_script_log_pass "Backup created: ${backupdir}/${backupname}.tar.gz is $(du -sh "${backupdir}/${backupname}.tar.gz" | awk '{print $1}') size"
  49. sleep 1
  50. echo ""
  51. core_exit.sh