**Motivations:** - Export Signet and mining wallet backups to git with only 2 versions kept - Document and add backup/restore scripts for signet and mining wallet **Correctifs:** - Backup-to-git uses SSH URL for passwordless cron; copy timestamped files only; prune to 2 versions; remove *-latest from backup repo **Evolutions:** - data/backup-to-git-cron.sh: daily export to git.4nkweb.com/4nk/backup - save-signet-datadir-backup.sh, restore-signet-from-backup.sh, export-mining-wallet.sh, import-mining-wallet.sh - features/backup-to-git-daily-cron.md, docs/MAINTENANCE.md backup section - .gitignore: data/backup-to-git.log **Pages affectées:** - .gitignore, data/backup-to-git-cron.sh, docs/MAINTENANCE.md, features/backup-to-git-daily-cron.md - save-signet-datadir-backup.sh, restore-signet-from-backup.sh, export-mining-wallet.sh, import-mining-wallet.sh - Plus autres fichiers modifiés ou non suivis déjà présents dans le working tree
66 lines
2.5 KiB
Bash
Executable File
66 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Restore the Bitcoin Signet chain from a full datadir backup (tar.gz).
|
|
# Use this to resume on the previous chain (e.g. height ~11535) after data loss.
|
|
#
|
|
# Prerequisite: a backup created with save-signet-datadir-backup.sh
|
|
# (or: docker exec bitcoin-signet-instance tar czf /tmp/bitcoin-backup.tar.gz /root/.bitcoin/
|
|
# docker cp bitcoin-signet-instance:/tmp/bitcoin-backup.tar.gz ./backups/)
|
|
#
|
|
# Usage: ./restore-signet-from-backup.sh <path-to-backup.tar.gz>
|
|
# Example: ./restore-signet-from-backup.sh backups/bitcoin-backup-20260124.tar.gz
|
|
#
|
|
# Author: 4NK Team
|
|
# Date: 2026-02-02
|
|
|
|
set -e
|
|
|
|
CONTAINER_NAME="bitcoin-signet-instance"
|
|
VOLUME_NAME="signet-bitcoin-data"
|
|
BACKUP_PATH="${1:?Usage: $0 <path-to-backup.tar.gz>}"
|
|
|
|
if [[ ! -f "$BACKUP_PATH" ]]; then
|
|
echo "Error: Backup file not found: $BACKUP_PATH"
|
|
exit 1
|
|
fi
|
|
|
|
BACKUP_PATH=$(realpath "$BACKUP_PATH")
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cd "$SCRIPT_DIR"
|
|
|
|
echo "=== Restore Signet from backup ==="
|
|
echo "Backup: $BACKUP_PATH"
|
|
echo "Volume: $VOLUME_NAME"
|
|
echo ""
|
|
|
|
if docker ps -a --format "{{.Names}}" | grep -q "^${CONTAINER_NAME}$"; then
|
|
echo "Stopping and removing current container..."
|
|
sudo docker stop "$CONTAINER_NAME" 2>/dev/null || true
|
|
sudo docker rm "$CONTAINER_NAME" 2>/dev/null || true
|
|
fi
|
|
|
|
echo "Creating volume $VOLUME_NAME if needed..."
|
|
sudo docker volume create "$VOLUME_NAME" 2>/dev/null || true
|
|
|
|
echo "Extracting backup into volume..."
|
|
# Archive may contain root/.bitcoin/... (from tar czf -C / root/.bitcoin) or .bitcoin/...
|
|
# Volume is mounted at /root/.bitcoin; extract to / then ensure content is under /root/.bitcoin
|
|
sudo docker run --rm \
|
|
-v "$VOLUME_NAME":/restore_target \
|
|
-v "$BACKUP_PATH":/backup.tar.gz:ro \
|
|
debian:bookworm-slim \
|
|
sh -c "cd / && tar xzf /backup.tar.gz && if [ -d /root/.bitcoin ] && [ -n \"\$(ls -A /root/.bitcoin 2>/dev/null)\" ]; then cp -a /root/.bitcoin/. /restore_target/; elif [ -d /.bitcoin ]; then cp -a /.bitcoin/. /restore_target/; else echo 'Unexpected archive layout' && exit 1; fi"
|
|
|
|
echo "Starting container with restored data..."
|
|
sudo docker run --env-file .env -d \
|
|
--name "$CONTAINER_NAME" \
|
|
-v "$VOLUME_NAME":/root/.bitcoin \
|
|
-p 38332:38332 -p 38333:38333 \
|
|
-p 28332:28332 -p 28333:28333 -p 28334:28334 \
|
|
bitcoin-signet
|
|
|
|
echo ""
|
|
echo "Container started. Check height with:"
|
|
echo " sudo docker exec $CONTAINER_NAME bitcoin-cli -datadir=\$(docker exec $CONTAINER_NAME printenv BITCOIN_DIR 2>/dev/null || echo /root/.bitcoin) getblockchaininfo"
|
|
echo ""
|