Template:MySQLdump Windows: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
MySQLdump script for Windows OSes using MySQLdump is possible, and the tool is typically provided along with the mysql/mariadb-server installation.
MySQLdump script for Windows OSes using MySQLdump is possible, and the tool is typically provided along with the mysql/mariadb-server installation. This is a script that can be used either manually or be hung into a time-repetitive scheduler. Log files are created with filenames that have a timestamp built-in, so older backups will not be overwritten. Copy the script below into your favorite text-editor and save it as a .bat (batch) file into the location+filename of your choosing. You can export database contents for the Kodi video library, music library, and the database user for the Kodi application.
 
This is a script that can be used either manually or be hung into a time-repetitive scheduler. Log files are created with filenames that have a timestamp built-in, so older backups will not be overwritten.
 
Copy the script below into your favorite text-editor and save it as a .bat (batch) file into the location+filename of your choosing.
 
You can export database contents for the Kodi video library, music library, and the database user for the Kodi application.


<syntaxhighlight lang="dos">
<syntaxhighlight lang="dos">
Line 16: Line 10:
echo "-------------------------------------------"
echo "-------------------------------------------"


REM TESTED ON WINDOWS 11 Pro with MYSQL SERVER 5.7.36 ON UBUNTU SERVER 18.04
REM UNTESTED SCRIPT !!
REM TO BE TESTED ON WINDOWS 11 Pro with MYSQL SERVER 5.7.36 ON UBUNTU SERVER 18.04


SET A/ timestamp = $(date +"%Y%m%d_%H%M");
REM SET FORMATTED TIMESTAMP
SET A/ timestamp=%date:~0,2%_%time:~0,2%_%time:~3,2%_%time:~6,2%


REM EXPORT PATH, ADJUST TO YOUR OWN CONVENIENCE
REM EXPORT PATH, ADJUST TO YOUR OWN CONVENIENCE
SET A/ ="/home/user/Dropbox/MySQL/kodidtbs_v19_""$timestamp""_"
SET A/ path="/home/user/Dropbox/MySQL/kodidtbs_v19_""%timestamp%""_"


REM FILENAMES
REM FILENAMES
SET A/ video_export = %path% + "video.sql"
SET A/ video_export=%path% + "video.sql"
SET A/ music_export = %path% + "music.sql"
SET A/ music_export=%path% + "music.sql"
SET A/ user_export = %path% + "user.sql"
SET A/ user_export =%path% + "user.sql"


REM USER PARAMETERS TO EDIT ACCORDING TO YOUR DATABASE SERVER, CREDENTIALS AND PORT SITUATION
REM USER PARAMETERS TO EDIT ACCORDING TO YOUR DATABASE SERVER, CREDENTIALS AND PORT SITUATION
SET A/ user = " --user=kodi --password=kodi"
SET A/ user=" --user=kodi --password=kodi"
SET A/ srvr = " --host=srvr1 "
SET A/ srvr=" --host=srvr1 "
SET A/ port = " --port=3306 "
SET A/ port=" --port=3306 "


REM FIXED PARAMETERS FOR KODI DATABASES
REM FIXED PARAMETERS FOR KODI DATABASES
SET A/ params = " --add-drop-database --add-drop-table --add-drop-trigger --routines --triggers "
SET A/ params=" --add-drop-database --add-drop-table --add-drop-trigger --routines --triggers "


REM VARIABLE PARAMETERS FOR KODI DATABASES
REM VARIABLE PARAMETERS FOR KODI DATABASES
SET A/ video = " --databases MyVideos119 "
SET A/ video=" --databases MyVideos119 "
SET A/ music = " --databases MyMusic82 "
SET A/ music=" --databases MyMusic82 "


REM ---------------------------------------------------------------------------------------
REM ---------------------------------------------------------------------------------------
Line 45: Line 41:
for %%x in (%*) do (
for %%x in (%*) do (
REM CHECK FOR VIDEO
REM CHECK FOR VIDEO
if (%%x == "v") OR (%%x == "video") echo "Exporting video to : ""$video_export"; mysqldump $user $srvr $params $video > $video_export
if (%%x == "v") OR (%%x == "video") echo "Exporting video to : %video_export%"; mysqldump %user% %srvr% %params% %video% > %video_export%
if (%%x == "m") OR (%%x == "music") echo "Exporting music to : ""$music_export"; mysqldump $user $srvr $params $music > $music_export
if (%%x == "m") OR (%%x == "music") echo "Exporting music to : %music_export%"; mysqldump %user% %srvr% %params% %music% > %music_export%
if (%%x == "u") OR (%%x == "user")  echo "Exporting user to : " "$user_export";  mysqldump $user $srvr $params --where="User='kodi'" > $user_export
if (%%x == "u") OR (%%x == "user")  echo "Exporting user to : "%$user_export%;  mysqldump %user% %srvr% %params% --where="User='kodi'" > %user_export%
)
)


Line 66: Line 62:


REM EXIT
REM EXIT


</syntaxhighlight >
</syntaxhighlight >

Latest revision as of 09:47, 26 January 2022

MySQLdump script for Windows OSes using MySQLdump is possible, and the tool is typically provided along with the mysql/mariadb-server installation. This is a script that can be used either manually or be hung into a time-repetitive scheduler. Log files are created with filenames that have a timestamp built-in, so older backups will not be overwritten. Copy the script below into your favorite text-editor and save it as a .bat (batch) file into the location+filename of your choosing. You can export database contents for the Kodi video library, music library, and the database user for the Kodi application.


cls
@echo off

echo " "
echo "MYSQLDUMP databases Kodi v19+ video & music"
echo "-------------------------------------------"

REM UNTESTED SCRIPT !!
REM TO BE TESTED ON WINDOWS 11 Pro with MYSQL SERVER 5.7.36 ON UBUNTU SERVER 18.04

REM SET FORMATTED TIMESTAMP
SET A/ timestamp=%date:~0,2%_%time:~0,2%_%time:~3,2%_%time:~6,2%

REM EXPORT PATH, ADJUST TO YOUR OWN CONVENIENCE
SET A/ path="/home/user/Dropbox/MySQL/kodidtbs_v19_""%timestamp%""_"

REM FILENAMES
SET A/ video_export=%path% + "video.sql"
SET A/ music_export=%path% + "music.sql"
SET A/ user_export =%path% + "user.sql"

REM USER PARAMETERS TO EDIT ACCORDING TO YOUR DATABASE SERVER, CREDENTIALS AND PORT SITUATION
SET A/ user=" --user=kodi --password=kodi"
SET A/ srvr=" --host=srvr1 "
SET A/ port=" --port=3306 "

REM FIXED PARAMETERS FOR KODI DATABASES
SET A/ params=" --add-drop-database --add-drop-table --add-drop-trigger --routines --triggers "

REM VARIABLE PARAMETERS FOR KODI DATABASES
SET A/ video=" --databases MyVideos119 "
SET A/ music=" --databases MyMusic82 "

REM ---------------------------------------------------------------------------------------

REM CHECK IF USER-GIVEN ARGUMENTS ARE PRESENT
for %%x in (%*) do (
	REM CHECK FOR VIDEO
	if (%%x == "v") OR (%%x == "video") echo "Exporting video to : %video_export%"; mysqldump %user% %srvr% %params% %video% > %video_export%
	if (%%x == "m") OR (%%x == "music") echo "Exporting music to : %music_export%"; mysqldump %user% %srvr% %params% %music% > %music_export%
	if (%%x == "u") OR (%%x == "user")  echo "Exporting user to : "%$user_export%;  mysqldump %user% %srvr% %params% --where="User='kodi'" > %user_export%
)

if (%%x ='')
	echo "EXAMPLE: dtbs-export.bat video ";
	echo " ";
	echo "Possible user parameters:";
	echo "  v or video";
	echo "  m or music";
	echo "  u or user";
	echo "  all";
	echo " ";
	echo "Note: for importing full Kodi database exports, you need SQL database root user access";
	echo "";
	echo "For a complete guide, type: 'mysqldump --help' or 'man mysqldump' ";
	echo " ";
fi

REM EXIT