autobackup.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
  3. Info="${Green_font_prefix}[ON]${Font_color_suffix}"
  4. Error="${Red_font_prefix}[OFF]${Font_color_suffix}"
  5. cek=$(grep -c -E "^# BEGIN_Backup" /etc/crontab)
  6. if [[ "$cek" = "1" ]]; then
  7. sts="${Info}"
  8. else
  9. sts="${Error}"
  10. fi
  11. function start() {
  12. email=$(cat /home/email)
  13. if [[ "$email" = "" ]]; then
  14. echo "Please enter your email"
  15. read -rp "Email: " -e email
  16. cat <<EOF>>/home/email
  17. $email
  18. EOF
  19. fi
  20. cat << EOF >> /etc/crontab
  21. # BEGIN_Backup
  22. 5 0 * * * root bckp
  23. # END_Backup
  24. EOF
  25. service cron restart
  26. sleep 1
  27. echo " Please Wait"
  28. clear
  29. echo " Autobackup Has Been Started"
  30. echo " Data Will Be Backed Up Automatically at 00:05 GMT +7"
  31. exit 0
  32. }
  33. function stop() {
  34. email=$(cat /home/email)
  35. sed -i "/^$email/d" /home/email
  36. sed -i "/^# BEGIN_Backup/,/^# END_Backup/d" /etc/crontab
  37. service cron restart
  38. sleep 1
  39. echo " Please Wait"
  40. clear
  41. echo " Autobackup Has Been Stopped"
  42. exit 0
  43. }
  44. clear
  45. echo -e " =============================="
  46. echo -e " Autobackup Data "
  47. echo -e " =============================="
  48. echo -e " Status $sts"
  49. echo -e " 1. Start Autobackup"
  50. echo -e " 2. Stop Autobackup"
  51. echo -e " Press CTRL+C to return"
  52. read -rp " Please Enter The Correct Number : " -e num
  53. if [[ "$num" = "1" ]]; then
  54. start
  55. elif [[ "$num" = "2" ]]; then
  56. stop
  57. else
  58. clear
  59. echo " You Entered The Wrong Number"
  60. menu
  61. fi