
这样描述清楚多了。
+ check_src_lv() + { + lvdisplay $1 > /dev/null || exit 1
exit 1 => exit 一般使用原始命令的exit code
+ } + + clone_boot_lv_from_src_lv() + { + src_lv=$1 + boot_lv=$2
src_lv == boot_lv 的情况下,需要跳过,直接返回
+ lvremove -f ${boot_lv}
-f => --force 描述更清楚点
+ lvcreate ${boot_lv} from ${src_lv} || exit 1
from => --snapshot 这里可以使用原始命令选项,不长,而且更清晰明了
+ } + + no_save_no_use() + { + src_lv="/dev/mapper/os-openeuler_aarch64_20.03_${timestamp}" + boot_lv="/dev/mapper/os-openeuler_aarch64_20.03" + + copy_nfsroot_to_src_lv ${src_lv}
copy_nfsroot_to_src_lv => rsync_to
+ clone_boot_lv_from_src_lv ${src_lv} ${boot_lv}
clone_boot_lv_from_src_lv => snapshot_to
+ boot_from_lv ${boot_lv} + } + + only_save() + { + src_lv="/dev/mapper/os-openeuler_aarch64_20.03_${timestamp}" + boot_lv="/dev/mapper/os-openeuler_aarch64_20.03_${save_root_partition}" + + copy_nfsroot_to_src_lv ${src_lv} + clone_boot_lv_from_src_lv ${src_lv} ${boot_lv} + boot_from_lv ${boot_lv} + } + + only_use() + { + src_lv="/dev/mapper/os-openeuler_aarch64_20.03_${use_root_partition}" + boot_lv="/dev/mapper/os-openeuler_aarch64_20.03" + + check_src_lv ${src_lv} + clone_boot_lv_from_src_lv ${src_lv} ${boot_lv} + boot_from_lv ${boot_lv} + } + + save_and_use() + { + src_lv="/dev/mapper/os-openeuler_aarch64_20.03_${use_root_partition}" + boot_lv="/dev/mapper/os-openeuler_aarch64_20.03_${save_root_partition}" + + check_src_lv ${src_lv} + clone_boot_lv_from_src_lv ${src_lv} ${boot_lv} + boot_from_lv ${boot_lv} + } + + main() + { + [ -z ${use_root_partition} ] && [ -z ${save_root_partition} ] && no_save_no_use + + [ -z ${use_root_partition} ] && [ -n ${save_root_partition} ] && only_save + + [ -n ${use_root_partition} ] && [ -z ${save_root_partition} ] && only_use + + [ -n ${use_root_partition} ] && [ -n ${save_root_partition} ] && save_and_use
clone_boot_lv_from_src_lv ${src_lv} ${boot_lv} boot_lv ${boot_lv} 都是公共行为,可以放这里来
+ } + + main() ```
4. execute the job -- 2.23.0