99 lines
3.5 KiB
Bash
99 lines
3.5 KiB
Bash
#!/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 -eo pipefail
|
|
|
|
# Configuration
|
|
WALLET="main"
|
|
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
|
# Path as seen by the RIN daemon (relative to its /data directory)
|
|
DAEMON_BACKUP_FILE="/data/rin_wallet_backup_${TIMESTAMP}.txt"
|
|
# Actual system path where the file will be created
|
|
SYSTEM_BACKUP_FILE="/mnt/data/docker_vol/rincoin/rincoin-node/data/rin_wallet_backup_${TIMESTAMP}.txt"
|
|
|
|
# RPC Configuration
|
|
RPC_USER="rinrpc"
|
|
RPC_PASSWORD="745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90"
|
|
RPC_HOST="localhost"
|
|
RPC_PORT="9556"
|
|
|
|
# No need to create directory - daemon writes to its own /data
|
|
|
|
# Check if RIN node is running
|
|
if ! pgrep -f "rincoind" > /dev/null; then
|
|
echo "Error: RinCoin daemon is not running. Start it first."
|
|
exit 1
|
|
fi
|
|
|
|
# Ensure wallet is loaded
|
|
echo "Checking if wallet '${WALLET}' is loaded..."
|
|
LIST_WALLETS_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"jsonrpc": "2.0", "id": "listwallets", "method": "listwallets", "params": []}' \
|
|
"http://$RPC_HOST:$RPC_PORT")
|
|
|
|
if ! echo "$LIST_WALLETS_RESPONSE" | grep -q '"main"'; then
|
|
echo "Wallet '${WALLET}' not loaded. Attempting to load..."
|
|
LOAD_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"jsonrpc": "2.0", "id": "loadwallet", "method": "loadwallet", "params": ["'$WALLET'"]}' \
|
|
"http://$RPC_HOST:$RPC_PORT")
|
|
|
|
if echo "$LOAD_RESPONSE" | grep -q '"error"'; then
|
|
echo "Failed to load wallet. Response: $LOAD_RESPONSE"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo "Dumping wallet to: $DAEMON_BACKUP_FILE"
|
|
echo "This may take a moment..."
|
|
|
|
# Dump wallet using RPC (use daemon's path)
|
|
DUMP_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"jsonrpc": "2.0", "id": "dumpwallet", "method": "dumpwallet", "params": ["'$DAEMON_BACKUP_FILE'"]}' \
|
|
"http://$RPC_HOST:$RPC_PORT/wallet/$WALLET")
|
|
|
|
# Check for errors in dump response
|
|
if echo "$DUMP_RESPONSE" | grep -q '"error":null'; then
|
|
echo "✓ Wallet dump successful"
|
|
else
|
|
echo "Error dumping wallet: $DUMP_RESPONSE"
|
|
exit 1
|
|
fi
|
|
|
|
# Verify the file was created and has content (check system path)
|
|
if [[ ! -f "$SYSTEM_BACKUP_FILE" ]]; then
|
|
echo "Error: Backup file was not created at $SYSTEM_BACKUP_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
LINE_COUNT=$(wc -l < "$SYSTEM_BACKUP_FILE")
|
|
if [[ $LINE_COUNT -lt 10 ]]; then
|
|
echo "Warning: Backup file seems too small (${LINE_COUNT} lines). Check for errors."
|
|
exit 1
|
|
fi
|
|
|
|
# Copy backup to user's home directory for easy access
|
|
USER_BACKUP_DIR="${HOME}/rin_wallet_backups"
|
|
mkdir -p "$USER_BACKUP_DIR"
|
|
USER_BACKUP_FILE="${USER_BACKUP_DIR}/rin_wallet_backup_${TIMESTAMP}.txt"
|
|
cp "$SYSTEM_BACKUP_FILE" "$USER_BACKUP_FILE"
|
|
|
|
echo "✅ Wallet successfully backed up to: $USER_BACKUP_FILE"
|
|
echo ""
|
|
echo "🔐 SECURITY REMINDERS:"
|
|
echo " - This file contains private keys for ALL addresses in the wallet."
|
|
echo " - Encrypt it immediately: gpg -c $USER_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 "$USER_BACKUP_FILE" | cut -f1)"
|
|
echo "Lines: $LINE_COUNT"
|
|
|