From a7df497245bc6783acf78ed320177de14baed522 Mon Sep 17 00:00:00 2001 From: Sebastian <379651+czarly@users.noreply.github.com> Date: Sun, 17 Mar 2024 04:25:58 +0100 Subject: [PATCH] neat script --- backup-node.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 backup-node.sh diff --git a/backup-node.sh b/backup-node.sh new file mode 100644 index 00000000..7b13c75f --- /dev/null +++ b/backup-node.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +if [ ! -d "/backup" ]; then + echo "Error: /backup directory does not exist" + exit 1 +fi + +# Read the JSON input and extract the list of keys +keys=$(cat /root/rpc/$1.yml | yaml2json - | jq '.volumes' | jq -r 'keys[]') + +# Iterate over the list of keys +for key in $keys; do + echo "Executing command with key: /var/lib/docker/volumes/rpc_$key/_data" + + source_folder="/var/lib/docker/volumes/rpc_$key/_data" + target_file="/backup/rpc_$key-$(date +'%Y-%m-%d-%H-%M-%S').tar.zst" + + tar -cf - "$source_folder" | pv -pterb -s $(du -sb "$source_folder" | awk '{print $1}') | zstd -o "$target_file" +done