autobackup.sh 1.5 KB

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