找到MySQL和Cassandra的正确PATH

时间:2021-03-11 02:09:19

I have a .BAT file for db backup that is setting up the paths for the sql server and cassandra, if the user don't install those applications in the same path the Backup it's going to fail.

我有一个用于db备份的.BAT文件,它正在为sql server和cassandra设置路径,如果用户没有在同一路径中安装那些应用程序将失败的应用程序。

Actually the .BAT file sets up the paths as follows:

实际上.BAT文件设置路径如下:

SET "CASSANDRA_DATA_PATH=C:\Program Files\DataStax Community\data\data"
SET "MSSQL_BACK_PATH=C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup"

So, if the user has another version of SQL Server the backup is not going to work neither.

因此,如果用户具有其他版本的SQL Server,则备份也不会起作用。

Instead of that, the .BAT file should find the correct paths and versions before executing the script.

而不是那样,.BAT文件应该在执行脚本之前找到正确的路径和版本。

Any idea how to do this?

知道怎么做吗?

2 个解决方案

#1


If the Casandra is not some kind of portable database , after its installation it should store information about itself in registry somewhere under HKEY_LOCAL_MACHINE\SOFTWARE\ . I'd never used casandra so you'll need to find by yourself where the data is stored. As for the MS SQL:

如果Casandra不是某种便携式数据库,安装后它应该在HKEY_LOCAL_MACHINE \ SOFTWARE \下的某个地方存储有关自身的信息。我从未使用过casandra,因此您需要自己找到存储数据的位置。至于MS SQL:

    @echo off 


    for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions"') do set "ver=%%~nxa"
    rem for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions"') do set "ver=%%~nxa"
    echo --%ver%--
    rem set "ver=%ver:.=%"
    for /f "skip=2 tokens=1,2,* delims= " %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\%ver%" /v "ParentInstance"') do set "pi=%%~nxc"
    rem echo --%pi%--
    for /f "skip=2 tokens=1,2,* delims= " %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\%pi%\MSSQLServer" /v "BackupDirectory"') do set dbp=%%~nc


    echo %dbp%

this should echo the back-up directory if its set.

这应该回应备份目录,如果它的设置。

#2


I solved the problem by doing this:

我通过这样做解决了这个问题:

sc \%HOSTIP% start RemoteRegistry
REG QUERY \\%HOSTIP%\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /s /f "DataStax" > search.txt
findstr "ty\data" search.txt > testcase.txt
sc \HOSTIP stop RemoteRegistry

sc \%HOSTIP%start RemoteRegistry REG QUERY \\%HOSTIP%\ HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Installer \ Folders / s / f“DataStax”> search.txt findstr“ty \ data”search.txt> testcase .txt sc \ HOSTIP停止RemoteRegistry

#1


If the Casandra is not some kind of portable database , after its installation it should store information about itself in registry somewhere under HKEY_LOCAL_MACHINE\SOFTWARE\ . I'd never used casandra so you'll need to find by yourself where the data is stored. As for the MS SQL:

如果Casandra不是某种便携式数据库,安装后它应该在HKEY_LOCAL_MACHINE \ SOFTWARE \下的某个地方存储有关自身的信息。我从未使用过casandra,因此您需要自己找到存储数据的位置。至于MS SQL:

    @echo off 


    for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions"') do set "ver=%%~nxa"
    rem for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions"') do set "ver=%%~nxa"
    echo --%ver%--
    rem set "ver=%ver:.=%"
    for /f "skip=2 tokens=1,2,* delims= " %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\%ver%" /v "ParentInstance"') do set "pi=%%~nxc"
    rem echo --%pi%--
    for /f "skip=2 tokens=1,2,* delims= " %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\%pi%\MSSQLServer" /v "BackupDirectory"') do set dbp=%%~nc


    echo %dbp%

this should echo the back-up directory if its set.

这应该回应备份目录,如果它的设置。

#2


I solved the problem by doing this:

我通过这样做解决了这个问题:

sc \%HOSTIP% start RemoteRegistry
REG QUERY \\%HOSTIP%\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /s /f "DataStax" > search.txt
findstr "ty\data" search.txt > testcase.txt
sc \HOSTIP stop RemoteRegistry

sc \%HOSTIP%start RemoteRegistry REG QUERY \\%HOSTIP%\ HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Installer \ Folders / s / f“DataStax”> search.txt findstr“ty \ data”search.txt> testcase .txt sc \ HOSTIP停止RemoteRegistry