0

I am using Xen, and for each of our VM's we have set up a process to create a new snapshot of the VM every morning, with the last seven being kept.

I am now trying to write a script to test restoring the latest snapshot for each VM.

In Xen command line I can get a list of all the snapshots for a given VM using:

xe snapshot-list snapshot-of=${vm_uuid}

which returns seven entires in the following format:

uuid ( RO)                : fc6cb150-b264-830e-4fb9-7fec030e434d
          name-label ( RW): 20220616-0118
    name-description ( RW):
    is-vmss-snapshot ( RO): true

Is there an easy way to find out which is the latest one, as so far all I have to go is the date in the name-label (e.g. 20220616), but the second part of the name (0118) changes with each snapshot, and as far as I can tell I can't use wildcards with the name-label option of xe e.g.

xe snapshot-list snapshot-of=${vm_uuid} name-label=20220616*

IGGt
  • 135
  • 1
  • 8

1 Answers1

0

So I figured this out.

today=$(date +%Y%m%d)

ss_name=$(xe snapshot-list snapshot-of=${vm_uuid} | grep ${today} | awk -F: '{print $2}' | awk '{$1=$1};1')

ss_uuid=$(xe snapshot-list name-label="${ss_name}" | awk '{print $5}') echo $ss_uuid

echo ${ss_uuid}

So while it isn't strictly finding the most recent one, so long as the snapshots contain the current date in the name, and a snapshot was taken today (and there is only one snapshot today), it should work.

IGGt
  • 135
  • 1
  • 8