Remove swap before restoring a snapshot

This commit is contained in:
Kay0u 2021-01-15 14:50:16 +01:00
parent 2ee8d7941f
commit 1a8ca9d37a
No known key found for this signature in database
GPG key ID: AAFEEB16CFA2AE2D

View file

@ -59,6 +59,11 @@ CREATE_LXC_SNAPSHOT () {
LOAD_LXC_SNAPSHOT () { LOAD_LXC_SNAPSHOT () {
local snapname=$1 local snapname=$1
log_debug "Loading snapshot $snapname ..." log_debug "Loading snapshot $snapname ..."
# Remove swap files before restoring the snapshot.
lxc exec $LXC_NAME -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do swapoff $swapfile; done' 2>/dev/null
lxc exec $LXC_NAME -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do rm -f $swapfile; done' 2>/dev/null
timeout 30 lxc stop --timeout 15 $LXC_NAME 2>/dev/null timeout 30 lxc stop --timeout 15 $LXC_NAME 2>/dev/null
lxc restore $LXC_NAME $snapname lxc restore $LXC_NAME $snapname
lxc start $LXC_NAME lxc start $LXC_NAME