Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. HOST=`hostname -s`
  4. CONFIG=`dirname ${0}`"/submit.cf"
  5. BCC=""
  6. SUBJECT="Daily Backup on ${HOST}"
  7. NAME="server "`uname -n`
  8.  
  9. M_BODY=""
  10. D_NOW=`/bin/date +%c`
  11.  
  12. W_DAY=`/bin/date +%A`
  13.  
  14. if [[ "$W_DAY" = "Monday" ]]
  15. then
  16. Y_DAY=`date +%Y-%b-%d -d "Today - 2 days"`
  17. else
  18. Y_DAY=`date +%A -d "Today - 1 day"`
  19. fi
  20.  
  21. err_msg ()
  22. {
  23. EMSG=" ERROR Detected while running backup for ${D_SET}"
  24. M_BODY="${M_BODY}"$'\n'$'\n'" -- "$'\n'$'\n'"${EMSG}"$'\n'$'\n'" ${1} --"
  25. SUBJECT="ERROR: Daily Backup on ${HOST}"
  26. }
  27.  
  28. snd_email ()
  29. {
  30. BODY=$1
  31.  
  32. echo -e "To: ${TO}
  33. Cc: ${CC}
  34. Bcc: ${BCC}
  35. Subject: ${SUBJECT}
  36. User-Agent: Heirloom mailx 12.4 7/29/08
  37. MIME-Version: 1.0
  38. Content-Type: text/plain; charset=us-ascii
  39. Content-Transfer-Encoding: 7bit
  40.  
  41.  
  42. Daily Backup on ${HOST} completed with the following messages
  43.  
  44. ${BODY}
  45.  
  46. -- Linux automated notification script
  47.  
  48. "|/usr/sbin/sendmail -vt -f${FROM} -C${CONFIG}
  49.  
  50. }
  51.  
  52. EMSG=""
  53. M_BODY=""
  54. for D_SET in $*
  55. do
  56.  
  57. if [[ -z "${D_SET}" ]]
  58. then
  59. err_msg "Filesystem argument is NULL"
  60. continue
  61. fi
  62. ZFS_1=`/sbin/zfs get -H type ${D_SET}|cut -d $'\t' -f 1`
  63. if [[ ${ZFS_1} != ${D_SET} ]]
  64. then
  65. err_msg "Argument is NOT a ZFS filesystem name"
  66. continue
  67. fi
  68. if [[ -n `/sbin/zfs list -H -t snapshot ${D_SET}@${W_DAY}` ]]
  69. then
  70. /sbin/zfs destroy -r ${D_SET}@${W_DAY}
  71. if [[ "${?}" -ne "0" ]]
  72. then
  73. err_msg "Failure destroying existing snapshots for ${D_SET}@${W_DAY}"
  74. continue
  75. fi
  76. fi
  77. /sbin/zfs snapshot -r ${D_SET}@${W_DAY}
  78. if [[ "${?}" -ne "0" ]]
  79. then
  80. err_msg "Failure creating zfs snapshots for ${D_SET}@${W_DAY}"
  81. continue
  82. fi
  83. ssh gemini "/sbin/zfs destroy -r ${D_SET}@${W_DAY}"
  84. if [[ "${?}" -ne "0" ]]
  85. then
  86. err_msg "Failure Destroying snapshots on gemini for ${D_SET}@${W_DAY}"
  87. fi
  88. /sbin/zfs send -R -i ${D_SET}@${Y_DAY} ${D_SET}@${W_DAY}| nc -w 200 gemini 8023
  89. if [[ "${?}" -ne "0" ]]
  90. then
  91. err_msg "Failure sending zfs incremental snapshots to gemini for ${D_SET}@${W_DAY}"
  92. continue
  93. fi
  94. LOC_N=`/sbin/zfs list -r -t snapshot ${D_SET}| grep @${W_DAY}|wc -l`
  95. LOC_R=`ssh gemini "/sbin/zfs list -r -t snapshot ${D_SET}| grep @${W_DAY}|wc -l"`
  96. if [[ "${LOC_N}" -ne "${LOC_R}" ]]
  97. then
  98. err_msg "Error, snapshot count inconsistency between atlas & gemini for ${D_SET}@${W_DAY}; atlas=${LOC_N} , gemini=${LOC_R}"
  99. continue
  100. fi
  101.  
  102. if [[ "${EMSG}K" = "K" ]]
  103. then
  104. M_BODY="${M_BODY}"$'\n'$'\n'" No problems were detected for backup of ${D_SET}.(atlas=${LOC_N} , gemini=${LOC_R}) "$'\n'" The backed up data as of ${D_NOW} is found in"$'\n'" .zfs/snapshot/${W_DAY}"
  105. ssh gemini 'echo "pass" > /var/lib/zfs-scripts/daily.status'
  106. else
  107. M_BODY="${M_BODY}"$'\n'$'\n'" ATTENTION: Errors were detected for backup of ${D_SET}.(atlas=${LOC_N} , gemini=${LOC_R}) "$'\n'" The backed up data as of ${D_NOW} is found in"$'\n'" .zfs/snapshot/${W_DAY}"
  108. ssh gemini 'echo "fail" > /var/lib/zfs-scripts/daily.status'
  109. fi
  110.  
  111. done
  112.  
  113. snd_email "$M_BODY"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement