Add Windows Batch Script for SQL Dump Splitting

This commit introduces a Windows batch (.bat) file as an alternative to the Python script for splitting SQL dumps. The batch script offers a convenient option for Windows users, especially those who prefer a quick, script-based solution without the need for Python. It reads a SQL dump file, identifies different databases, and creates separate SQL files for each database, ensuring ease of use and accessibility on Windows environments.
This commit is contained in:
Steve Dogiakos 2023-12-30 14:46:25 -07:00 committed by GitHub
parent ab4fadddbd
commit 991beaa9f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 0 deletions

27
split_sql_dump.bat Normal file
View File

@ -0,0 +1,27 @@
@echo off
setlocal enabledelayedexpansion
REM Set your SQL dump file name here
set "SQL_DUMP_FILE=your_dump.sql"
REM Variable to hold the current output file name
set "CURRENT_DB_FILE="
REM Read each line from the SQL dump
for /f "tokens=*" %%a in (%SQL_DUMP_FILE%) do (
REM Check if the line contains the database name
echo %%a | findstr /c:"-- Database: " >nul
if !errorlevel! == 0 (
REM Extract the database name and create a new file name
for /f "tokens=2 delims=`" %%b in ("%%a") do (
set "CURRENT_DB_FILE=%%b.sql"
)
)
REM If a current database file is set, append the line to it
if not "!CURRENT_DB_FILE!" == "" (
echo %%a >> !CURRENT_DB_FILE!
)
)
endlocal