1
0
Pārlūkot izejas kodu

PVE backup script based on PBS with new web design

pmacko 2 dienas atpakaļ
vecāks
revīzija
42d960c6a8
1 mainītis faili ar 203 papildinājumiem un 0 dzēšanām
  1. 203 0
      pbs_backup.sh

+ 203 - 0
pbs_backup.sh

@@ -0,0 +1,203 @@
+#!/bin/bash
+#########################################################################
+#                 Script for extract PBS backup VM status               #
+#                      Created by Pavol Macko - DoIT                    #
+#                                 ver 0.2                               #
+#########################################################################
+
+#---------------------------- VARIABLES --------------------------------#
+FLD="/var/www/backup"
+test -d $FLD || mkdir $FLD
+WEB="$FLD/index.html"
+
+#--------------------------- EXTRACT-PBS -------------------------------#
+/home/pbs_backup.py > /dev/null 2>&1
+
+#-------------------------- GENERATE-DATA ------------------------------#
+gendata(){
+echo -e "\e[1;32mSUMMARY\e[0m of \e[1;36mALL\e[0m extracted VM virtual server \e[1;35mbackups\e[0m from server \e[1;33mPBS\e[0m "
+echo "--- --------- ------- ------- ------- ---------- --------------" > /tmp/pbs.log
+echo "VID HOSTNAME NODE HDD(MB) BACKUPS BCK-DATE BCK-TIME" >> /tmp/pbs.log
+echo "--- --------- ------- ------- ------- ---------- --------------" >> /tmp/pbs.log
+LST=$(cat /tmp/pbs.tmp | sed 's/,/ /g'| awk '{print $1}' | sort)
+for i in $LST;
+do
+HOST=$(cat /tmp/pbs.tmp | grep -w $i | sed 's/,/ /g' | awk '{print $2}')
+NODE=$(cat /tmp/pbs.tmp | grep -w $i | sed 's/,/ /g' | awk '{print $3}')
+SIB=$(cat /tmp/pbs.tmp | grep -w $i | sed 's/,/ /g' | awk '{print $4}')
+SIZE=$(($SIB/1024/1024))
+COUNT=$(cat /tmp/pbs.tmp | grep -w $i | sed 's/,/ /g' | awk '{print $5}')
+LAST=$(cat /tmp/pbs.tmp | grep -w $i | sed 's/,/ /g' | awk '{print $NF}')
+echo "$i $HOST $NODE $SIZE $COUNT $LAST" >> /tmp/pbs.log
+done
+echo "--- --------- ------- ------- ------- ---------- --------------" >> /tmp/pbs.log
+sed -i '/vmid/d' /tmp/pbs.log
+}
+
+#-------------------------- GENERATE-WEB -------------------------------#
+genweb(){
+  cat > $WEB <<EOG
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>PBS Backup</title>
+  <style>
+    :root {
+      --bg: #111827;
+      --card-bg: #1f2937;
+      --border: #374151;
+      --text: #f9fafb;
+      --text-muted: #9ca3af;
+      --accent: #e57008;
+      --hover: #2d3748;
+      --badge-bg: #374151;
+    }
+    body {
+      font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
+      background-color: var(--bg);
+      color: var(--text);
+      margin: 0;
+      padding: 2rem;
+      display: flex;
+      justify-content: center;
+    }
+    .container {
+      width: 100%;
+      max-width: 1200px;
+    }
+    .header {
+      display: flex;
+      justify-content: space-between;
+      align-items: center;
+      margin-bottom: 1.5rem;
+      border-bottom: 2px solid var(--accent);
+      padding-bottom: 0.75rem;
+    }
+    h1 {
+      margin: 0;
+      font-size: 1.5rem;
+      font-weight: 600;
+      display: flex;
+      align-items: center;
+      gap: 0.5rem;
+    }
+    h1 span {
+      color: var(--accent);
+    }
+    .table-wrapper {
+      background: var(--card-bg);
+      border-radius: 8px;
+      overflow-x: auto;
+      border: 1px solid var(--border);
+      box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
+    }
+    table {
+      width: 100%;
+      border-collapse: collapse;
+      text-align: left;
+      font-size: 0.9rem;
+    }
+    th {
+      background-color: #111827;
+      color: var(--text-muted);
+      font-weight: 600;
+      text-transform: uppercase;
+      font-size: 0.75rem;
+      letter-spacing: 0.05em;
+      padding: 0.85rem 1rem;
+      border-bottom: 1px solid var(--border);
+    }
+    td {
+      padding: 0.85rem 1rem;
+      border-bottom: 1px solid var(--border);
+      white-space: nowrap;
+    }
+    tr:last-child td {
+      border-bottom: none;
+    }
+    tr:hover {
+      background-color: var(--hover);
+    }
+    .vid {
+      font-weight: 700;
+      background: var(--badge-bg);
+      padding: 0.2rem 0.5rem;
+      border-radius: 4px;
+      font-size: 0.85rem;
+    }
+    .hostname {
+      font-weight: 600;
+      color: #60a5fa;
+    }
+    .node {
+      color: #34d399;
+      font-weight: 500;
+    }
+    .footer {
+      margin-top: 1rem;
+      text-align: center;
+      font-size: 0.8rem;
+      color: var(--text-muted);
+    }
+  </style>
+</head>
+<body>
+  <div class="container">
+    <div class="header">
+      <h1>Proxmox Backup Server <span>Status</span></h1>
+      <div>Server: <strong>PBS</strong></div>
+    </div>
+    <div class="table-wrapper">
+      <table>
+        <thead>
+          <tr>
+            <th>VID</th>
+            <th>Hostname</th>
+            <th>Node</th>
+            <th>HDD (MB)</th>
+            <th>Backups</th>
+            <th>Last Backup</th>
+          </tr>
+        </thead>
+        <tbody>
+EOG
+  while read -r line; do
+    if [[ "$line" =~ ^[0-9]+ ]]; then
+      read -r vid whost wnode wsize wcount wlast_date wlast_time <<< "$line"
+      wlast_date="${wlast_date//T/ }"
+      wlast="$wlast_date ${wlast_time:-}"
+      cat >> $WEB <<EOF
+          <tr>
+            <td><span class="vid">$vid</span></td>
+            <td class="hostname">$whost</td>
+            <td class="node">$wnode</td>
+            <td>$wsize</td>
+            <td>$wcount</td>
+            <td>$wlast</td>
+          </tr>
+EOF
+    fi
+  done < /tmp/pbs.log
+  cat >> $WEB <<EOX
+        </tbody>
+      </table>
+    </div>
+    <div class="footer">
+      Generated: $(date +'%d.%m.%Y %H:%M:%S')
+    </div>
+  </div>
+</body>
+</html>
+EOX
+}
+
+#------------------------------- CORE ----------------------------------#
+rm -rf /tmp/pveb*
+echo ""
+gendata
+genweb
+sed -i -E 's/([0-9])T([0-9])/\1 \2/g' /tmp/pbs.log
+cat /tmp/pbs.log | column -t
+echo -e "- \e[1;32mGenerating\e[0m web report [\e[1;33m$WEB\e[0m]"