mirror of
https://github.com/YunoHost/package_check.git
synced 2024-09-03 20:06:20 +02:00
Implement ynh_lxc_snapshot_create
This commit is contained in:
parent
89f88521df
commit
822abcaa91
2 changed files with 33 additions and 11 deletions
32
lib/ynh_lxd
32
lib/ynh_lxd
|
@ -216,6 +216,38 @@ ynh_lxc_snapshot_exists () {
|
|||
lxc list --format json | jq -e --arg name $name --arg snapname $snapname '.[] | select(.name==$name) | .snapshots[] | select(.name==$snapname)' >/dev/null
|
||||
}
|
||||
|
||||
# Create a snapshot of an LXC container
|
||||
#
|
||||
# usage: ynh_lxc_snapshot_create --name=name --snapname=snapname
|
||||
# | arg: -n, --name= - name of the LXC
|
||||
# | arg: -s, --snapname= - name of the snapshot
|
||||
#
|
||||
# Requires YunoHost version *.*.* or higher.
|
||||
ynh_lxc_snapshot_create () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=ns
|
||||
local -A args_array=([n]=name= [s]=snapname=)
|
||||
local name
|
||||
local snapname
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
# Remove swap files to avoid killing the CI with huge snapshots.
|
||||
ynh_lxc_swapfiles_clean --name=$name
|
||||
|
||||
ynh_lxc_stop --name=$name
|
||||
|
||||
# Check if the snapshot already exist
|
||||
if ! ynh_lxc_snapshot_exists --name=$name --snapname="$snapname"
|
||||
then
|
||||
log_info "(Creating snapshot $snapname ...)"
|
||||
lxc snapshot $name $snapname
|
||||
else
|
||||
log_info "(Recreating snapshot $snapname ...)"
|
||||
lxc snapshot $name $snapname --reuse
|
||||
fi
|
||||
}
|
||||
|
||||
# Load a snapshot of an LXC container
|
||||
#
|
||||
# usage: ynh_lxc_snapshot_load --name=name --snapname=snapname
|
||||
|
|
|
@ -237,17 +237,7 @@ ynh_lxc_pc_snapshot_create () {
|
|||
# Check all the witness files, to verify if them still here
|
||||
ynh_lxc_pc_witness_files_check --name=$name >&2
|
||||
|
||||
# Remove swap files to avoid killing the CI with huge snapshots.
|
||||
ynh_lxc_swapfiles_clean --name=$name
|
||||
|
||||
ynh_lxc_stop --name=$name
|
||||
|
||||
# Check if the snapshot already exist
|
||||
if ! ynh_lxc_snapshot_exists --name=$name --snapname="$snapname"
|
||||
then
|
||||
log_info "(Creating snapshot $snapname ...)"
|
||||
lxc snapshot $name $snapname
|
||||
fi
|
||||
ynh_lxc_snapshot_create --name=$name --snapname=$snapname
|
||||
|
||||
_ynh_lxc_start_and_wait --name=$name
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue