command_backup.sh 1.5 KB

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