diff --git a/modules/backup/mysql-restore-to-sql.sh b/modules/backup/mysql-restore-to-sql.sh index 11eb358..0a37fdc 100755 --- a/modules/backup/mysql-restore-to-sql.sh +++ b/modules/backup/mysql-restore-to-sql.sh @@ -23,7 +23,19 @@ source "$SCRIPT_DIR/lib/system-detect.sh" # Root check if [ "$EUID" -ne 0 ]; then - print_error "This script must be run as root" + echo "" + print_error "PERMISSION DENIED: This script must be run as root" + echo "" + echo "Why root is required:" + echo " - Read access to live MySQL data directory (/var/lib/mysql)" + echo " - Create directories in /home (for temporary restore location)" + echo " - Change file ownership to mysql:mysql" + echo " - Start MySQL daemon (mysqld) process" + echo " - Access system configuration files" + echo "" + echo "To run this script:" + echo " sudo $0 $*" + echo "" exit 1 fi @@ -182,6 +194,12 @@ detect_mysql_datadir() { LIVE_DATADIR=$(mysql -NBe 'SELECT @@datadir;' 2>/dev/null) if [ -n "$LIVE_DATADIR" ]; then echo " Detected from running MySQL: $LIVE_DATADIR" + # Verify we can read this directory + if [ ! -r "$LIVE_DATADIR" ]; then + print_error "Cannot read MySQL data directory: Permission denied" + print_info "Try running this script with: sudo $0" + return 1 + fi return 0 fi fi @@ -191,6 +209,12 @@ detect_mysql_datadir() { if [ -n "$config_dir" ]; then LIVE_DATADIR="$config_dir" echo " Detected from config: $LIVE_DATADIR" + # Verify we can read this directory + if [ ! -r "$LIVE_DATADIR" ]; then + print_error "Cannot read MySQL data directory: Permission denied" + print_info "Try running this script with: sudo $0" + return 1 + fi return 0 fi @@ -198,6 +222,12 @@ detect_mysql_datadir() { if [ -d "/var/lib/mysql" ]; then LIVE_DATADIR="/var/lib/mysql" echo " Using default: $LIVE_DATADIR" + # Verify we can read this directory + if [ ! -r "$LIVE_DATADIR" ]; then + print_error "Cannot read MySQL data directory: Permission denied" + print_info "Try running this script with: sudo $0" + return 1 + fi return 0 fi