| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- #!/bin/bash
- #########################################################################
- # Script for extract PVE backup VM status II #
- # Created by Pavol Macko - DoIT #
- # ver 0.3 #
- #########################################################################
- #---------------------------- VARIABLES --------------------------------#
- SRC="usb"
- SRV=$(hostname -s)
- FLD="/var/www/backup"
- test -d $FLD || mkdir $FLD
- WEB="$FLD/index.html"
- test -d /mnt/pve/$SRC/ || echo -e "- \e[1;31mWrong\e[0m source variable [\e[1;36m$SRC\e[0m]"
- test -d /mnt/pve/$SRC/ || exit 1
- #------------------------------- DATE ----------------------------------#
- aid(){
- date +%s
- }
- #--------------------------- EXTRACT-ALL -------------------------------#
- extall(){
- 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 "
- echo "---------- --------- ---------- ---------- ---------- -------- -------- -------- ----------" > /tmp/pveb.log
- echo "AUTOID HOSTNAME START-DATE START-TIME END-DATE END-TIME HDD-SIZE BCK-SIZE DUR" >> /tmp/pveb.log
- echo "---------- --------- ---------- ---------- ---------- -------- -------- -------- ----------" >> /tmp/pveb.log
- LST=$(ls /mnt/pve/$SRC/dump/*.log)
- for i in $LST;
- do
- SDAT=$(cat $i | grep "VM Name" | awk '{print $1}')
- STIM=$(cat $i | grep "VM Name" | awk '{print $2}')
- HST=$(cat $i | grep "VM Name" | awk '{print $NF}')
- DSK=$(cat $i | grep "include disk" | egrep -v "efidisk|tpmstat" | awk '{print $NF}')
- ARC=$(cat $i | grep "archive file" | awk '{print $NF}')
- DUR=$(cat $i | grep "Finished" | awk '{print $NF}')
- FDAT=$(cat $i | grep "Finished" | awk '{print $1}')
- FTIM=$(cat $i | grep "Finished" | awk '{print $2}')
- echo "$(aid) $HST $SDAT $STIM $FDAT $FTIM $DSK $ARC $DUR" | awk 'NF >= 2' >> /tmp/pveb.log
- sleep 1
- done
- echo "---------- --------- ---------- ---------- ---------- -------- -------- -------- ----------" >> /tmp/pveb.log
- sed -i 's/(//g' /tmp/pveb.log
- sed -i 's/)//g' /tmp/pveb.log
- }
- #-------------------------- GENERATE-WEB -------------------------------#
- extweb(){
- cat > $WEB <<EOG
- <!DOCTYPE html>
- <html lang="sk">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>$SRV Backup</title>
- <style>
- :root {
- --bg: #111827;
- --card-bg: #1f2937;
- --border: #374151;
- --text: #f9fafb;
- --text-muted: #9ca3af;
- --accent: #e57008;
- --hover: #2d3748;
- }
- 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);
- }
- .hostname {
- font-weight: 600;
- color: #60a5fa;
- }
- .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>PVE <span>Backup Report</span></h1>
- <div>Server: <strong>$SRV</strong></div>
- </div>
- <div class="table-wrapper">
- <table>
- <thead>
- <tr>
- <th>Hostname</th>
- <th>Start Date</th>
- <th>Start Time</th>
- <th>End Date</th>
- <th>End Time</th>
- <th>HDD Size</th>
- <th>Bck Size</th>
- <th>Duration</th>
- </tr>
- </thead>
- <tbody>
- EOG
- while read -r line; do
- if [[ "$line" =~ ^[0-9]+ ]]; then
- read -r _ hst sdate stime edate etime hsize bsize dura <<< "$line"
- cat >> $WEB <<EOF
- <tr>
- <td class="hostname">$hst</td>
- <td>$sdate</td>
- <td>$stime</td>
- <td>$edate</td>
- <td>$etime</td>
- <td>$hsize</td>
- <td>$bsize</td>
- <td>$dura</td>
- </tr>
- EOF
- fi
- done < /tmp/pveb.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 ""
- extall
- extweb
- cat /tmp/pveb.log | column -t
- echo -e "- \e[1;32mGenerating\e[0m web report [\e[1;33m$WEB\e[0m]"
|