From 59b8ab5ce2d1ce9ff032eabfe4268d051b7f128c Mon Sep 17 00:00:00 2001 From: Bastian Date: Fri, 4 Aug 2023 13:38:26 +0200 Subject: [PATCH] added: default pool, feature: confirm --migrate, add: --noconfirm --- crossover | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crossover b/crossover index 80a4cba..dfe1426 100755 --- a/crossover +++ b/crossover @@ -65,6 +65,7 @@ declare opt_destination declare opt_vm_ids='' declare opt_snapshot_prefix='mirror-' declare opt_rewrite='' +declare opt_pool='rbd' declare -i opt_prefix_id declare opt_exclude_vmids='' declare -i opt_debug=0 @@ -76,6 +77,7 @@ declare -i opt_keepdlock=0 declare -i opt_overwrite=0 declare -i opt_online=0 declare -i opt_migrate=0 +declare -i opt_noconfirm=0 declare opt_keep_local='0s' declare opt_keep_remote='0s' @@ -118,7 +120,7 @@ Options: --prefixid Prefix for VMID's on target System [optional] --excludevmids Exclusde VM IDs when using --vmid==all --destination Target PVE Host in target pool. e.g. --destination=pve04 - --pool Ceph pool name in target pool. e.g. --pool=data + --pool Ceph pool name in target pool. e.g. --pool=data [default=rbd] --keeplocal How many additional Snapshots to keep locally. e.g. --keeplocal=2d --keepremote How many additional Snapshots to keep remote. e.g. --keepremote=7d --rewrite PCRE Regex to rewrite the Config Files (eg. --rewrite='s/(net0:)(.*)tag=([0-9]+)/\1\2tag=1/g' would @@ -135,6 +137,7 @@ Switches: --keep-slock Keep source VM locked on Transfer --keep-dlock Keep VM locked after transfer on Destination --overwrite Overwrite Destination + --noconfirm Don't ask for confirmation before starting --migrate mode (use with care!) --debug Show Debug Output Report bugs to @@ -149,7 +152,7 @@ function parse_opts(){ local args args=$(getopt \ --options '' \ - --longoptions=vmid:,prefixid:,excludevmids:,destination:,pool:,keeplocal:,keepremote:,rewrite:,influxurl:,influxorg:,influxtoken:,influxbucket:,jobname:,mail:,online,migrate,nolock,keep-slock,keep-dlock,overwrite,dry-run,debug,syslog \ + --longoptions=vmid:,prefixid:,excludevmids:,destination:,pool:,keeplocal:,keepremote:,rewrite:,influxurl:,influxorg:,influxtoken:,influxbucket:,jobname:,mail:,online,migrate,nolock,keep-slock,keep-dlock,overwrite,dry-run,noconfirm,debug,syslog \ --name "$PROGNAME" \ -- "$@") \ || end_process 128 @@ -175,6 +178,7 @@ function parse_opts(){ --online) opt_online=1; shift ;; --migrate) opt_migrate=1; shift ;; --dry-run) opt_dry_run=1; shift;; + --noconfirm) opt_noconfirm=1; shift;; --debug) opt_debug=1; shift;; --nolock) opt_lock=0; shift;; --keep-slock) opt_keepslock=1; shift;; @@ -435,6 +439,18 @@ function mirror() { scluster=$(grep cluster_name /etc/pve/corosync.conf | cut -d " " -f 4) dcluster=$(ssh "$opt_destination" grep cluster_name /etc/pve/corosync.conf | cut -d " " -f 4) + if [ $opt_migrate -eq 1 ] && [ $opt_noconfirm -eq 0 ]; then + echo "VM(s) $opt_vm_ids will be shutdown on [$scluster] and started on [$dcluster]" + read -p "Do you want to proceed? (yes/no) " yn + case $yn in + yes ) echo ok, we will proceed;; + no ) echo exiting...; + exit;; + * ) echo invalid response; + exit 1;; + esac + fi + map_source_to_destination_vmid map_vmids_to_host map_vmids_to_dsthost "$opt_destination"