1
0

pve_backup.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #!/bin/bash
  2. #########################################################################
  3. # Script for extract PVE backup VM status II #
  4. # Created by Pavol Macko - DoIT #
  5. # ver 0.3 #
  6. #########################################################################
  7. #---------------------------- VARIABLES --------------------------------#
  8. SRC="usb"
  9. SRV=$(hostname -s)
  10. FLD="/var/www/backup"
  11. test -d $FLD || mkdir $FLD
  12. WEB="$FLD/index.html"
  13. test -d /mnt/pve/$SRC/ || echo -e "- \e[1;31mWrong\e[0m source variable [\e[1;36m$SRC\e[0m]"
  14. test -d /mnt/pve/$SRC/ || exit 1
  15. #------------------------------- DATE ----------------------------------#
  16. aid(){
  17. date +%s
  18. }
  19. #--------------------------- EXTRACT-ALL -------------------------------#
  20. extall(){
  21. echo -e " \e[1;32mACTUAL SUMMARY\e[0m of \e[1;36mALL\e[0m extracted PROXMOX virtual server \e[1;35mbackups\e[0m from server \e[1;33m$SRV\e[0m "
  22. echo "---------- --------- ---------- ---------- ---------- -------- -------- -------- ----------" > /tmp/pveb.log
  23. echo "AUTOID HOSTNAME START-DATE START-TIME END-DATE END-TIME HDD-SIZE BCK-SIZE DUR" >> /tmp/pveb.log
  24. echo "---------- --------- ---------- ---------- ---------- -------- -------- -------- ----------" >> /tmp/pveb.log
  25. LST=$(ls /mnt/pve/$SRC/dump/*.log)
  26. for i in $LST;
  27. do
  28. SDAT=$(cat $i | grep "VM Name" | awk '{print $1}')
  29. STIM=$(cat $i | grep "VM Name" | awk '{print $2}')
  30. HST=$(cat $i | grep "VM Name" | awk '{print $NF}')
  31. DSK=$(cat $i | grep "include disk" | egrep -v "efidisk|tpmstat" | awk '{print $NF}')
  32. ARC=$(cat $i | grep "archive file" | awk '{print $NF}')
  33. DUR=$(cat $i | grep "Finished" | awk '{print $NF}')
  34. FDAT=$(cat $i | grep "Finished" | awk '{print $1}')
  35. FTIM=$(cat $i | grep "Finished" | awk '{print $2}')
  36. echo "$(aid) $HST $SDAT $STIM $FDAT $FTIM $DSK $ARC $DUR" | awk 'NF >= 2' >> /tmp/pveb.log
  37. sleep 1
  38. done
  39. echo "---------- --------- ---------- ---------- ---------- -------- -------- -------- ----------" >> /tmp/pveb.log
  40. sed -i 's/(//g' /tmp/pveb.log
  41. sed -i 's/)//g' /tmp/pveb.log
  42. }
  43. #-------------------------- GENERATE-WEB -------------------------------#
  44. extweb(){
  45. cat > $WEB <<EOG
  46. <!DOCTYPE html>
  47. <html lang="sk">
  48. <head>
  49. <meta charset="UTF-8">
  50. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  51. <title>$SRV Backup</title>
  52. <style>
  53. :root {
  54. --bg: #111827;
  55. --card-bg: #1f2937;
  56. --border: #374151;
  57. --text: #f9fafb;
  58. --text-muted: #9ca3af;
  59. --accent: #e57008;
  60. --hover: #2d3748;
  61. }
  62. body {
  63. font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  64. background-color: var(--bg);
  65. color: var(--text);
  66. margin: 0;
  67. padding: 2rem;
  68. display: flex;
  69. justify-content: center;
  70. }
  71. .container {
  72. width: 100%;
  73. max-width: 1200px;
  74. }
  75. .header {
  76. display: flex;
  77. justify-content: space-between;
  78. align-items: center;
  79. margin-bottom: 1.5rem;
  80. border-bottom: 2px solid var(--accent);
  81. padding-bottom: 0.75rem;
  82. }
  83. h1 {
  84. margin: 0;
  85. font-size: 1.5rem;
  86. font-weight: 600;
  87. display: flex;
  88. align-items: center;
  89. gap: 0.5rem;
  90. }
  91. h1 span {
  92. color: var(--accent);
  93. }
  94. .table-wrapper {
  95. background: var(--card-bg);
  96. border-radius: 8px;
  97. overflow-x: auto;
  98. border: 1px solid var(--border);
  99. box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  100. }
  101. table {
  102. width: 100%;
  103. border-collapse: collapse;
  104. text-align: left;
  105. font-size: 0.9rem;
  106. }
  107. th {
  108. background-color: #111827;
  109. color: var(--text-muted);
  110. font-weight: 600;
  111. text-transform: uppercase;
  112. font-size: 0.75rem;
  113. letter-spacing: 0.05em;
  114. padding: 0.85rem 1rem;
  115. border-bottom: 1px solid var(--border);
  116. }
  117. td {
  118. padding: 0.85rem 1rem;
  119. border-bottom: 1px solid var(--border);
  120. white-space: nowrap;
  121. }
  122. tr:last-child td {
  123. border-bottom: none;
  124. }
  125. tr:hover {
  126. background-color: var(--hover);
  127. }
  128. .hostname {
  129. font-weight: 600;
  130. color: #60a5fa;
  131. }
  132. .footer {
  133. margin-top: 1rem;
  134. text-align: center;
  135. font-size: 0.8rem;
  136. color: var(--text-muted);
  137. }
  138. </style>
  139. </head>
  140. <body>
  141. <div class="container">
  142. <div class="header">
  143. <h1>PVE <span>Backup Report</span></h1>
  144. <div>Server: <strong>$SRV</strong></div>
  145. </div>
  146. <div class="table-wrapper">
  147. <table>
  148. <thead>
  149. <tr>
  150. <th>Hostname</th>
  151. <th>Start Date</th>
  152. <th>Start Time</th>
  153. <th>End Date</th>
  154. <th>End Time</th>
  155. <th>HDD Size</th>
  156. <th>Bck Size</th>
  157. <th>Duration</th>
  158. </tr>
  159. </thead>
  160. <tbody>
  161. EOG
  162. while read -r line; do
  163. if [[ "$line" =~ ^[0-9]+ ]]; then
  164. read -r _ hst sdate stime edate etime hsize bsize dura <<< "$line"
  165. cat >> $WEB <<EOF
  166. <tr>
  167. <td class="hostname">$hst</td>
  168. <td>$sdate</td>
  169. <td>$stime</td>
  170. <td>$edate</td>
  171. <td>$etime</td>
  172. <td>$hsize</td>
  173. <td>$bsize</td>
  174. <td>$dura</td>
  175. </tr>
  176. EOF
  177. fi
  178. done < /tmp/pveb.log
  179. cat >> $WEB <<EOX
  180. </tbody>
  181. </table>
  182. </div>
  183. <div class="footer">
  184. Generated: $(date +'%d.%m.%Y %H:%M:%S')
  185. </div>
  186. </div>
  187. </body>
  188. </html>
  189. EOX
  190. }
  191. #------------------------------- CORE ----------------------------------#
  192. rm -rf /tmp/pveb*
  193. echo ""
  194. extall
  195. extweb
  196. cat /tmp/pveb.log | column -t
  197. echo -e "- \e[1;32mGenerating\e[0m web report [\e[1;33m$WEB\e[0m]"