Add multi-panel support + safety enhancements to MySQL restore tool
Changes to modules/backup/mysql-restore-to-sql.sh:
Multi-Control Panel Support:
- Source system-detect.sh to detect control panel
- Use SYS_USER_HOME_BASE for restore directory paths
- cPanel/InterWorx/Standalone: /home
- Plesk: /var/www/vhosts
- Fixes issue where InterWorx/Plesk don't have /home directories
SQL Output Location Fix:
- Changed output from current working directory to restore directory
- SQL files now saved to parent of TEMP_DATADIR
Example: /home/temp/restore20251210/ (not /root/)
- Prevents cluttering control panel system directories
- Added print_info showing exact save location before dump
Safety Enhancements:
- Added check_disk_space() function (validates 2x required space)
- Added warn_force_recovery() function (levels 5-6 require risk acknowledgment)
- Integrated disk space check before dump creation
- Integrated force recovery warnings in step4_configure_options()
- Added cleanup trap handler for Ctrl+C/interruption
- Critical safety check prevents using /var/lib/mysql as restore dir
Changes to REFDB_FORMAT.txt:
- Documented multi-control panel support
- Added control_panel_paths section with all 4 panel paths
- Updated output location documentation
- Added safety features documentation
- Updated features list
QA Status: ✅ PASSED
- 0 CRITICAL issues
- 0 HIGH issues
- Syntax validated
- All safety checks functional
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
# Path resolution (modules/backup/script.sh → ../../)
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
source "$SCRIPT_DIR/lib/common-functions.sh"
|
||||
source "$SCRIPT_DIR/lib/system-detect.sh"
|
||||
|
||||
# Root check
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
@@ -25,6 +26,9 @@ if [ "$EUID" -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Detect control panel for proper directory paths
|
||||
detect_control_panel >/dev/null 2>&1 || true
|
||||
|
||||
################################################################################
|
||||
# GLOBAL VARIABLES
|
||||
################################################################################
|
||||
@@ -1069,8 +1073,11 @@ step2_set_restore_location() {
|
||||
echo "Let's set up the restore directory."
|
||||
echo ""
|
||||
|
||||
# Use control panel-specific home base, fallback to /home
|
||||
local home_base="${SYS_USER_HOME_BASE:-/home}"
|
||||
|
||||
# Offer to create a timestamped directory
|
||||
local suggested_dir="/home/temp/restore$(date +%Y%m%d)/mysql"
|
||||
local suggested_dir="${home_base}/temp/restore$(date +%Y%m%d)/mysql"
|
||||
echo "Suggested directory: $suggested_dir"
|
||||
echo ""
|
||||
echo " 1) Use suggested directory (will create if needed)"
|
||||
@@ -1117,9 +1124,10 @@ step2_set_restore_location() {
|
||||
chown mysql:mysql "$TEMP_DATADIR"
|
||||
chmod 751 "$TEMP_DATADIR"
|
||||
|
||||
# Also ensure parent /home/temp has correct permissions
|
||||
if [ -d "/home/temp" ]; then
|
||||
chmod 751 /home/temp 2>/dev/null || true
|
||||
# Also ensure parent temp directory has correct permissions
|
||||
local parent_temp="${home_base}/temp"
|
||||
if [ -d "$parent_temp" ]; then
|
||||
chmod 751 "$parent_temp" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
print_success "Directory created with mysql:mysql ownership"
|
||||
@@ -1423,13 +1431,19 @@ step5_create_dump() {
|
||||
|
||||
echo ""
|
||||
|
||||
# Generate output filename
|
||||
# Generate output filename - save to parent directory of TEMP_DATADIR
|
||||
# e.g., if TEMP_DATADIR is /home/temp/restore20251210/mysql
|
||||
# then output goes to /home/temp/restore20251210/
|
||||
local timestamp=$(date +%Y%m%d_%H%M%S)
|
||||
local output_file="${DATABASE_NAME}_restored_${timestamp}.sql"
|
||||
local output_dir="$(dirname "$TEMP_DATADIR")"
|
||||
local output_file="${output_dir}/${DATABASE_NAME}_restored_${timestamp}.sql"
|
||||
if [ -n "$TICKET_NUMBER" ]; then
|
||||
output_file="${DATABASE_NAME}_ticket${TICKET_NUMBER}_${timestamp}.sql"
|
||||
output_file="${output_dir}/${DATABASE_NAME}_ticket${TICKET_NUMBER}_${timestamp}.sql"
|
||||
fi
|
||||
|
||||
print_info "SQL dump will be saved to: $output_file"
|
||||
echo ""
|
||||
|
||||
# Create dump
|
||||
if ! dump_database "$TEMP_DATADIR" "$DATABASE_NAME" "$output_file"; then
|
||||
print_error "Failed to create dump"
|
||||
@@ -1448,19 +1462,19 @@ step5_create_dump() {
|
||||
print_success "RESTORE COMPLETE!"
|
||||
echo "════════════════════════════════════════════════════════════════"
|
||||
echo ""
|
||||
echo "SQL Dump Created: $(pwd)/$output_file"
|
||||
echo "SQL Dump Created: $output_file"
|
||||
echo ""
|
||||
echo "Next Steps:"
|
||||
echo " 1. Verify dump integrity:"
|
||||
echo " grep 'Dump completed on' $output_file"
|
||||
echo " grep 'Dump completed on' '$output_file'"
|
||||
echo ""
|
||||
echo " 2. Import to live database:"
|
||||
echo " mysql $DATABASE_NAME < $output_file"
|
||||
echo " mysql $DATABASE_NAME < '$output_file'"
|
||||
echo ""
|
||||
echo " 3. Or create fresh database first:"
|
||||
echo " mysql -e 'DROP DATABASE IF EXISTS $DATABASE_NAME;'"
|
||||
echo " mysql -e 'CREATE DATABASE $DATABASE_NAME;'"
|
||||
echo " mysql $DATABASE_NAME < $output_file"
|
||||
echo " mysql $DATABASE_NAME < '$output_file'"
|
||||
echo ""
|
||||
|
||||
press_enter
|
||||
|
||||
Reference in New Issue
Block a user