Support different syntaxes for lxc incus snapshot create / restore

This commit is contained in:
Salamandar 2024-03-15 16:00:13 +01:00
parent 0998271a98
commit fc79adbed4

View file

@ -64,7 +64,11 @@ LXC_CREATE () {
sleep 3 sleep 3
log_info "Creating initial snapshot $LXC_NAME ..." log_info "Creating initial snapshot $LXC_NAME ..."
$lxc snapshot create $LXC_NAME snap0 if [[ "$lxc" == "lxc" ]]; then
$lxc snapshot $LXC_NAME snap0
else
$lxc snapshot create $LXC_NAME snap0
fi
if [[ -z "$($lxc list $LXC_NAME --format json | jq '.[].snapshots[] | select(.name=="snap0")')" ]] if [[ -z "$($lxc list $LXC_NAME --format json | jq '.[].snapshots[] | select(.name=="snap0")')" ]]
then then
@ -99,7 +103,11 @@ CREATE_LXC_SNAPSHOT () {
if ! LXC_SNAPSHOT_EXISTS "$snapname" if ! LXC_SNAPSHOT_EXISTS "$snapname"
then then
log_info "(Creating snapshot $snapname ...)" log_info "(Creating snapshot $snapname ...)"
$lxc snapshot create $LXC_NAME $snapname if [[ "$lxc" == "lxc" ]]; then
$lxc snapshot $LXC_NAME $snapname
else
$lxc snapshot create $LXC_NAME $snapname
fi
fi fi
_LXC_START_AND_WAIT $LXC_NAME _LXC_START_AND_WAIT $LXC_NAME
@ -118,7 +126,11 @@ LOAD_LXC_SNAPSHOT () {
while [[ ${retry_lxc} -lt 10 ]] while [[ ${retry_lxc} -lt 10 ]]
do do
LXC_STOP $LXC_NAME || true LXC_STOP $LXC_NAME || true
$lxc snapshot restore $LXC_NAME $snapname && break || retry_lxc=$(($retry_lxc+1)) if [[ "$lxc" == "lxc" ]]; then
$lxc restore $LXC_NAME $snapname && break || retry_lxc=$(($retry_lxc+1))
else
$lxc snapshot restore $LXC_NAME $snapname && break || retry_lxc=$(($retry_lxc+1))
fi
log_warning "Failed to restore snapshot? Retrying in 20 sec ..." log_warning "Failed to restore snapshot? Retrying in 20 sec ..."
if [[ ${retry_lxc} -ge 3 ]] if [[ ${retry_lxc} -ge 3 ]]
then then