autobackup.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/bash
  2. # SL
  3. # ==========================================
  4. # Color
  5. RED='\033[0;31m'
  6. NC='\033[0m'
  7. GREEN='\033[0;32m'
  8. ORANGE='\033[0;33m'
  9. BLUE='\033[0;34m'
  10. PURPLE='\033[0;35m'
  11. CYAN='\033[0;36m'
  12. LIGHT='\033[0;37m'
  13. # ==========================================
  14. # Getting
  15. clear
  16. IP=$(wget -qO- ipinfo.io/ip);
  17. date=$(date +"%Y-%m-%d");
  18. 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"
  19. Info="${Green_font_prefix}[ON]${Font_color_suffix}"
  20. Error="${Red_font_prefix}[OFF]${Font_color_suffix}"
  21. cek=$(grep -c -E "^# BEGIN_Backup" /etc/crontab)
  22. if [[ "$cek" = "1" ]]; then
  23. sts="${Info}"
  24. else
  25. sts="${Error}"
  26. fi
  27. function start() {
  28. email=$(cat /home/email)
  29. if [[ "$email" = "" ]]; then
  30. echo "Please enter your email"
  31. read -rp "Email : " -e email
  32. cat <<EOF>>/home/email
  33. $email
  34. EOF
  35. fi
  36. cat << EOF >> /etc/crontab
  37. # BEGIN_Backup
  38. 5 0 * * * root backup
  39. # END_Backup
  40. EOF
  41. service cron restart
  42. sleep 1
  43. echo " Please Wait"
  44. clear
  45. echo " Autobackup Has Been Started"
  46. echo " Data Will Be Backed Up Automatically at 00:05 GMT +7"
  47. exit 0
  48. }
  49. function stop() {
  50. email=$(cat /home/email)
  51. sed -i "/^$email/d" /home/email
  52. sed -i "/^# BEGIN_Backup/,/^# END_Backup/d" /etc/crontab
  53. service cron restart
  54. sleep 1
  55. echo " Please Wait"
  56. clear
  57. echo " Autobackup Has Been Stopped"
  58. exit 0
  59. }
  60. function gantipenerima() {
  61. rm -rf /home/email
  62. echo "Please enter your email"
  63. read -rp "Email : " -e email
  64. cat <<EOF>>/home/email
  65. $email
  66. EOF
  67. }
  68. function gantipengirim() {
  69. echo "Please enter your email"
  70. read -rp "Email : " -e email
  71. echo "Please enter your Password email"
  72. read -rp "Password : " -e pwdd
  73. rm -rf /etc/msmtprc
  74. cat<<EOF>>/etc/msmtprc
  75. defaults
  76. tls on
  77. tls_starttls on
  78. tls_trust_file /etc/ssl/certs/ca-certificates.crt
  79. account default
  80. host smtp.gmail.com
  81. port 587
  82. auth on
  83. user $email
  84. from $email
  85. password $pwdd
  86. logfile ~/.msmtp.log
  87. EOF
  88. }
  89. function testemail() {
  90. email=$(cat /home/email)
  91. if [[ "$email" = "" ]]; then
  92. start
  93. fi
  94. email=$(cat /home/email)
  95. echo -e "
  96. Ini adalah isi email percobaaan kirim email dari vps
  97. IP VPS : $IP
  98. Tanggal : $date
  99. " | mail -s "Percobaan Pengiriman Email" $email
  100. }
  101. clear
  102. echo -e "=============================="
  103. echo -e " Autobackup Data $sts "
  104. echo -e "=============================="
  105. echo -e "1. Start Autobackup"
  106. echo -e "2. Stop Autobackup"
  107. echo -e "3. Ganti Email Penerima"
  108. echo -e "4. Ganti Email Pengirim"
  109. echo -e "5. Test kirim Email"
  110. echo -e "=============================="
  111. read -rp "Please Enter The Correct Number : " -e num
  112. case $num in
  113. 1)
  114. start
  115. ;;
  116. 2)
  117. stop
  118. ;;
  119. 3)
  120. gantipenerima
  121. ;;
  122. 4)
  123. gantipengirim
  124. ;;
  125. 5)
  126. testemail
  127. ;;
  128. *)
  129. clear
  130. ;;
  131. esac