crossover icon indicating copy to clipboard operation
crossover copied to clipboard

Incorrect VM filtering when using tags

Open adminsyspro opened this issue 1 year ago • 0 comments

Description:

I encountered an issue with the crossover script when filtering VMs using Proxmox tags. The problem is that the script incorrectly includes VMs with tags that partially match the specified tag. Steps to reproduce:

Assign the following tags to VMs:
    VM1: tags: 4h
    VM2: tags: 24h
Run the following command to mirror VMs tagged 4h:

./crossover mirror --jobname=Replication --tag=4h --destination=PROXMOX-1 --pool=CephStoragePool --online

Expected behavior: Only VMs with the exact 4h tag should be replicated.
Actual behavior: VMs with the 24h tag are also included.

Cause:

The issue comes from the following line in the get_vm_ids function:

if [ -n "$opt_tag" ] && ! grep -qE "^tags:\s.*$opt_tag(;|$)" $conf; then

This regex does not ensure that $opt_tag is a complete tag and allows partial matches (e.g., 4h is matched inside 24h). Suggested fix:

Modify the regex to ensure $opt_tag is a standalone tag:

if [ -n "$opt_tag" ] && ! grep -qE "^tags:.*(^|[[:space:];])$opt_tag([[:space:];]|$)" $conf; then

adminsyspro avatar Feb 27 '25 07:02 adminsyspro