#!/bin/bash # Script de restauration des données LeCoffre Node # Restaure Bitcoin, BlindBit, SDK Storage et SDK Signer set -e # Couleurs pour l'affichage RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color BACKUP_DIR="./backups" if [ $# -eq 0 ]; then echo -e "${RED}Usage: $0 ${NC}" echo -e "${YELLOW}Available backups:${NC}" ls -la "$BACKUP_DIR"/*.tar.gz 2>/dev/null | awk '{print " " $9}' | sed 's|.*/||' | sed 's|\.tar\.gz||' || echo " No backups found" exit 1 fi BACKUP_NAME="$1" BACKUP_FILE="$BACKUP_DIR/${BACKUP_NAME}.tar.gz" if [ ! -f "$BACKUP_FILE" ]; then echo -e "${RED}Error: Backup file $BACKUP_FILE not found${NC}" exit 1 fi echo -e "${BLUE}========================================${NC}" echo -e "${BLUE} LeCoffre Node - Data Restore${NC}" echo -e "${BLUE}========================================${NC}" echo echo -e "${YELLOW}Restoring from: $BACKUP_NAME${NC}" echo -e "${RED}WARNING: This will overwrite existing data!${NC}" echo -e "${YELLOW}Are you sure you want to continue? (y/N)${NC}" read -r response if [[ ! "$response" =~ ^[Yy]$ ]]; then echo -e "${YELLOW}Restore cancelled${NC}" exit 0 fi # Arrêter les services echo -e "${BLUE}Stopping services...${NC}" docker compose --env-file .env.master down >/dev/null 2>&1 || true # Extraire la sauvegarde echo -e "${BLUE}Extracting backup...${NC}" cd "$BACKUP_DIR" tar -xzf "${BACKUP_NAME}.tar.gz" cd .. # Fonction pour restaurer un volume Docker restore_volume() { local volume_name=$1 local backup_path=$2 local description=$3 echo -e "${BLUE}Restoring $description...${NC}" # Créer le volume s'il n'existe pas docker volume create "$volume_name" >/dev/null 2>&1 || true # Restaurer les données if [ -d "$BACKUP_DIR/$BACKUP_NAME$backup_path" ]; then docker run --rm \ -v "$volume_name":/target \ -v "$(pwd)/$BACKUP_DIR/$BACKUP_NAME$backup_path":/source:ro \ alpine:latest \ sh -c "rm -rf /target/* && cp -r /source/* /target/ 2>/dev/null || true" echo -e "${GREEN}✓ $description restored${NC}" else echo -e "${YELLOW}⚠ No backup data found for $description${NC}" fi } # Restaurer les volumes critiques restore_volume "4nk_node_bitcoin_data" "/bitcoin" "Bitcoin Signet Data" restore_volume "4nk_node_blindbit_data" "/blindbit" "BlindBit Oracle Data" restore_volume "4nk_node_sdk_data" "/sdk" "SDK Relay Data" restore_volume "4nk_node_sdk_storage_data" "/sdk_storage" "SDK Storage Data" restore_volume "4nk_node_grafana_data" "/grafana" "Grafana Data" restore_volume "4nk_node_loki_data" "/loki" "Loki Data" # Nettoyer les fichiers temporaires rm -rf "$BACKUP_DIR/$BACKUP_NAME" echo echo -e "${GREEN}✅ Data restoration completed successfully!${NC}" echo -e "${YELLOW}You can now start the services with: ./scripts/start.sh${NC}" echo