diff --git a/modules/backup/mysql-restore-to-sql.sh b/modules/backup/mysql-restore-to-sql.sh index fbe6577..1bdff9d 100755 --- a/modules/backup/mysql-restore-to-sql.sh +++ b/modules/backup/mysql-restore-to-sql.sh @@ -1233,6 +1233,8 @@ dump_database() { # INTERACTIVE WORKFLOW ################################################################################ +# Display the welcome banner and script overview to the user +# Explains what the script does and shows required steps show_intro() { clear print_banner "MySQL/MariaDB File-Based Restore" @@ -1290,6 +1292,9 @@ show_intro() { echo "" } +# Step 1: Auto-detect or prompt for live MySQL data directory +# Looks for running MySQL instance or attempts to find config file +# Sets LIVE_DATADIR variable for use in later steps step1_detect_datadir() { print_banner "Step 1: Detect Live MySQL Data Directory" @@ -1341,6 +1346,10 @@ step1_detect_datadir() { press_enter } +# Step 2: Configure temporary location for restored MySQL data +# Allows user to choose suggested directory or provide custom path +# Validates path for safety (no traversal, not live MySQL dir) +# Sets TEMP_DATADIR variable for second MySQL instance step2_set_restore_location() { print_banner "Step 2: Set Restored Data Location" @@ -1575,6 +1584,10 @@ step2_set_restore_location() { press_enter } +# Step 3: Allow user to select which database to extract from the restored data +# Lists available databases from TEMP_DATADIR and prompts for selection +# Validates database directory exists before proceeding +# Sets DATABASE_NAME variable for dump operation step3_select_database() { print_banner "Step 3: Select Database to Restore" @@ -1641,6 +1654,10 @@ step3_select_database() { press_enter } +# Step 4: Configure InnoDB recovery options and ticket information +# Allows user to set InnoDB force recovery level if needed (0-6) +# Prompts for optional ticket number for tracking purposes +# Shows analysis-based recovery recommendations from error logs step4_configure_options() { print_banner "Step 4: Configure Restore Options" @@ -1700,6 +1717,10 @@ step4_configure_options() { press_enter } +# Step 5: Create SQL dump from the restored database using second MySQL instance +# Starts isolated MySQL instance, dumps selected database, validates integrity +# Generates .sql file with optional ticket number in filename +# Cleans up second instance and provides import instructions step5_create_dump() { print_banner "Step 5: Create SQL Dump" @@ -1813,6 +1834,10 @@ step5_create_dump() { # MAIN EXECUTION ################################################################################ +# Main entry point: orchestrates the 5-step workflow to extract SQL from restored backup +# Detects MySQL location, validates restore files, starts second instance, +# creates SQL dump, and provides usage instructions +# Handles errors and signal interrupts with proper cleanup main() { show_intro echo -n "Continue? (y/n, or 0 to cancel): "