-
Star
(158)
You must be signed in to star a gist -
Fork
(45)
You must be signed in to fork a gist
-
-
Save josemmo/24e35f2b4984a4370ce2c164f5956437 to your computer and use it in GitHub Desktop.
# Based on this answer: https://stackoverflow.com/a/61859561/1956278 | |
# Backup old data | |
Rename-Item -Path "./data" -NewName "./data_old" | |
# Create new data directory | |
Copy-Item -Path "./backup" -Destination "./data" -Recurse | |
Remove-Item "./data/test" -Recurse | |
$dbPaths = Get-ChildItem -Path "./data_old" -Exclude ('mysql', 'performance_schema', 'phpmyadmin') -Recurse -Directory | |
Copy-Item -Path $dbPaths.FullName -Destination "./data" -Recurse | |
Copy-Item -Path "./data_old/ibdata1" -Destination "./data/ibdata1" | |
# Notify user | |
Write-Host "Finished repairing MySQL data" | |
Write-Host "Previous data is located at ./data_old" |
I realize existing Database was not able to access and getting error.
Equivalent bash scripts is
`@echo off REM Backup old data rename "data" "data_old"
REM Create new data directory xcopy "backup" "data" /E /I rmdir /S /Q "data\test"
REM Copy directories excluding specific ones (mysql, performance_schema, phpmyadmin) for /d %%i in (data_old*) do ( if /i not "%%~nxi"=="mysql" ( if /i not "%%~nxi"=="performance_schema" ( if /i not "%%~nxi"=="phpmyadmin" ( xcopy "%%i" "data%%~nxi" /E /I ) ) ) )
REM Copy ibdata1 file copy "data_old\ibdata1" "data\ibdata1"
REM Notify user echo Finished repairing MySQL data echo Previous data is located at ./data_old ` Run this inside mysql directory, save it like repair.bat , easier to save using notepad++, select bat for file type
I've edited this code a bit to include PWD support as my install had issues jumping between disks. ^^
@echo off
REM Change directory to the MySQL directory
cd /d "D:\Path\To\XAMPP\mysql"
REM Backup old data
rename "data" "data_old"
REM Create new data directory
xcopy "backup" "data" /E /I
rmdir /S /Q "data\test"
REM Copy directories excluding specific ones (mysql, performance_schema, phpmyadmin)
for /d %%i in (data_old\*) do (
if /i not "%%~nxi"=="mysql" (
if /i not "%%~nxi"=="performance_schema" (
if /i not "%%~nxi"=="phpmyadmin" (
xcopy "%%i" "data\%%~nxi" /E /I
)
)
)
)
REM Copy ibdata1 file
copy "data_old\ibdata1" "data\ibdata1"
REM Notify user
echo Finished repairing MySQL data
echo Previous data is located at .\data_old
pause
Thank you, Great work !
@echo off REM Change directory to the MySQL directory cd /d "D:\Path\To\XAMPP\mysql" REM Backup old data rename "data" "data_old" REM Create new data directory xcopy "backup" "data" /E /I rmdir /S /Q "data\test" REM Copy directories excluding specific ones (mysql, performance_schema, phpmyadmin) for /d %%i in (data_old\*) do ( if /i not "%%~nxi"=="mysql" ( if /i not "%%~nxi"=="performance_schema" ( if /i not "%%~nxi"=="phpmyadmin" ( xcopy "%%i" "data\%%~nxi" /E /I ) ) ) ) REM Copy ibdata1 file copy "data_old\ibdata1" "data\ibdata1" REM Notify user echo Finished repairing MySQL data echo Previous data is located at .\data_old pause
Thanks, this code works correctly.
One of the best gists