RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
feat(migration): support docker compose -p project name for backup/restore (#13191)
Ray Zhangcbe64402dbd1
diff --git a/docker/migration.sh b/docker/migration.shindex 35adab505e..b881dbc45e 100644--- a/docker/migration.sh+++ b/docker/migration.sh@@ -1,8 +1,8 @@#!/bin/bash# RAGFlow Data Migration Script-# Usage: ./migration.sh [backup|restore] [backup_folder]-#+# Usage: ./migration.sh [-p project_name] [backup|restore] [backup_folder]+## This script helps you backup and restore RAGFlow Docker volumes# including MySQL, MinIO, Redis, and Elasticsearch data.@@ -11,35 +11,55 @@ set -e # Exit on any error# Default valuesDEFAULT_BACKUP_FOLDER="backup"-VOLUMES=("docker_mysql_data" "docker_minio_data" "docker_redis_data" "docker_esdata01")+DEFAULT_PROJECT_NAME="docker"+VOLUME_BASES=("mysql_data" "minio_data" "redis_data" "esdata01")BACKUP_FILES=("mysql_backup.tar.gz" "minio_backup.tar.gz" "redis_backup.tar.gz" "es_backup.tar.gz")+# Build volume names from project name and base names+build_volume_names() {+ VOLUMES=()+ for base in "${VOLUME_BASES[@]}"; do+ VOLUMES+=("${PROJECT_NAME}_${base}")+ done+}+# Function to display help informationshow_help() {echo "RAGFlow Data Migration Tool"echo ""echo "USAGE:"- echo " $0 <operation> [backup_folder]"+ echo " $0 [-p project_name] <operation> [backup_folder]"echo ""echo "OPERATIONS:"echo " backup - Create backup of all RAGFlow data volumes"echo " restore - Restore RAGFlow data volumes from backup"echo " help - Show this help message"echo ""+ echo "OPTIONS:"+ echo " -p project_name - Docker Compose project name (default: '$DEFAULT_PROJECT_NAME')"+ echo " Use this when you started RAGFlow with 'docker compose -p <name>'"+ echo ""echo "PARAMETERS:"- echo " backup_folder - Name of backup folder (default: '$DEFAULT_BACKUP_FOLDER')"+ echo " backup_folder - Name of backup folder (default: '$DEFAULT_BACKUP_FOLDER')"echo ""echo "EXAMPLES:"- echo " $0 backup # Backup to './backup' folder"- echo " $0 backup my_backup # Backup to './my_backup' folder"- echo " $0 restore # Restore from './backup' folder"- echo " $0 restore my_backup # Restore from './my_backup' folder"+ echo " $0 backup # Backup with default project name 'docker'"+ echo " $0 backup my_backup # Backup to './my_backup' folder"+ echo " $0 restore # Restore from './backup' folder"+ echo " $0 restore my_backup # Restore from './my_backup' folder"+ echo " $0 -p ragflow backup # Backup volumes for project 'ragflow'"+ echo " $0 -p ragflow restore my_backup # Restore volumes for project 'ragflow'"+ echo ""+ echo "DOCKER VOLUMES (with default project name '$DEFAULT_PROJECT_NAME'):"+ echo " - ${DEFAULT_PROJECT_NAME}_mysql_data (MySQL database)"+ echo " - ${DEFAULT_PROJECT_NAME}_minio_data (MinIO object storage)"+ echo " - ${DEFAULT_PROJECT_NAME}_redis_data (Redis cache)"+ echo " - ${DEFAULT_PROJECT_NAME}_esdata01 (Elasticsearch indices)"echo ""- echo "DOCKER VOLUMES:"- echo " - docker_mysql_data (MySQL database)"- echo " - docker_minio_data (MinIO object storage)"- echo " - docker_redis_data (Redis cache)"- echo " - docker_esdata01 (Elasticsearch indices)"+ echo "NOTE:"+ echo " If you started RAGFlow with 'docker compose -p myproject up', the volume"+ echo " names will be prefixed with 'myproject' instead of 'docker'. In that case,"+ echo " use '-p myproject' with this script to match the correct volumes."}# Function to check if Docker is running@@ -60,23 +80,23 @@ volume_exists() {# Function to check if any containers are using the target volumescheck_containers_using_volumes() {echo "π Checking for running containers that might be using target volumes..."-+# Get all running containerslocal running_containers=$(docker ps --format "{{.Names}}")-+if [ -z "$running_containers" ]; thenecho "β No running containers found"return 0fi-+# Check each running container for volume usagelocal containers_using_volumes=()local volume_usage_details=()-+for container in $running_containers; do# Get container's mount informationlocal mounts=$(docker inspect "$container" --format '{{range .Mounts}}{{.Source}}{{"|"}}{{end}}' 2>/dev/null || echo "")-+# Check if any of our target volumes are used by this containerfor volume in "${VOLUMES[@]}"; doif echo "$mounts" | grep -q "$volume"; then@@ -86,7 +106,7 @@ check_containers_using_volumes() {fidonedone-+# If any containers are using our volumes, show error and exitif [ ${#containers_using_volumes[@]} -gt 0 ]; thenecho ""@@ -100,15 +120,19 @@ check_containers_using_volumes() {echo " - $detail"doneecho ""- echo "π SOLUTION: Stop the containers before performing backup/restore operations:"- echo " docker-compose -f docker/<your-docker-compose-file>.yml down"+ if [ "$PROJECT_NAME" = "$DEFAULT_PROJECT_NAME" ]; then+ echo "π SOLUTION: Stop the containers before performing backup/restore operations:"+ echo " docker compose -f docker/<your-docker-compose-file>.yml down"+ else+ echo "π SOLUTION: Stop the containers before performing backup/restore operations:"+ echo " docker compose -p $PROJECT_NAME -f docker/<your-docker-compose-file>.yml down"+ fiecho ""- echo "π‘ After backup/restore, you can restart with:"- echo " docker-compose -f docker/<your-docker-compose-file>.yml up -d"+ echo "π‘ After backup/restore, you can restart with the corresponding 'up -d' command."echo ""exit 1fi-+echo "β No containers are using target volumes, safe to proceed"return 0}@@ -127,25 +151,28 @@ confirm_action() {# Function to perform backupperform_backup() {local backup_folder=$1-+echo "π Starting RAGFlow data backup..."echo "π Backup folder: $backup_folder"+ echo "π·οΈ Project name: $PROJECT_NAME"echo ""-+# Check if any containers are using the volumescheck_containers_using_volumes-+# Create backup folder if it doesn't existmkdir -p "$backup_folder"-++ local total=${#VOLUMES[@]}+# Backup each volumefor i in "${!VOLUMES[@]}"; dolocal volume="${VOLUMES[$i]}"local backup_file="${BACKUP_FILES[$i]}"local step=$((i + 1))-- echo "π¦ Step $step/4: Backing up $volume..."-++ echo "π¦ Step $step/$total: Backing up $volume..."+if volume_exists "$volume"; thendocker run --rm \-v "$volume":/source \@@ -157,10 +184,10 @@ perform_backup() {fiecho ""done-+echo "π Backup completed successfully!"echo "π Backup location: $(pwd)/$backup_folder"-+# List backup files with sizesecho ""echo "π Backup files created:"@@ -175,20 +202,21 @@ perform_backup() {# Function to perform restoreperform_restore() {local backup_folder=$1-+echo "π Starting RAGFlow data restore..."echo "π Backup folder: $backup_folder"+ echo "π·οΈ Project name: $PROJECT_NAME"echo ""-+# Check if any containers are using the volumescheck_containers_using_volumes-+# Check if backup folder existsif [ ! -d "$backup_folder" ]; thenecho "β Error: Backup folder '$backup_folder' does not exist"exit 1fi-+# Check if all backup files existlocal missing_files=()for backup_file in "${BACKUP_FILES[@]}"; do@@ -196,7 +224,7 @@ perform_restore() {missing_files+=("$backup_file")fidone-+if [ ${#missing_files[@]} -gt 0 ]; thenecho "β Error: Missing backup files:"for file in "${missing_files[@]}"; do@@ -205,7 +233,7 @@ perform_restore() {echo "Please ensure all backup files are present in '$backup_folder'"exit 1fi-+# Check for existing volumes and warn userlocal existing_volumes=()for volume in "${VOLUMES[@]}"; do@@ -213,7 +241,7 @@ perform_restore() {existing_volumes+=("$volume")fidone-+if [ ${#existing_volumes[@]} -gt 0 ]; thenecho "β οΈ WARNING: The following Docker volumes already exist:"for volume in "${existing_volumes[@]}"; do@@ -222,23 +250,25 @@ perform_restore() {echo ""echo "π΄ IMPORTANT: Restoring will OVERWRITE existing data!"echo "π‘ Recommendation: Create a backup of your current data first:"- echo " $0 backup current_backup_$(date +%Y%m%d_%H%M%S)"+ echo " $0 -p $PROJECT_NAME backup current_backup_$(date +%Y%m%d_%H%M%S)"echo ""-+if ! confirm_action "Do you want to continue with the restore operation?"; thenecho "β Restore operation cancelled by user"exit 0fifi-++ local total=${#VOLUMES[@]}+# Create volumes and restore datafor i in "${!VOLUMES[@]}"; dolocal volume="${VOLUMES[$i]}"local backup_file="${BACKUP_FILES[$i]}"local step=$((i + 1))-- echo "π§ Step $step/4: Restoring $volume..."-++ echo "π§ Step $step/$total: Restoring $volume..."+# Create volume if it doesn't existif ! volume_exists "$volume"; thenecho " π Creating Docker volume: $volume"@@ -246,18 +276,18 @@ perform_restore() {elseecho " π Using existing Docker volume: $volume"fi-+# Restore dataecho " π₯ Restoring data from $backup_file..."docker run --rm \-v "$volume":/target \-v "$(pwd)/$backup_folder":/backup \alpine tar xzf "/backup/$backup_file" -C /target-+echo "β Successfully restored $volume"echo ""done-+echo "π Restore completed successfully!"echo "π‘ You can now start your RAGFlow services"}@@ -266,17 +296,38 @@ perform_restore() {main() {# Check if Docker is availablecheck_docker-- # Parse command line arguments++ # Parse -p flag+ PROJECT_NAME="$DEFAULT_PROJECT_NAME"+ while [ $# -gt 0 ]; do+ case "$1" in+ -p)+ if [ -z "${2:-}" ]; then+ echo "β Error: -p requires a project name argument"+ exit 1+ fi+ PROJECT_NAME="$2"+ shift 2+ ;;+ *)+ break+ ;;+ esac+ done++ # Build volume names based on project name+ build_volume_names++ # Parse remaining positional argumentslocal operation=${1:-}local backup_folder=${2:-$DEFAULT_BACKUP_FOLDER}-+# Handle help or no argumentsif [ -z "$operation" ] || [ "$operation" = "help" ] || [ "$operation" = "-h" ] || [ "$operation" = "--help" ]; thenshow_helpexit 0fi-+# Validate operationcase "$operation" inbackup)@@ -295,4 +346,4 @@ main() {}# Run main function with all arguments-main "$@"\ No newline at end of file+main "$@"