How to Solve Protected VMs Residual Data Inconsistency in SynetoOS 6

Written By Christian Castagna (Administrator)

Updated at October 28th, 2025

Table of Contents

→ Applies to: SynetoOS 6.x

 

Symptom

After destroying and recreating the pool, in some cases on SynetoOS 6 there may be residual data from previous protections, causing an inconsistency in the Dashboard, where more protected VMs are shown than actually exist.
 

 

Solution

Step 1. Connect to SynetoOS appliance via SSH as admin

ssh admin@<your_ip_address_or_hostname>

 

Step 2. Get root privileges

sudo su -

 

Step 3. Create clean-policy-assignments.sh file

vi /tmp/clean-policy-assignments.sh

IMPORTANT
Make sure to copy and paste the exact lines below.

#!/usr/bin/env bash

#
# A script to delete records from the policy_assignments table that do not
# have a corresponding ZFS storage volume.
#
# Usage:
#   ./clean-policy-assignments.bash                # Runs the script and performs deletions.
#   ./clean-policy-assignments.bash --dry-run      # Reports which records would be deleted without changing the database.
#

# --- Configuration ---
# Set to "true" for dry-run mode, which only reports what would be deleted.
DRY_RUN=false
if [[ "$1" == "--dry-run" ]]; then
    DRY_RUN=true
    echo "--- Running in DRY-RUN mode. No records will be deleted. ---"
    echo
fi

# Exit immediately if a command fails.
set -e

# --- Script Body ---

echo "Starting cleanup of policy_assignments table..."
echo "Fetching storage volume IDs from the database..."

# Get all storage_volume_ids from the policy_assignments table.
# The `tr -d '\r'` is added to handle potential carriage return characters from psql.
volume_ids=$(kubectl exec pod/postgres-postgresql-0 -- bash -c 'PGPASSWORD=$POSTGRES_PASSWORD psql -h localhost -U postgres -d chronos -At -c "select storage_volume_id from policy_assignments;"' | tr -d '\r')

if [ -z "$volume_ids" ]; then
    echo "No volume IDs found in policy_assignments table. Nothing to do."
    exit 0
fi

echo "Found IDs. Checking each against ZFS volumes..."
echo

# Loop through each volume ID found in the database
for volume_id in $volume_ids; do
    echo "Checking volume: $volume_id"

    # Check if a ZFS volume with this ID exists in its name.
    # We use `zfs list -H -o name` to get all volume names and grep to check.
    # The '-q' flag makes grep silent; it only returns an exit code.
    if zfs list -H -o name | grep -q "$volume_id"; then
        echo "  -> OK: Found matching ZFS volume. Skipping."
    else
        echo "  -> ACTION: No matching ZFS volume found."

        if [ "$DRY_RUN" = true ]; then
            echo "  [DRY-RUN] Would delete record with storage_volume_id: $volume_id"
        else
            echo "  -> Deleting record from policy_assignments..."
            # Construct and execute the DELETE command within the postgres pod.
            # The variable is inside double quotes, so it expands correctly.
            kubectl exec pod/postgres-postgresql-0 -- bash -c "PGPASSWORD=\$POSTGRES_PASSWORD psql -h localhost -U postgres -d chronos -c \"DELETE FROM policy_assignments WHERE storage_volume_id = '$volume_id';\""
            echo "  -> Record for $volume_id deleted successfully."
        fi
    fi
    echo # Add a blank line for readability
done

echo "Cleanup complete."
echo

echo "Please restart chronos to sync changes."

 

Save and EXIT

:wq

 

Step 4. Give permissions to clean-policy-assignments.sh file

chmod +x /tmp/clean-policy-assignments.sh

 

Step 5. Clean policy assignments

sh /tmp/clean-policy-assignments.sh

 

Step 6. Delete the clean-policy-assignments.sh file after removing the snapshots

rm /tmp/clean-policy-assignments.sh