command_backup.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 commandname="BACKUP"
  7. local commandaction="Backup"
  8. local 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. fn_print_dots ""
  13. sleep 0.5
  14. fn_print_info_nl "A total of ${rootdirduexbackup} will be compressed into the following backup:"
  15. echo "${backupdir}/${backupname}.tar.gz"
  16. echo ""
  17. while true; do
  18. read -e -i "y" -p "Continue? [Y/N]" yn
  19. case $yn in
  20. [Yy]* ) break;;
  21. [Nn]* ) echo Exiting; return;;
  22. * ) echo "Please answer yes or no.";;
  23. esac
  24. done
  25. echo ""
  26. check_status.sh
  27. if [ "${status}" != "0" ]; then
  28. echo ""
  29. fn_print_warning_nl "${servicename} is currently running."
  30. sleep 1
  31. while true; do
  32. read -p "Stop ${servicename} while running the backup? [Y/N]" yn
  33. case $yn in
  34. [Yy]* ) command_stop.sh; break;;
  35. [Nn]* ) break;;
  36. * ) echo "Please answer yes or no.";;
  37. esac
  38. done
  39. fi
  40. fn_print_dots "Backup in progress, please wait..."
  41. fn_script_log_info "Started backup"
  42. sleep 2
  43. if [ ! -d "${backupdir}" ]; then
  44. mkdir "${backupdir}"
  45. fi
  46. tar -czf "${backupdir}/${backupname}.tar.gz" -C "${rootdir}" --exclude "backups" ./*
  47. if [ $? == 0 ]; then
  48. fn_print_ok_nl "Backup created: ${backupname}.tar.gz is $(du -sh "${backupdir}/${backupname}.tar.gz" | awk '{print $1}') size"
  49. fn_script_log_pass "Backup created: ${backupdir}/${backupname}.tar.gz is $(du -sh "${backupdir}/${backupname}.tar.gz" | awk '{print $1}') size"
  50. else
  51. fn_print_error_nl "Backup failed: ${backupname}.tar.gz"
  52. fn_script_log_error "Backup failed: ${backupname}.tar.gz"
  53. fi
  54. sleep 1
  55. echo ""
  56. core_exit.sh