Fernando Soder avatar

Just a script I made to back up IPFS files into my personal Kubo.

fernandosoder

Published: 14 Jul 2026 › Updated: 14 Jul 2026Just a script I made to back up IPFS files into my personal Kubo.

Just a script I made to back up IPFS files into my personal Kubo.

As most people who know me are aware, I enjoy making experiments with Hive and IPFS aiming at free data distribution in decentralized ways.

#!/bin/bash

HIVE_RPC="https://api.hive.blog"
IPFS_API="http://127.0.0.1:5001"
MFS_DIR="/hive"
LAST_FILE="/home/fernando/Documentos/last.txt"

MAX_JOBS=100
TTL=10


if [ -f "$LAST_FILE" ]; then
    LAST=$(<"$LAST_FILE")
else
    LAST=$(curl -s "$HIVE_RPC" \
        -H "Content-Type: application/json" \
        -d '{
            "jsonrpc":"2.0",
            "method":"condenser_api.get_dynamic_global_properties",
            "params":[],
            "id":1
        }' \
        | jq -r '.result.head_block_number')
    echo "$LAST" > "$LAST_FILE"
fi

while true; do
    HEAD=$(curl -s "$HIVE_RPC" \
        -H "Content-Type: application/json" \
        -d '{
            "jsonrpc":"2.0",
            "method":"condenser_api.get_dynamic_global_properties",
            "params":[],
            "id":1
        }' \
        | jq -r '.result.head_block_number')

    echo "Head block: $HEAD"
    curl -X POST -s "$IPFS_API/api/v0/files/mkdir?arg=$MFS_DIR&parents=true"
    if (( LAST < HEAD - 100 )); then
        TTL=60
    else
        TTL=3600
    fi
    while [ "$LAST" -lt "$HEAD" ]; do
        echo "Last block: $LAST | HTTP Jobs: $(pgrep -af "pin/add|files/cp" | wc -l) | $((HEAD - LAST)) behind"
        echo "$LAST" > "$LAST_FILE"
        LAST=$((LAST+1))
        BLOCK=$(curl -s "$HIVE_RPC" \
            -H "Content-Type: application/json" \
            -d "{
                \"jsonrpc\":\"2.0\",
                \"method\":\"block_api.get_block\",
                \"params\":{\"block_num\":$LAST},
                \"id\":2
            }")
        echo "$BLOCK" |
        jq -r '.. | strings' |
        grep -Eo '(Qm[1-9A-HJ-NP-Za-km-z]{44}|bafy[a-z0-9]{20,})' |
        sort -u |
        while read -r CID; do
            echo "Found CID: $CID"
            while [ "$(pgrep -af "pin/add|files/cp" | wc -l)" -ge "$MAX_JOBS" ]; do
                sleep 0.1
                echo -e "\e[1A\e[KLast block: $LAST | HTTP Jobs: $(pgrep -af "pin/add|files/cp" | wc -l) | $((HEAD - LAST)) behind"
            done
            FILE="$(date +%s%N)"
            curl --max-time "$TTL" -X POST -s "$IPFS_API/api/v0/pin/add?arg=$CID" &&
            curl --max-time "$TTL" -X POST -s "$IPFS_API/api/v0/files/cp?arg=/ipfs/$CID&arg=$MFS_DIR/$FILE" &
        done
        sleep 0.1
    done
    sleep 3
done


If you trust my capability to run a stable and updated Hive Witness...

Vote for me as your Hive Witness


If you want to support Brazilian creators...

Vote curator @perfilbrasil for Hive Witness

Delegations to perfilbrasil@perfilbrasil are rewarded here.

Leave Just a script I made to back up IPFS files into my personal Kubo. to:

Written by

Cientista da Computação formado pela UNISC. Gosto de feedback em minhas publicações, por isso peço que quem der "curtida" ou "thumbs-up" deixe uma mensagem, nem que seja uma única frase dizendo sua opinião. O mesmo vale para quem der flag.

Read more #ipfs posts


Best Posts From Fernando Soder

We have not curated any of fernandosoder's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Fernando Soder