try to figure
This commit is contained in:
19
show-file-size.sh
Executable file
19
show-file-size.sh
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Read the JSON input and extract the list of keys
|
||||||
|
keys=$(cat /root/rpc/$1.yml | yaml2json - | jq '.volumes' | jq -r 'keys[]')
|
||||||
|
|
||||||
|
total_size=0
|
||||||
|
|
||||||
|
# Iterate over the list of keys
|
||||||
|
for key in $keys; do
|
||||||
|
#echo "checking: /var/lib/docker/volumes/rpc_$key"
|
||||||
|
|
||||||
|
prefix="/var/lib/docker/volumes/rpc_$key"
|
||||||
|
|
||||||
|
volume_size=$(du -s $prefix 2>/dev/null | awk '{print $1}')
|
||||||
|
|
||||||
|
total_size=$((total_size + volume_size))
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "$total_size"
|
||||||
56
show-size.sh
Executable file
56
show-size.sh
Executable file
@@ -0,0 +1,56 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
BASEPATH="$(dirname "$0")"
|
||||||
|
source $BASEPATH/.env
|
||||||
|
|
||||||
|
IFS=':' read -ra parts <<< $COMPOSE_FILE
|
||||||
|
|
||||||
|
blacklist=("drpc.yml" "drpc-free.yml" "base.yml" "rpc.yml" "monitoring.yml" "ftp.yml" "backup-http.yml")
|
||||||
|
|
||||||
|
total_size=0
|
||||||
|
static_size=0
|
||||||
|
|
||||||
|
for part in "${parts[@]}"; do
|
||||||
|
include=true
|
||||||
|
for word in "${blacklist[@]}"; do
|
||||||
|
if echo "$part" | grep -qE "$word"; then
|
||||||
|
#echo "The path $path contains a blacklisted word: $word"
|
||||||
|
include=false
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Check if any parameters were passed
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
# Put parameters into an array (list)
|
||||||
|
params=("$@")
|
||||||
|
|
||||||
|
# Check if a string is part of the list
|
||||||
|
if [[ " ${params[@]} " =~ " ${part%.yml} " ]]; then
|
||||||
|
include=$include # don't change anything
|
||||||
|
else
|
||||||
|
include=false
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $include; then
|
||||||
|
static_ratio="$($BASEPATH/show-static-file-size.sh ${part%.yml})"
|
||||||
|
static_ratio="0$static_ratio"
|
||||||
|
total_kb=$($BASEPATH/show-file-size.sh ${part%.yml})
|
||||||
|
|
||||||
|
total_size=$((total_size + total_kb))
|
||||||
|
|
||||||
|
#output=$(echo "$((total_kb * 1024))" | numfmt --to=iec --suffix=B --format="%.2f")
|
||||||
|
#echo "$output"
|
||||||
|
static_part=$(echo "$total_kb * $static_ratio" | bc)
|
||||||
|
|
||||||
|
static_size=$(echo "$static_size + $static_part" | bc)
|
||||||
|
#output=$(echo "$static_size" | numfmt --to=iec --suffix=B --format="%.2f")
|
||||||
|
#echo "$output"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
total=$(echo "$(( total_size * 1024 ))" | numfmt --to=iec --suffix=B --format="%.2f")
|
||||||
|
static=$(echo $(echo "$static_size * 1024" | bc) | numfmt --to=iec --suffix=B --format="%.2f")
|
||||||
|
|
||||||
|
echo "total: $total"
|
||||||
|
echo "static: $static"
|
||||||
31
show-static-file-size.sh
Executable file
31
show-static-file-size.sh
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Read the JSON input and extract the list of keys
|
||||||
|
keys=$(cat /root/rpc/$1.yml | yaml2json - | jq '.volumes' | jq -r 'keys[]')
|
||||||
|
|
||||||
|
static_size=0
|
||||||
|
total_size=0
|
||||||
|
|
||||||
|
# Iterate over the list of keys
|
||||||
|
for key in $keys; do
|
||||||
|
#echo "checking: /var/lib/docker/volumes/rpc_$key"
|
||||||
|
|
||||||
|
prefix="/var/lib/docker/volumes/rpc_$key"
|
||||||
|
|
||||||
|
volume_size=$(du -s $prefix 2>/dev/null | awk '{print $1}')
|
||||||
|
|
||||||
|
total_size=$((total_size + volume_size))
|
||||||
|
|
||||||
|
while IFS= read -r path; do
|
||||||
|
# Check if the path exists
|
||||||
|
if [[ -e "$prefix/_data/$path" ]]; then
|
||||||
|
# Print the size of the file or directory
|
||||||
|
size=$(du -s "$prefix/_data/$path" 2>/dev/null | awk '{print $1}')
|
||||||
|
static_size=$((static_size + size))
|
||||||
|
#echo "$path: $size"
|
||||||
|
fi
|
||||||
|
done < static-file-path-list.txt
|
||||||
|
done
|
||||||
|
|
||||||
|
ratio=$(bc -l <<< "scale=2; $static_size/$total_size")
|
||||||
|
echo "$ratio"
|
||||||
4
static-file-path-list.txt
Normal file
4
static-file-path-list.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
static_files
|
||||||
|
chain/nitro/l2chaindata/ancient
|
||||||
|
ancient
|
||||||
|
geth/chaindata/ancient
|
||||||
Reference in New Issue
Block a user