From 26addc9b5a061d57235703c4e4c5391b322fb9ae Mon Sep 17 00:00:00 2001 From: kneutron <50146127+kneutron@users.noreply.github.com> Date: Fri, 16 Aug 2024 18:36:34 -0600 Subject: [PATCH] added features parallel, ctr --- proxmox/proxmox-list-vm-snapshots.sh | 79 ++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 proxmox/proxmox-list-vm-snapshots.sh diff --git a/proxmox/proxmox-list-vm-snapshots.sh b/proxmox/proxmox-list-vm-snapshots.sh new file mode 100644 index 0000000..f2c46b6 --- /dev/null +++ b/proxmox/proxmox-list-vm-snapshots.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +# 2024.Aug kneutron + +# Feature - parallel process if # of VMs is > 15 +# Feature - now works with either VM / CTR VMID + +# REQUIRES: parallel awk grep + +# arg1 = vmid +if [ "$1" = "" ]; then +# list all; + echo "$(date) - Listing all VM snapshots" +# xxx TODO EDITME - change this if you favor CTR count over VMs +# if [ $(pct list |wc -l) -gt 15 ]; then + if [ $(qm list |wc -l) -gt 15 ]; then +# DONE parallel to sep tmp files, sort and cat + +# create list of VM IDs on thisnode + tmpdir=/dev/shm + vmlistf=$tmpdir/vmlist.infile + ctrlistf=$tmpdir/ctrlist.infile + + para=/usr/bin/parallel +# REF: https://stackoverflow.com/questions/22187834/gnu-parallel-output-each-job-to-a-different-file + [ -e $para ] || apt-get install -y parallel + +# auto cleanup + /bin/rm -f $tmpdir/proxmox-snaplist* "$vmlistf" "$ctrlistf" + +# populate + echo "$(date) - Getting list of VMs" + qm list |grep -v VMID |awk '{print "qm listsnapshot "$1}' > "$vmlistf" + + echo "$(date) - Getting list of CTRs" + pct list |grep -v VMID |awk '{print "pct listsnapshot "$1}' > "$ctrlistf" + + limitt=5 + cd $tmpdir + + echo "$(date) - Processing VM list in parallel" + time cat $vmlistf |$para -j $limitt --results proxmox-snaplist-{}.out + date + + echo "$(date) - Processing CTR list in parallel" + time cat $ctrlistf |$para -j $limitt --results proxmox-snaplist-{}.out + date + +# show filename + tail -n +1 proxmox-snaplist-pct*.out #|less + tail -n +1 proxmox-snaplist-qm*.out #|less + + else + for vmid in $(pct list |grep -v VMID |awk '{print $1}'); do + echo "$(date) === CTR VMID: $vmid" + pct listsnapshot $vmid + done + for vmid in $(qm list |grep -v VMID |awk '{print $1}'); do + echo "$(date) === VMID: $vmid" + qm listsnapshot $vmid + done + fi +else +# we got passed an arg + time qm listsnapshot $1 2>/dev/null || time pct listsnapshot $1 +fi + +# PROTIP: pipe output to awk 'NF>0' to get rid of blank lines + +exit; + +# REF: https://phoenixnap.com/kb/proxmox-delete-vm#ftoc-heading-9 +# qm listsnapshot 126 +`-> b4-nic-change 2024-05-02 17:54:37 powered off! + `-> current You are here! + +# to delete snapshot: +# qm delsnapshot [vmid] [snapshot_name] +# pct delsnapshot [OPTIONS] # for CTR