#!/bin/bash # RinCoin Wallet Backup Script # Dumps all private keys to a secure text file for backup. # WARNING: This file contains sensitive private keys. Store it securely (encrypted, offline). # Do not share or email it. Anyone with this file can spend your coins. set -euo pipefail # Configuration CONTAINER="rincoin-node" WALLET="main" BACKUP_DIR="${HOME}/rin_wallet_backups" TIMESTAMP=$(date +%Y%m%d_%H%M%S) BACKUP_FILE="${BACKUP_DIR}/rin_wallet_backup_${TIMESTAMP}.txt" # Ensure backup directory exists mkdir -p "$BACKUP_DIR" # Check if container is running if ! sudo docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then echo "Error: ${CONTAINER} container is not running. Start it with 'sudo docker start ${CONTAINER}'." exit 1 fi # Ensure wallet is loaded CLI_CMD=(sudo docker exec "$CONTAINER" rincoin-cli -datadir=/data -conf=/data/rincoin.conf -rpcwallet="$WALLET") if ! "${CLI_CMD[@]//-rpcwallet=$WALLET/}" listwallets | grep -q '"main"'; then echo "Wallet '${WALLET}' not loaded. Attempting to load..." "${CLI_CMD[@]//-rpcwallet=$WALLET/}" loadwallet "$WALLET" >/dev/null 2>&1 || { echo "Failed to load wallet. Ensure it exists." exit 1 } fi echo "Dumping wallet to: $BACKUP_FILE" echo "This may take a moment..." # Dump wallet "${CLI_CMD[@]}" dumpwallet "$BACKUP_FILE" # Verify the file was created and has content if [[ ! -f "$BACKUP_FILE" ]]; then echo "Error: Backup file was not created." exit 1 fi LINE_COUNT=$(wc -l < "$BACKUP_FILE") if [[ $LINE_COUNT -lt 10 ]]; then echo "Warning: Backup file seems too small (${LINE_COUNT} lines). Check for errors." exit 1 fi echo "✅ Wallet successfully backed up to: $BACKUP_FILE" echo "" echo "🔐 SECURITY REMINDERS:" echo " - This file contains private keys for ALL addresses in the wallet." echo " - Encrypt it immediately: gpg -c $BACKUP_FILE" echo " - Store on encrypted media (e.g., USB drive in safe)." echo " - Delete the unencrypted file after encryption." echo " - Test restoration on a testnet node before relying on it." echo "" echo "File size: $(du -h "$BACKUP_FILE" | cut -f1)" echo "Lines: $LINE_COUNT"