zfs replication to all nodes

onlyzeros

Member
Dec 22, 2023
13
3
8
I have 3 node proxmox cluster with zfs storage and want to setup replication jobs but I have around 30 LXCs and can only setup one by one.

I have LXCs in all 3 nodes and I want all LXCs replicated to all nodes.

Is there a way of doing this without having to manually add an entry to every node for every LXC?

I couldn't find any script that could help me doing this, even AI scripts wasn't helpful.

Thanks in advance.
 
Thanks @Neobin that was helpful. I was able to create the below script with the help of AI.

You can change "*/15" to adjust the schedule to your liking and add --rate to prevent storage/network bottlenecks, ie: --rate 20 (20 MB/s)

Bash:
#!/bin/bash
# List of all nodes in your cluster
NODES=("node1" "node2" "node3")

# Fetch all LXC container IDs
LXC_IDS=$(pct list | awk '{print $1}')

echo "Starting automated replication job creation for $LXC_IDS..."

for LXC_ID in $LXC_IDS; do
    # Source node where the LXC currently resides
    SRC_NODE=$(pct config $LXC_ID | grep -A1 "node:" | awk '{print $2}')
      
    echo "Processing LXC $LXC_ID (source: $SRC_NODE)"
    JOB_NUM=0
    
    for TARGET in "${NODES[@]}"; do
        # Only create jobs for target nodes that are not the source
        if [ "$SRC_NODE" != "$TARGET" ]; then
            JOB_ID="${LXC_ID}-${JOB_NUM}"
            echo "   → Creating job $JOB_ID for target: $TARGET"
            pvesr create-local-job "$JOB_ID" "$TARGET" --schedule "*/15" --comment "Auto-replicate LXC $LXC_ID"
            JOB_NUM=$((JOB_NUM + 1))
        fi
    done
done
echo "All replication jobs created. Verify with: pvesr status"
 
  • Like
Reactions: Johannes S