make the volume scripts ignore ephemeral volumes

This commit is contained in:
goldsquid
2026-06-06 09:57:48 +07:00
parent d369f62c44
commit 91ef991773
10 changed files with 61 additions and 14 deletions

View File

@@ -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

View File

@@ -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_"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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

View File

@@ -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=()

View File

@@ -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

View File

@@ -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

40
volume-utils.sh Executable file
View File

@@ -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")
}