Mikrotik_backuper.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env bash
  2. #
  3. #
  4. # Please note that for the correct operation you
  5. # will need the utilities found here
  6. #
  7. #
  8. DIR= # example: DIR=/home/user/backups/
  9. LGIN= # example: LGIN=admin
  10. PRT= # example: PRT=22
  11. #SHELF= # example: SHELF=13
  12. #
  13. DATE=$(echo `date +%Y.%m.%d`)
  14. exec 2>> $DIR$DATE".log"
  15. gg=success
  16. #
  17. ##### DO NOT DELETE COMMENTS IN THE BLOCK BELOW #####
  18. #
  19. # router0
  20. #
  21. #NEWVARIABLE
  22. #
  23. #NEWFUNK
  24. #
  25. function startsaver {
  26. # NEWNAME
  27. }
  28. #
  29. startsaver >> $DIR$DATE.log
  30. #
  31. ##### DO NOT DELETE COMMENTS IN THE BLOCK ABOVE #####
  32. #
  33. #
  34. #
  35. ##### ARCHIVING BACKUPS AND DELETING OLD VERSIONS #####
  36. #
  37. statsave=$(cat $DIR$DATE.log | grep "ERROR \| failed \| denied \| error \| Permission" && echo ERROR || echo success )
  38. #
  39. function archandel {
  40. echo "
  41. _______________________________
  42. Archiving of collected backup's started:"
  43. if [ "$statsave" = "$gg" ]
  44. then
  45. zip -9 -j $DIR$DATE.zip $DIR*.backup $DIR*rsc
  46. rm $DIR*.backup $DIR*.rsc
  47. # echo "
  48. # search and delete old versions"
  49. # find "$DIR"2* -mtime +$SHELF -delete
  50. echo "
  51. Archiving done
  52. _______________________________"
  53. else
  54. echo " ...............................
  55. ERROR
  56. not all backups are received
  57. сheck the correctness
  58. of the entered data
  59. and read the log!
  60. ..............................."
  61. zip -9 -j $DIR$DATE"_brocken".zip $DIR*.backup $DIR*rsc
  62. rm $DIR*.backup $DIR*.rsc
  63. echo " _______________________________"
  64. fi
  65. }
  66. #
  67. archandel >> $DIR$DATE.log
  68. #####_____________________________________________#####
  69. #
  70. #
  71. #
  72. ##### TELEGRAM ALERT SETTINGS #####
  73. #TOKEN=
  74. #IDCHAT=
  75. #URL="https://api.telegram.org/bot$TOKEN/sendMessage"
  76. ##PROXYSOCKS=
  77. ##TGMESS="curl --silent --show-error --fail -k -G -o /dev/null -x socks5://${PROXYSOCKS} ${URL} -d chat_id=${IDCHAT} "
  78. #TGMESS="curl --silent --show-error --fail -k -G -o /dev/null $URL -d chat_id=$IDCHAT "
  79. #Function alerts
  80. #function alert {
  81. # echo " _______________________________
  82. # Alerts are generated"
  83. #if [ "$statsave" = "$gg" ]
  84. # then
  85. # $TGMESS --data-urlencode "text=Creation of backups $DATE was successful"
  86. # echo "END
  87. # _______________________________"
  88. # else
  89. # $TGMESS --data-urlencode "text=An error occurred while creating backups, check the $DATE log"
  90. # echo "END
  91. # _______________________________"
  92. #fi
  93. #}
  94. #####_________________________#####
  95. #alert >> $DIR$DATE.log