mirror of
https://github.com/lephisto/crossover.git
synced 2025-12-06 12:19:20 +01:00
Compare commits
10 Commits
v0.5
...
284cfb6e76
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
284cfb6e76 | ||
|
|
5b7fd4986b | ||
|
|
41abd0429a | ||
|
|
890567ad05 | ||
|
|
f5441f4c0b | ||
|
|
fb5b3a6d09 | ||
|
|
5bf37e886c | ||
|
|
010f04c412 | ||
|
|
13245fdf5e | ||
|
|
ae641a3927 |
82
README.md
82
README.md
@@ -86,6 +86,7 @@ It'll work according this scheme:
|
|||||||
* Retention policy: (eg. keep x snapshots on the source and y snapshots in the destination cluster)
|
* Retention policy: (eg. keep x snapshots on the source and y snapshots in the destination cluster)
|
||||||
* Rewrites VM configurations so they match the new VMID and/or poolname on the destination
|
* Rewrites VM configurations so they match the new VMID and/or poolname on the destination
|
||||||
* Secure an encrypted transfer (SSH), so it's safe to mirror between datacenter without an additional VPN
|
* Secure an encrypted transfer (SSH), so it's safe to mirror between datacenter without an additional VPN
|
||||||
|
* Near live-migrate: To move a VM from one Cluster to another, make an initial copy and re-run with --migrate. This will shutdown the VM on the source cluster and start it on the destination cluster.
|
||||||
|
|
||||||
## Installation of prerequisites
|
## Installation of prerequisites
|
||||||
|
|
||||||
@@ -99,9 +100,9 @@ git clone https://github.com/lephisto/crossover/ /opt
|
|||||||
|
|
||||||
Ensure that you can freely ssh from the Node you plan to mirror _from_ to _all_ nodes in the destination cluster, as well as localhost.
|
Ensure that you can freely ssh from the Node you plan to mirror _from_ to _all_ nodes in the destination cluster, as well as localhost.
|
||||||
|
|
||||||
## Examples
|
## Continuous replication between Clusters
|
||||||
|
|
||||||
Mirror VM to another Cluster:
|
Example 1: Mirror VM to another Cluster:
|
||||||
|
|
||||||
```
|
```
|
||||||
root@pve01:~/crossover# ./crossover mirror --vmid=all --prefixid=99 --excludevmids=101 --destination=pve04 --pool=data2 --overwrite --online
|
root@pve01:~/crossover# ./crossover mirror --vmid=all --prefixid=99 --excludevmids=101 --destination=pve04 --pool=data2 --overwrite --online
|
||||||
@@ -136,12 +137,89 @@ Full xmitted..........: 0 byte
|
|||||||
Differential Bytes ...: 372.96 KiB
|
Differential Bytes ...: 372.96 KiB
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This example creates a mirror of VM 100 (in the source cluster) as VM 10100 (in the destination cluster) using the ceph pool "data2" for storing all attached disks. It will keep 4 Ceph snapshots prior the latest (in total 5) and 8 snapshots on the remote cluster. It will keep the VM on the target Cluster locked to avoid an accidental start (thus causing split brain issues), and will do it even if the source VM is running.
|
This example creates a mirror of VM 100 (in the source cluster) as VM 10100 (in the destination cluster) using the ceph pool "data2" for storing all attached disks. It will keep 4 Ceph snapshots prior the latest (in total 5) and 8 snapshots on the remote cluster. It will keep the VM on the target Cluster locked to avoid an accidental start (thus causing split brain issues), and will do it even if the source VM is running.
|
||||||
|
|
||||||
The use case is that you might want to keep a cold-standby copy of a certain VM on another Cluster. If you need to start it on the target cluster you just have to unlock it with `qm unlock VMID` there.
|
The use case is that you might want to keep a cold-standby copy of a certain VM on another Cluster. If you need to start it on the target cluster you just have to unlock it with `qm unlock VMID` there.
|
||||||
|
|
||||||
Another usecase could be that you want to migrate a VM from one cluster to another with the least downtime possible. Real live migration that you are used to inside one cluster is hard to achive cross-cluster, but you can easily make an initial migration while the VM is still running on the source cluster (fully transferring the block devices), shut it down on source, run the mirror process again (which is much faster now because it only needs to transfer the diff since the initial snapshot) and start it up on the target cluster. This way the migration basically takes one boot plus a few seconds for transferring the incremental snapshot.
|
Another usecase could be that you want to migrate a VM from one cluster to another with the least downtime possible. Real live migration that you are used to inside one cluster is hard to achive cross-cluster, but you can easily make an initial migration while the VM is still running on the source cluster (fully transferring the block devices), shut it down on source, run the mirror process again (which is much faster now because it only needs to transfer the diff since the initial snapshot) and start it up on the target cluster. This way the migration basically takes one boot plus a few seconds for transferring the incremental snapshot.
|
||||||
|
|
||||||
|
## Near-live Migration
|
||||||
|
|
||||||
|
To minimize downtime and achive a near-live Migration from one Cluster to another it's recommended to do an initial Sync of a VM from the source to the destination cluster. After that, run the job again, and add the --migrate switch. This causes the source VM to be shut down prior snapshot + transfer, and be restarted on the destination cluster as soon as the incremental transfer is complete. Using --migrate will always try to start the VM on the destination cluster.
|
||||||
|
|
||||||
|
Example 2: Near-live migrate VM from one cluster to another (Run initial replication first, which works online, then run with --migrate to shutdown on source, incrematally copy and start on destination):
|
||||||
|
|
||||||
|
```
|
||||||
|
root@pve01:~/crossover# ./crossover mirror --jobname=migrate --vmid=100 --destination=pve04 --pool=data2 --online
|
||||||
|
ACTION: Onlinemirror
|
||||||
|
Start mirror 2023-04-26 15:02:24
|
||||||
|
VM 100 - Starting mirror for testubuntu
|
||||||
|
VM 100 - Checking for VM 100 on destination cluster pve04 /etc/pve/nodes/*/qemu-server
|
||||||
|
VM 100 - Transmitting Config for to destination pve04 VMID 100
|
||||||
|
VM 100 - locked 100 [rc:0] on source
|
||||||
|
VM 100 - locked 100 [rc:0] on destination
|
||||||
|
VM 100 - Creating snapshot data/vm-100-disk-0@mirror-20230426150224
|
||||||
|
VM 100 - Creating snapshot data/vm-100-disk-1@mirror-20230426150224
|
||||||
|
VM 100 - unlocked source VM 100 [rc:0]
|
||||||
|
VM 100 - F data/vm-100-disk-0@mirror-20230426150224: e:0:09:20 r: c:[36.6MiB/s] a:[36.6MiB/s] 20.0GiB [===============================>] 100%
|
||||||
|
VM 100 - created snapshot on 100 [rc:0]
|
||||||
|
VM 100 - Disk Summary: Took 560 Seconds to transfer 20.00 GiB in a full run
|
||||||
|
VM 100 - F data/vm-100-disk-1@mirror-20230426150224: e:0:00:40 r: c:[50.7MiB/s] a:[50.7MiB/s] 2.00GiB [===============================>] 100%
|
||||||
|
VM 100 - created snapshot on 100 [rc:0]
|
||||||
|
VM 100 - Disk Summary: Took 40 Seconds to transfer 22.00 GiB in a full run
|
||||||
|
VM 100 - Unlocking destination VM 100
|
||||||
|
Finnished mirror 2023-04-26 15:13:47
|
||||||
|
Job Summary: Bytes transferred 22.00 GiB for 2 Disks on 1 VMs in 00 hours 11 minutes 23 seconds
|
||||||
|
VM Freeze OK/failed.......: 1/0
|
||||||
|
RBD Snapshot OK/failed....: 2/0
|
||||||
|
RBD export-full OK/failed.: 2/0
|
||||||
|
RBD export-diff OK/failed.: 0/0
|
||||||
|
Full xmitted..............: 22.00 GiB
|
||||||
|
Differential Bytes .......: 0 Bytes
|
||||||
|
|
||||||
|
root@pve01:~/crossover# ./crossover mirror --jobname=migrate --vmid=100 --destination=pve04 --pool=data2 --online --migrate
|
||||||
|
ACTION: Onlinemirror
|
||||||
|
Start mirror 2023-04-26 15:22:35
|
||||||
|
VM 100 - Starting mirror for testubuntu
|
||||||
|
VM 100 - Checking for VM 100 on destination cluster pve04 /etc/pve/nodes/*/qemu-server
|
||||||
|
VM 100 - Migration requested, shutting down VM on pve01
|
||||||
|
VM 100 - locked 100 [rc:0] on source
|
||||||
|
VM 100 - locked 100 [rc:0] on destination
|
||||||
|
VM 100 - Creating snapshot data/vm-100-disk-0@mirror-20230426152235
|
||||||
|
VM 100 - Creating snapshot data/vm-100-disk-1@mirror-20230426152235
|
||||||
|
VM 100 - I data/vm-100-disk-0@mirror-20230426152235: e:0:00:03 c:[1.29MiB/s] a:[1.29MiB/s] 4.38MiB
|
||||||
|
VM 100 - Housekeeping: localhost data/vm-100-disk-0, keeping Snapshots for 0s
|
||||||
|
VM 100 - Removing Snapshot localhost data/vm-100-disk-0@mirror-20230323162532 (2930293s) [rc:0]
|
||||||
|
VM 100 - Removing Snapshot localhost data/vm-100-disk-0@mirror-20230426144911 (2076s) [rc:0]
|
||||||
|
VM 100 - Removing Snapshot localhost data/vm-100-disk-0@mirror-20230426145632 (1637s) [rc:0]
|
||||||
|
VM 100 - Removing Snapshot localhost data/vm-100-disk-0@mirror-20230426145859 (1492s) [rc:0]
|
||||||
|
VM 100 - Removing Snapshot localhost data/vm-100-disk-0@mirror-20230426150224 (1290s) [rc:0]
|
||||||
|
VM 100 - Housekeeping: pve04 data2/vm-100-disk-0-data, keeping Snapshots for 0s
|
||||||
|
VM 100 - Removing Snapshot pve04 data2/vm-100-disk-0-data@mirror-20230426150224 (1293s) [rc:0]
|
||||||
|
VM 100 - Disk Summary: Took 4 Seconds to transfer 4.37 MiB in a incremental run
|
||||||
|
VM 100 - I data/vm-100-disk-1@mirror-20230426152235: e:0:00:00 c:[ 227 B/s] a:[ 227 B/s] 74.0 B
|
||||||
|
VM 100 - Housekeeping: localhost data/vm-100-disk-1, keeping Snapshots for 0s
|
||||||
|
VM 100 - Removing Snapshot localhost data/vm-100-disk-1@mirror-20230323162532 (2930315s) [rc:0]
|
||||||
|
VM 100 - Removing Snapshot localhost data/vm-100-disk-1@mirror-20230426144911 (2098s) [rc:0]
|
||||||
|
VM 100 - Removing Snapshot localhost data/vm-100-disk-1@mirror-20230426145632 (1659s) [rc:0]
|
||||||
|
VM 100 - Removing Snapshot localhost data/vm-100-disk-1@mirror-20230426145859 (1513s) [rc:0]
|
||||||
|
VM 100 - Removing Snapshot localhost data/vm-100-disk-1@mirror-20230426150224 (1310s) [rc:0]
|
||||||
|
VM 100 - Housekeeping: pve04 data2/vm-100-disk-1-data, keeping Snapshots for 0s
|
||||||
|
VM 100 - Removing Snapshot pve04 data2/vm-100-disk-1-data@mirror-20230426150224 (1313s) [rc:0]
|
||||||
|
VM 100 - Disk Summary: Took 2 Seconds to transfer 4.37 MiB in a incremental run
|
||||||
|
VM 100 - Unlocking destination VM 100
|
||||||
|
VM 100 - Starting VM on pve01
|
||||||
|
Finnished mirror 2023-04-26 15:24:25
|
||||||
|
Job Summary: Bytes transferred 4.37 MiB for 2 Disks on 1 VMs in 00 hours 01 minutes 50 seconds
|
||||||
|
VM Freeze OK/failed.......: 0/0
|
||||||
|
RBD Snapshot OK/failed....: 2/0
|
||||||
|
RBD export-full OK/failed.: 0/0
|
||||||
|
RBD export-diff OK/failed.: 2/0
|
||||||
|
Full xmitted..............: 0 Bytes
|
||||||
|
Differential Bytes .......: 4.37 MiB
|
||||||
|
```
|
||||||
|
|
||||||
## Things to check
|
## Things to check
|
||||||
|
|
||||||
From Proxmox VE Hosts you want to backup you need to be able to ssh passwordless to all other Cluster hosts, that may hold VM's or Containers. This goes for the source and for the destination Cluster.
|
From Proxmox VE Hosts you want to backup you need to be able to ssh passwordless to all other Cluster hosts, that may hold VM's or Containers. This goes for the source and for the destination Cluster.
|
||||||
|
|||||||
96
crossover
96
crossover
@@ -9,13 +9,14 @@ declare opt_influx_api_url=''
|
|||||||
declare opt_influx_token=''
|
declare opt_influx_token=''
|
||||||
declare opt_influx_bucket=''
|
declare opt_influx_bucket=''
|
||||||
declare opt_influx_api_org=''
|
declare opt_influx_api_org=''
|
||||||
|
declare opt_influx_jobname=''
|
||||||
declare opt_influx_job_metrics='crossover_xmit'
|
declare opt_influx_job_metrics='crossover_xmit'
|
||||||
declare opt_influx_summary_metrics='crossover_jobs'
|
declare opt_influx_summary_metrics='crossover_jobs'
|
||||||
|
|
||||||
# Cross Pool Migration and incremental replication Tool for Proxmox VMs using Ceph.
|
# Cross Pool Migration and incremental replication Tool for Proxmox VMs using Ceph.
|
||||||
# Author: Bastian Mäuser <bma@netz.org>
|
# Author: Bastian Mäuser <bma@netz.org>
|
||||||
|
|
||||||
declare -r VERSION=0.5
|
declare -r VERSION=0.7
|
||||||
declare -r NAME=$(basename "$0")
|
declare -r NAME=$(basename "$0")
|
||||||
declare -r PROGNAME=${NAME%.*}
|
declare -r PROGNAME=${NAME%.*}
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ declare -i opt_keepslock=0
|
|||||||
declare -i opt_keepdlock=0
|
declare -i opt_keepdlock=0
|
||||||
declare -i opt_overwrite=0
|
declare -i opt_overwrite=0
|
||||||
declare -i opt_online=0
|
declare -i opt_online=0
|
||||||
|
declare -i opt_migrate=0
|
||||||
declare opt_keep_local='0s'
|
declare opt_keep_local='0s'
|
||||||
declare opt_keep_remote='0s'
|
declare opt_keep_remote='0s'
|
||||||
|
|
||||||
@@ -114,8 +116,10 @@ Options:
|
|||||||
--influxurl Influx API url (e.g. --influxurl=https://your-influxserver.com/api/)
|
--influxurl Influx API url (e.g. --influxurl=https://your-influxserver.com/api/)
|
||||||
--influxtoken Influx API token with write permission
|
--influxtoken Influx API token with write permission
|
||||||
--influxbucket Influx Bucket to write to (e.g. --influxbucket=telegraf/autogen)
|
--influxbucket Influx Bucket to write to (e.g. --influxbucket=telegraf/autogen)
|
||||||
|
--jobname Descriptive name for the job, used in Statistics
|
||||||
Switches:
|
Switches:
|
||||||
--online Allow online Copy
|
--online Allow online Copy
|
||||||
|
--migrate Stop VM on Source Cluster before final Transfer and restart on destination Cluster
|
||||||
--nolock Don't lock source VM on Transfer (mainly for test purposes)
|
--nolock Don't lock source VM on Transfer (mainly for test purposes)
|
||||||
--keep-slock Keep source VM locked on Transfer
|
--keep-slock Keep source VM locked on Transfer
|
||||||
--keep-dlock Keep VM locked after transfer on Destination
|
--keep-dlock Keep VM locked after transfer on Destination
|
||||||
@@ -135,7 +139,7 @@ function parse_opts(){
|
|||||||
local args
|
local args
|
||||||
args=$(getopt \
|
args=$(getopt \
|
||||||
--options '' \
|
--options '' \
|
||||||
--longoptions=vmid:,prefixid:,excludevmids:,destination:,pool:,keeplocal:,keepremote:,rewrite:,influxurl:,influxorg:,influxtoken:,influxbucket:,online,nolock,keep-slock,keep-dlock,overwrite,dry-run,debug \
|
--longoptions=vmid:,prefixid:,excludevmids:,destination:,pool:,keeplocal:,keepremote:,rewrite:,influxurl:,influxorg:,influxtoken:,influxbucket:,jobname:,online,migrate,nolock,keep-slock,keep-dlock,overwrite,dry-run,debug \
|
||||||
--name "$PROGNAME" \
|
--name "$PROGNAME" \
|
||||||
-- "$@") \
|
-- "$@") \
|
||||||
|| end_process 128
|
|| end_process 128
|
||||||
@@ -156,8 +160,9 @@ function parse_opts(){
|
|||||||
--influxorg) opt_influx_api_org=$2; shift 2;;
|
--influxorg) opt_influx_api_org=$2; shift 2;;
|
||||||
--influxtoken) opt_influx_token=$2; shift 2;;
|
--influxtoken) opt_influx_token=$2; shift 2;;
|
||||||
--influxbucket) opt_influx_bucket=$2; shift 2;;
|
--influxbucket) opt_influx_bucket=$2; shift 2;;
|
||||||
|
--jobname) opt_influx_jobname=$2; shift 2;;
|
||||||
--online) opt_online=1; shift 2;;
|
--online) opt_online=1; shift ;;
|
||||||
|
--migrate) opt_migrate=1; shift ;;
|
||||||
--dry-run) opt_dry_run=1; shift;;
|
--dry-run) opt_dry_run=1; shift;;
|
||||||
--debug) opt_debug=1; shift;;
|
--debug) opt_debug=1; shift;;
|
||||||
--nolock) opt_lock=0; shift;;
|
--nolock) opt_lock=0; shift;;
|
||||||
@@ -183,6 +188,8 @@ function parse_opts(){
|
|||||||
|
|
||||||
[ -z "$opt_vm_ids" ] && { log info "VM id is not set."; end_process 1; }
|
[ -z "$opt_vm_ids" ] && { log info "VM id is not set."; end_process 1; }
|
||||||
|
|
||||||
|
[ -z "$opt_influx_jobname" ] && { log info "Jobname is not set."; end_process 1; }
|
||||||
|
|
||||||
if [ -n "$opt_keep_local" ]; then
|
if [ -n "$opt_keep_local" ]; then
|
||||||
if ! [[ ${opt_keep_local:(-1)} == "s" || ${opt_keep_local:(-1)} == "d" ]]; then
|
if ! [[ ${opt_keep_local:(-1)} == "s" || ${opt_keep_local:(-1)} == "d" ]]; then
|
||||||
echo "--keeplocal: Parameter malformed. suffix s or d missing"
|
echo "--keeplocal: Parameter malformed. suffix s or d missing"
|
||||||
@@ -197,10 +204,16 @@ function parse_opts(){
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $opt_keepdlock -eq 1 ] && [ $opt_migrate -eq 1 ]; then
|
||||||
|
log error "--keepdlock/--migrate: Invalid parameter Combination: you can't keep the destination locked in near-live migration mode"
|
||||||
|
end_process 255
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$opt_vm_ids" = "all" ]; then
|
if [ "$opt_vm_ids" = "all" ]; then
|
||||||
local all=''
|
local all=''
|
||||||
local data=''
|
local data=''
|
||||||
local cnt=''
|
local cnt=''
|
||||||
|
local ids=''
|
||||||
|
|
||||||
all=$(get_vm_ids "$QEMU_CONF_CLUSTER/*$EXT_CONF" "$LXC_CONF_CLUSTER/*$EXT_CONF")
|
all=$(get_vm_ids "$QEMU_CONF_CLUSTER/*$EXT_CONF" "$LXC_CONF_CLUSTER/*$EXT_CONF")
|
||||||
all=$(echo "$all" | tr ',' "\n")
|
all=$(echo "$all" | tr ',' "\n")
|
||||||
@@ -212,9 +225,18 @@ function parse_opts(){
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
vm_ids=$(echo "$vm_ids" | tr ',' "\n")
|
vm_ids=$(echo "$vm_ids" | tr ',' "\n")
|
||||||
|
else
|
||||||
|
if [ ! -z $opt_prefix_id ]; then
|
||||||
|
ids=$(echo "$opt_vm_ids" | tr ',' "\n")
|
||||||
|
for id in $ids; do
|
||||||
|
vm_ids=$(echo "$vm_ids$id:$opt_prefix_id$id,")
|
||||||
|
done
|
||||||
|
vm_ids=$(echo "$vm_ids" | tr ',' "\n")
|
||||||
else
|
else
|
||||||
vm_ids=$(echo "$opt_vm_ids" | tr ',' "\n")
|
vm_ids=$(echo "$opt_vm_ids" | tr ',' "\n")
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
log debug "vm_ids: $vm_ids"
|
||||||
}
|
}
|
||||||
|
|
||||||
human_readable() {
|
human_readable() {
|
||||||
@@ -333,13 +355,15 @@ function log(){
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
warn)
|
warn)
|
||||||
echo "WARNING: $message" 1>&2
|
echo -n $(echoyellow "WARNING: ")
|
||||||
|
echo $(echowhite "$message") 1>&2
|
||||||
echo -e "$message" >> "$LOG_FILE";
|
echo -e "$message" >> "$LOG_FILE";
|
||||||
[ $opt_syslog -eq 1 ] && logger -t "$PROGNAME" -p daemon.warn "$message"
|
[ $opt_syslog -eq 1 ] && logger -t "$PROGNAME" -p daemon.warn "$message"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
error)
|
error)
|
||||||
echo "ERROR: $message" 1>&2
|
echo -n $(echored "ERROR: ")
|
||||||
|
echo $(echowhite "$message") 1>&2
|
||||||
echo -e "$message" >> "$LOG_FILE";
|
echo -e "$message" >> "$LOG_FILE";
|
||||||
[ $opt_syslog -eq 1 ] && logger -t "$PROGNAME" -p daemon.err "$message"
|
[ $opt_syslog -eq 1 ] && logger -t "$PROGNAME" -p daemon.err "$message"
|
||||||
;;
|
;;
|
||||||
@@ -409,6 +433,11 @@ function mirror() {
|
|||||||
map_vmids_to_host
|
map_vmids_to_host
|
||||||
map_vmids_to_dsthost "$opt_destination"
|
map_vmids_to_dsthost "$opt_destination"
|
||||||
|
|
||||||
|
if [ $(check_pool_exist "$opt_pool") -eq 0 ]; then
|
||||||
|
log error "Preflight check: Destination RBD-Pool $opt_pool does not exist."
|
||||||
|
end_process 255
|
||||||
|
fi
|
||||||
|
|
||||||
for vm_id in $svmids; do
|
for vm_id in $svmids; do
|
||||||
(( vmcount++ ))
|
(( vmcount++ ))
|
||||||
local file_config; file_config=$(get_config_file)
|
local file_config; file_config=$(get_config_file)
|
||||||
@@ -419,7 +448,7 @@ function mirror() {
|
|||||||
log info "VM $vm_id - Starting mirror for $(echowhite "$vmname")"
|
log info "VM $vm_id - Starting mirror for $(echowhite "$vmname")"
|
||||||
srcvmgenid=$(cat $PVE_NODES/"${pvnode[$vm_id]}"/$QEMU/"$vm_id".conf | sed -e ''$restripsnapshots'' | grep vmgenid | sed -r -e 's/^vmgenid:\s(.*)/\1/')
|
srcvmgenid=$(cat $PVE_NODES/"${pvnode[$vm_id]}"/$QEMU/"$vm_id".conf | sed -e ''$restripsnapshots'' | grep vmgenid | sed -r -e 's/^vmgenid:\s(.*)/\1/')
|
||||||
dstvmgenid=$(ssh $opt_destination cat $PVE_NODES/"${dstpvnode[$dvmid]}"/$QEMU/"$dvmid".conf 2>/dev/null | grep vmgenid | sed -e ''$restripsnapshots'' | sed -r -e 's/^vmgenid:\s(.*)/\1/')
|
dstvmgenid=$(ssh $opt_destination cat $PVE_NODES/"${dstpvnode[$dvmid]}"/$QEMU/"$dvmid".conf 2>/dev/null | grep vmgenid | sed -e ''$restripsnapshots'' | sed -r -e 's/^vmgenid:\s(.*)/\1/')
|
||||||
log info "VM $vm_id - Checking for VM $dvmid on Destination Host $opt_destination $QEMU_CONF_CLUSTER"
|
log info "VM $vm_id - Checking for VM $dvmid on destination cluster $opt_destination $QEMU_CONF_CLUSTER"
|
||||||
log debug "DVMID:$dvmid srcvmgenid:$srcvmgenid dstvmgenid:$dstvmgenid"
|
log debug "DVMID:$dvmid srcvmgenid:$srcvmgenid dstvmgenid:$dstvmgenid"
|
||||||
conf_on_destination=$(ssh $opt_destination "ls -d $QEMU_CONF_CLUSTER/$dvmid$EXT_CONF 2>/dev/null")
|
conf_on_destination=$(ssh $opt_destination "ls -d $QEMU_CONF_CLUSTER/$dvmid$EXT_CONF 2>/dev/null")
|
||||||
[[ "$conf_on_destination" =~ $redstconf ]]
|
[[ "$conf_on_destination" =~ $redstconf ]]
|
||||||
@@ -428,7 +457,7 @@ function mirror() {
|
|||||||
if [ $host_on_destination ]; then
|
if [ $host_on_destination ]; then
|
||||||
dststatus=$(ssh root@${dstpvnode[$dvmid]} qm status $dvmid|cut -d' ' -f 2)
|
dststatus=$(ssh root@${dstpvnode[$dvmid]} qm status $dvmid|cut -d' ' -f 2)
|
||||||
if [ $dststatus == "running" ]; then
|
if [ $dststatus == "running" ]; then
|
||||||
log error "Destination VM is running. bailing out"
|
log error "VM is running on Destination. bailing out"
|
||||||
end_process 255
|
end_process 255
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -449,14 +478,25 @@ function mirror() {
|
|||||||
map_vmids_to_dsthost "$opt_destination"
|
map_vmids_to_dsthost "$opt_destination"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#--move so we need to shutdown and remove from ha group?
|
||||||
|
if [ $opt_migrate -eq 1 ]; then
|
||||||
|
log info "VM $vm_id - Migration requested, shutting down VM on ${pvnode[$vm_id]}"
|
||||||
|
if [ "$(get_ha_status "$vm_id")" == "started" ]; then
|
||||||
|
log info "VM $vm_id - remove from HA"
|
||||||
|
do_run "ha-manager remove $vm_id"
|
||||||
|
fi
|
||||||
|
do_run "ssh root@${pvnode[$vm_id]} qm shutdown $vm_id >/dev/null"
|
||||||
|
fi
|
||||||
|
|
||||||
#Lock on source + destination
|
#Lock on source + destination
|
||||||
if [ $opt_lock -eq 1 ]; then
|
if [ $opt_lock -eq 1 ]; then
|
||||||
do_run "ssh root@"${pvnode[$vm_id]}" qm set "$vm_id" --lock backup" >/dev/null
|
do_run "ssh root@"${pvnode[$vm_id]}" qm set "$vm_id" --lock backup" >/dev/null
|
||||||
log info "VM $vm_id - locked $vm_id [rc:$?]"
|
log info "VM $vm_id - locked $vm_id [rc:$?] on source"
|
||||||
do_run "ssh root@"${dstpvnode[$dvmid]}" qm set "$dvmid" --lock backup" >/dev/null
|
do_run "ssh root@"${dstpvnode[$dvmid]}" qm set "$dvmid" --lock backup" >/dev/null
|
||||||
log info "VM $dvmid - locked $dvmid [rc:$?]"
|
log info "VM $dvmid - locked $dvmid [rc:$?] on destination"
|
||||||
fi
|
fi
|
||||||
|
#Freeze fs only if no migration running
|
||||||
|
if [ $opt_migrate -eq 0 ]; then
|
||||||
vm_freeze "$vm_id" "${pvnode[$vm_id]}" >/dev/null
|
vm_freeze "$vm_id" "${pvnode[$vm_id]}" >/dev/null
|
||||||
freezerc=$?
|
freezerc=$?
|
||||||
if [ $freezerc -gt 0 ]; then
|
if [ $freezerc -gt 0 ]; then
|
||||||
@@ -465,6 +505,7 @@ function mirror() {
|
|||||||
else
|
else
|
||||||
(( perf_freeze_ok++ ))
|
(( perf_freeze_ok++ ))
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
for disk in $(get_disks_from_config "$file_config"); do
|
for disk in $(get_disks_from_config "$file_config"); do
|
||||||
src_image_spec=$(get_image_spec "$disk")
|
src_image_spec=$(get_image_spec "$disk")
|
||||||
create_snapshot "$src_image_spec@$opt_snapshot_prefix$timestamp" 2>/dev/null
|
create_snapshot "$src_image_spec@$opt_snapshot_prefix$timestamp" 2>/dev/null
|
||||||
@@ -476,6 +517,7 @@ function mirror() {
|
|||||||
(( perf_ss_ok++ ))
|
(( perf_ss_ok++ ))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
if [ $opt_migrate -eq 0 ]; then
|
||||||
vm_unfreeze "$vm_id" "${pvnode[$vm_id]}" >/dev/null
|
vm_unfreeze "$vm_id" "${pvnode[$vm_id]}" >/dev/null
|
||||||
unfreezerc=$?
|
unfreezerc=$?
|
||||||
if [ $unfreezerc -gt 0 ]; then
|
if [ $unfreezerc -gt 0 ]; then
|
||||||
@@ -485,7 +527,7 @@ function mirror() {
|
|||||||
do_run "ssh root@${pvnode[$vm_id]} qm unlock $vm_id" >/dev/null
|
do_run "ssh root@${pvnode[$vm_id]} qm unlock $vm_id" >/dev/null
|
||||||
log info "VM $vm_id - unlocked source VM $vm_id [rc:$?]"
|
log info "VM $vm_id - unlocked source VM $vm_id [rc:$?]"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
for disk in $(get_disks_from_config "$file_config"); do
|
for disk in $(get_disks_from_config "$file_config"); do
|
||||||
(( diskcount++ ))
|
(( diskcount++ ))
|
||||||
log debug "VMID: $vm_id Disk: $disk DESTVMID: $dvmid"
|
log debug "VMID: $vm_id Disk: $disk DESTVMID: $dvmid"
|
||||||
@@ -573,7 +615,7 @@ function mirror() {
|
|||||||
log info "VM $vm_id - Disk Summary: Took $(( enddisk - startdisk )) Seconds to transfer $(human_readable "$perf_bytes_total" 2) in a $xmittype run"
|
log info "VM $vm_id - Disk Summary: Took $(( enddisk - startdisk )) Seconds to transfer $(human_readable "$perf_bytes_total" 2) in a $xmittype run"
|
||||||
if [ -n "$opt_influx_api_url" ]; then
|
if [ -n "$opt_influx_api_url" ]; then
|
||||||
log info "VM $vm_id - Logging to InfluxDB: $opt_influx_api_url"
|
log info "VM $vm_id - Logging to InfluxDB: $opt_influx_api_url"
|
||||||
influxlp="$opt_influx_job_metrics,vmname=$vmname,destination=$opt_destination,srcimage=$src_image_name,dstimage=$dst_image_name,xmittype=$xmittype bytescalculated=$snapshotsize""i,bytesonwire=$perf_bytes_total""i,xmitrc=$xmitrc""i,freezerc=$freezerc""i,unfreezerc=$unfreezerc""i,basets=$basets""i"
|
influxlp="$opt_influx_job_metrics,vmname=$vmname,jobname=$opt_influx_jobname,destination=$opt_destination,srcimage=$src_image_name,dstimage=$dst_image_name,xmittype=$xmittype bytescalculated=$snapshotsize""i,bytesonwire=$perf_bytes_total""i,xmitrc=$xmitrc""i,freezerc=$freezerc""i,unfreezerc=$unfreezerc""i,basets=$basets""i"
|
||||||
log debug "InfluxLP: --->\n $influxlp"
|
log debug "InfluxLP: --->\n $influxlp"
|
||||||
cmd="curl --request POST \"$opt_influx_api_url/v2/write?org=$opt_influx_api_org&bucket=$opt_influx_bucket&precision=ns\" --header \"Authorization: Token $opt_influx_token\" --header \"Content-Type: text/plain; charset=utf-8\" --header \"Accept: application/json\" --data-binary '$influxlp'"
|
cmd="curl --request POST \"$opt_influx_api_url/v2/write?org=$opt_influx_api_org&bucket=$opt_influx_bucket&precision=ns\" --header \"Authorization: Token $opt_influx_token\" --header \"Content-Type: text/plain; charset=utf-8\" --header \"Accept: application/json\" --data-binary '$influxlp'"
|
||||||
do_run "$cmd"
|
do_run "$cmd"
|
||||||
@@ -584,6 +626,12 @@ function mirror() {
|
|||||||
ssh root@${dstpvnode[$dvmid]} qm unlock $dvmid
|
ssh root@${dstpvnode[$dvmid]} qm unlock $dvmid
|
||||||
log info "VM $dvmid - Unlocking destination VM $dvmid"
|
log info "VM $dvmid - Unlocking destination VM $dvmid"
|
||||||
fi
|
fi
|
||||||
|
#--migrate so start on destination?
|
||||||
|
if [ $opt_migrate -eq 1 ]; then
|
||||||
|
log info "VM $dvmid - Starting VM on ${pvnode[$vm_id]}"
|
||||||
|
do_run "ssh root@"${dstpvnode[$dvmid]}" qm start "$dvmid >/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
endjob=$(date +%s)
|
endjob=$(date +%s)
|
||||||
log info "Finnished mirror $(date "+%F %T")"
|
log info "Finnished mirror $(date "+%F %T")"
|
||||||
@@ -601,7 +649,7 @@ function mirror() {
|
|||||||
log info "Differential Bytes .......: $(human_readable $perf_bytes_diff)"
|
log info "Differential Bytes .......: $(human_readable $perf_bytes_diff)"
|
||||||
if [ -n "$opt_influx_api_url" ]; then
|
if [ -n "$opt_influx_api_url" ]; then
|
||||||
log info "VM $vm_id - Logging Job summary to InfluxDB: $opt_influx_api_url"
|
log info "VM $vm_id - Logging Job summary to InfluxDB: $opt_influx_api_url"
|
||||||
influxlp="$opt_influx_summary_metrics perf_bytes_diff=$perf_bytes_diff""i,perf_bytes_full=$perf_bytes_full""i,perf_bytes_total=$perf_bytes_total""i,perf_diff_failed=$perf_diff_failed""i,perf_diff_ok=$perf_diff_ok""i,perf_freeze_failed=$perf_freeze_failed""i,perf_freeze_ok=$perf_freeze_ok""i,perf_full_failed=$perf_full_failed""i,perf_full_ok=$perf_full_ok""i,perf_ss_failed=$perf_ss_failed""i,perf_ss_ok=$perf_ss_ok""i,perf_vm_running=$perf_vm_running""i,perf_vm_stopped=$perf_vm_stopped""i"
|
influxlp="$opt_influx_summary_metrics,jobname=$opt_influx_jobname perf_bytes_diff=$perf_bytes_diff""i,perf_bytes_full=$perf_bytes_full""i,perf_bytes_total=$perf_bytes_total""i,perf_diff_failed=$perf_diff_failed""i,perf_diff_ok=$perf_diff_ok""i,perf_freeze_failed=$perf_freeze_failed""i,perf_freeze_ok=$perf_freeze_ok""i,perf_full_failed=$perf_full_failed""i,perf_full_ok=$perf_full_ok""i,perf_ss_failed=$perf_ss_failed""i,perf_ss_ok=$perf_ss_ok""i,perf_vm_running=$perf_vm_running""i,perf_vm_stopped=$perf_vm_stopped""i"
|
||||||
log debug "InfluxLP: --->\n $influxlp"
|
log debug "InfluxLP: --->\n $influxlp"
|
||||||
cmd="curl --request POST \"$opt_influx_api_url/v2/write?org=$opt_influx_api_org&bucket=$opt_influx_bucket&precision=ns\" --header \"Authorization: Token $opt_influx_token\" --header \"Content-Type: text/plain; charset=utf-8\" --header \"Accept: application/json\" --data-binary '$influxlp'"
|
cmd="curl --request POST \"$opt_influx_api_url/v2/write?org=$opt_influx_api_org&bucket=$opt_influx_bucket&precision=ns\" --header \"Authorization: Token $opt_influx_token\" --header \"Content-Type: text/plain; charset=utf-8\" --header \"Accept: application/json\" --data-binary '$influxlp'"
|
||||||
do_run "$cmd"
|
do_run "$cmd"
|
||||||
@@ -703,7 +751,7 @@ function rewriteconfig(){
|
|||||||
else
|
else
|
||||||
sedcmd='sed -e /^$/,$d'
|
sedcmd='sed -e /^$/,$d'
|
||||||
fi
|
fi
|
||||||
cat "$oldconfig" | sed -r -e "s/^(virtio|ide|scsi|sata|mp)([0-9]+):\s([a-zA-Z0-9]+):(.*)-([0-9]+)-disk-([0-9]+).*,(.*)$/\1\2: $newpool:\4-$newvmid-disk-\6-\3,\7/g" | $sedcmd | sed -e '/^$/,$d' | grep -v "^parent:\s.*$" | ssh "$dst" "cat - >$newconfig"
|
cat "$oldconfig" | sed -r -e "s/^(virtio|ide|scsi|sata|mp)([0-9]+):\s([a-zA-Z0-9]+):(.*)-([0-9]+)-disk-([0-9]+).*,(.*)$/\1\2: $newpool:\4-$newvmid-disk-\6-\3,\7/g" | $sedcmd | sed -e '/^$/,$d' | sed -e '/ide[0-9]:.*-cloudinit,media=cdrom.*/d' | grep -v "^parent:\s.*$" | ssh "$dst" "cat - >$newconfig"
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkvmid(){
|
function checkvmid(){
|
||||||
@@ -767,6 +815,24 @@ function get_image_spec(){
|
|||||||
echo "$image_spec"
|
echo "$image_spec"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_ha_status() {
|
||||||
|
local havmid="$1"
|
||||||
|
ha_status=$(ha-manager status| grep vm:"$havmid" | cut -d " " -f 4| sed 's/.$//')
|
||||||
|
echo "$ha_status"
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_pool_exist() {
|
||||||
|
local poolname="$1"
|
||||||
|
local -i exists=255
|
||||||
|
pool_status=$(ssh $opt_destination pvesm status|grep rbd|cut -d " " -f 1|grep $poolname)
|
||||||
|
if [ "$pool_status" == "$poolname" ]; then
|
||||||
|
exists=1
|
||||||
|
else
|
||||||
|
exists=0
|
||||||
|
fi
|
||||||
|
echo $exists
|
||||||
|
}
|
||||||
|
|
||||||
function main(){
|
function main(){
|
||||||
[ $# = 0 ] && usage;
|
[ $# = 0 ] && usage;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user