how to batch delete snapshot in command ?

chchang

Well-Known Member
Feb 6, 2018
33
4
48
47
let`s say I have a VM with several snapshot created by pve-autosnap (https://github.com/kvaps/pve-autosnap)

E8joGn1.png

for some reason , I need to move the disk to another storage , so I try to use shell to delete the snapshot first.

root@empmv02:/zpssd480/images/113# qm listsnapshot 105 | awk {'print $1'} |xargs
autodaily190213 autodaily190216 init_clone autodaily190218 autodaily190214 autodaily190212 autodaily190217 ansible24_with_python2_and_python3 autodaily190215 current
root@empmv02:/zpssd480/images/113# qm listsnapshot 105 | awk {'print $1'} |xargs qm delsnapshot 105
400 too many arguments
qm delsnapshot <vmid> <snapname> [OPTIONS]
xargs: qm: exited with status 255; aborting

and then I try
qm delsnapshot 105 autodaily{12..20}

still the same error : 400 too many arguments

so , I`m wondering , is there any way to batch delete snapshot in shell or maybe in GUI ?
 
Hi,

xargs need the -n1 flag to separate the output

qm listsnapshot 105 | awk {'print $1'} |xargs -n1 qm delsnapshot 105
 
  • Like
Reactions: misku and chchang
Seems the output format of listsnapshot changed, here is an updated variant with the option to preserve the most recent snapshots:

qm listsnapshot 101 | awk {'print $2'} | head -n -3 | xargs -n1 qm delsnapshot 101
 
thanks for the update! also if you want todo this with LXC containers use pct instead of qm:
pct listsnapshot 101 | awk {'print $2'} | head -n -3 | xargs -n1 pct delsnapshot 101