Hi,
I've created a windows batch script to solve the issue below, however, it takes around 10 minutes for around 20k lines. This is too long.
This can be faster, that's when I found JREPL.
So, I'm new to using JREPL and I cannot figure this one out.
Some background information;
I'm using MYSQLDUMP to make a backup of a database's structure.
Unfortunately, the output is one big file.
The next, and missing, step would be to split this file into multiple files.
For this, I'm focusing on routines only.
This is what a part of the dump would look like:
Code: Select all
DELIMITER ;;
CREATE DEFINER=`rm_su`@`%` PROCEDURE `sp_name_1`()
BEGIN
some code
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_change_pl_for_project` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
DELIMITER ;;
CREATE DEFINER=`rm_su`@`%` PROCEDURE `sp_name_2`(
some variables
)
BEGIN
some code
END ;;
DELIMITER ;
The output should be 2 separate files:
sp_name_1.sql
Code: Select all
DELIMITER ;;
CREATE DEFINER=`rm_su`@`%` PROCEDURE `sp_name_1`()
BEGIN
some code
END ;;
DELIMITER ;
sp_name_2.sql
Code: Select all
DELIMITER ;;
CREATE DEFINER=`rm_su`@`%` PROCEDURE `sp_name_2`(
some variables
)
BEGIN
some code
END ;;
DELIMITER ;
This extracts all data, including start (DELIMITER ;;) and end (DELIMITER ; ) strings into one file, just doesn't split them:
Code: Select all
jrepl "^[ \t]*DELIMITER ;;[\s\S]*?^\s*DELIMITER ;.*$" $0 /m /jmatch /f "dump.sql" /o output.sql
Something like this should work, I'm making a mistake somewhere, don't know what I'm doing wrong though.
Code: Select all
jrepl "^(DELIMITER ;;$[\s\S]*PROCEDURE `([a-zA-z]+)`[\s\S]*^DELIMITER ;)$" "openOutput($2.sql);$txt=$0" /m /jq /f "dump.sql"
Thanks in advance