From 91ef9917732b7d3f4872abd3c7e6bd35b5c8f384 Mon Sep 17 00:00:00 2001 From: goldsquid Date: Sat, 6 Jun 2026 09:57:48 +0700 Subject: [PATCH] make the volume scripts ignore ephemeral volumes --- backup-node.sh | 3 ++- cleanup-volumes.sh | 8 ++------ clone-backup.sh | 3 ++- clone-node.sh | 3 ++- delete-node-keys.sh | 3 ++- node-size.sh | 4 +++- restore-volumes.sh | 3 ++- show-file-size.sh | 5 ++++- show-static-file-size.sh | 3 ++- volume-utils.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 10 files changed, 61 insertions(+), 14 deletions(-) create mode 100755 volume-utils.sh diff --git a/backup-node.sh b/backup-node.sh index 70304c68..2bbec52a 100755 --- a/backup-node.sh +++ b/backup-node.sh @@ -1,6 +1,7 @@ #!/bin/bash BASEPATH="$(dirname "$0")" +source "$BASEPATH/volume-utils.sh" backup_dir="/backup" if [[ -n $2 ]]; then @@ -43,7 +44,7 @@ generate_volume_metadata() { } # Read the JSON input and extract the list of keys -keys=$(cat /root/rpc/$1.yml | yaml2json - | jq '.volumes' | jq -r 'keys[]') +keys=$(get_persistent_volume_keys "/root/rpc/$1.yml") # Iterate over the list of keys for key in $keys; do diff --git a/cleanup-volumes.sh b/cleanup-volumes.sh index 9e4c4151..23522a9e 100755 --- a/cleanup-volumes.sh +++ b/cleanup-volumes.sh @@ -1,17 +1,13 @@ BASEPATH="$(dirname "$0")" source $BASEPATH/.env +source $BASEPATH/volume-utils.sh IFS=':' read -ra parts <<< $COMPOSE_FILE used_volumes=() for part in "${parts[@]}"; do - - # Convert YAML to JSON using yaml2json - json=$(yaml2json "$BASEPATH/$part") - - # Extract volumes using jq - volumes=$(echo "$json" | jq -r '.volumes | keys[]' 2> /dev/null) + volumes=$(get_volume_keys "$BASEPATH/$part") # Convert volumes to an array prefix="rpc_" diff --git a/clone-backup.sh b/clone-backup.sh index 0e7051e1..4274f069 100755 --- a/clone-backup.sh +++ b/clone-backup.sh @@ -12,6 +12,7 @@ else fi dir="$(dirname "$0")" +source "$dir/volume-utils.sh" # Configuration BASE_PORT=9000 @@ -524,7 +525,7 @@ main() { sudo sysctl -w net.ipv4.tcp_no_metrics_save=1 echo "Reading volume configuration from $dir/$1.yml..." - keys=$(cat "$dir/$1.yml" | yaml2json - | jq '.volumes' | jq -r 'keys[]') + keys=$(get_persistent_volume_keys "$dir/$1.yml") if [[ -z "$keys" ]]; then echo "Error: No volumes found in configuration" diff --git a/clone-node.sh b/clone-node.sh index 578a8579..d54d14b6 100755 --- a/clone-node.sh +++ b/clone-node.sh @@ -3,6 +3,7 @@ # Fixed version that handles missing netstat BASEPATH="$(dirname "$0")" +source "$BASEPATH/volume-utils.sh" if [[ -n $2 ]]; then DEST_HOST="$2.stakesquid.eu" @@ -496,7 +497,7 @@ main() { sudo sysctl -w net.ipv4.tcp_no_metrics_save=1 echo "Reading volume configuration from $1.yml..." - keys=$(cat /root/rpc/$1.yml | yaml2json - | jq '.volumes' | jq -r 'keys[]') + keys=$(get_persistent_volume_keys "/root/rpc/$1.yml") if [[ -z "$keys" ]]; then echo "Error: No volumes found in configuration" diff --git a/delete-node-keys.sh b/delete-node-keys.sh index 4315f85a..ff376495 100755 --- a/delete-node-keys.sh +++ b/delete-node-keys.sh @@ -14,6 +14,7 @@ fi CONFIG_FILE="$1.yml" GLOBS_FILE="${2:-node-key-globs.txt}" SCRIPT_DIR="$(dirname "$0")" +source "$SCRIPT_DIR/volume-utils.sh" # Try to find config file in multiple locations if [[ -f "$SCRIPT_DIR/$CONFIG_FILE" ]]; then @@ -42,7 +43,7 @@ fi # Read volume keys from config file echo "Reading volume configuration from $CONFIG_PATH..." -keys=$(cat "$CONFIG_PATH" | yaml2json - | jq '.volumes' | jq -r 'keys[]') +keys=$(get_persistent_volume_keys "$CONFIG_PATH") if [[ -z "$keys" ]]; then echo "Error: No volumes found in configuration" diff --git a/node-size.sh b/node-size.sh index 381e751f..72e4e795 100755 --- a/node-size.sh +++ b/node-size.sh @@ -1,7 +1,9 @@ #!/bin/bash +source "$(dirname "$0")/volume-utils.sh" + # Read the JSON input and extract the list of keys -keys=$(cat /root/rpc/$1.yml | yaml2json - | jq '.volumes' | jq -r 'keys[]') +keys=$(get_persistent_volume_keys "/root/rpc/$1.yml") total_size=0 diff --git a/restore-volumes.sh b/restore-volumes.sh index b9e33500..c6c2aec0 100755 --- a/restore-volumes.sh +++ b/restore-volumes.sh @@ -1,5 +1,6 @@ #!/bin/bash dir="$(dirname "$0")" +source "$dir/volume-utils.sh" # Path to the backup directory backup_dir="/backup" @@ -13,7 +14,7 @@ if [ ! -d "$volume_dir" ]; then fi # Read the JSON input and extract the list of keys -keys=$(cat $dir/$1.yml | yaml2json - | jq '.volumes' | jq -r 'keys[]' | grep -E '^["'\'']?[0-9a-z]') +keys=$(get_persistent_volume_keys "$dir/$1.yml" | grep -E '^[0-9a-z]') restore_files=() cleanup_folders=() diff --git a/show-file-size.sh b/show-file-size.sh index ef65b815..c65fb990 100755 --- a/show-file-size.sh +++ b/show-file-size.sh @@ -1,7 +1,10 @@ #!/bin/bash +BASEPATH="$(dirname "$0")" +source "$BASEPATH/volume-utils.sh" + # Read the JSON input and extract the list of keys -keys=$(cat /root/rpc/$1.yml | yaml2json - | jq '.volumes' | jq -r 'keys[]') +keys=$(get_persistent_volume_keys "/root/rpc/$1.yml") total_size=0 diff --git a/show-static-file-size.sh b/show-static-file-size.sh index bb3d4f13..329517b3 100755 --- a/show-static-file-size.sh +++ b/show-static-file-size.sh @@ -1,10 +1,11 @@ #!/bin/bash BASEPATH="$(dirname "$0")" +source "$BASEPATH/volume-utils.sh" static_file_list="$BASEPATH/static-file-path-list.txt" # Read the JSON input and extract the list of keys -keys=$(cat /root/rpc/$1.yml | yaml2json - | jq '.volumes' | jq -r 'keys[]') +keys=$(get_persistent_volume_keys "/root/rpc/$1.yml") static_size=0 total_size=0 diff --git a/volume-utils.sh b/volume-utils.sh new file mode 100755 index 00000000..39167379 --- /dev/null +++ b/volume-utils.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Shared helpers for compose volume operations. +# Ephemeral volumes (init-container config) are excluded from backup/restore/size. + +is_ephemeral_volume_key() { + local key=$1 + local compose_file=$2 + + # op-node rollup config volumes + [[ "$key" == *_node_config ]] && return 0 + + if [[ -n "$compose_file" && -f "$compose_file" ]]; then + local ephemeral + ephemeral=$(yaml2json "$compose_file" 2>/dev/null | jq -r '.["x-ephemeral-volumes"] // [] | .[]' 2>/dev/null) + while IFS= read -r vol; do + [[ -z "$vol" ]] && continue + [[ "$key" == "$vol" ]] && return 0 + done <<< "$ephemeral" + fi + + return 1 +} + +get_volume_keys() { + local compose_file=$1 + yaml2json "$compose_file" 2>/dev/null | jq -r '.volumes | keys[]' 2>/dev/null +} + +get_persistent_volume_keys() { + local compose_file=$1 + local key + + while IFS= read -r key; do + [[ -z "$key" ]] && continue + if ! is_ephemeral_volume_key "$key" "$compose_file"; then + echo "$key" + fi + done < <(get_volume_keys "$compose_file") +}