RemoveServerFromDB.bat スクリプト ファイルの内容
例B-1 に、パブリッシャ サーバから SQL 複製情報を削除するスクリプト ファイルの内容を示します。
例B-1 スクリプト ファイルの内容
@echo off
@if "%3x" == "x" goto Usage
echo Install stored procedure in database %2
echo USE %2 temp.sql
echo GO temp.sql
echo DROP PROCEDURE dblRemoveServerFromDB temp.sql
echo GO temp.sql
echo CREATE PROCEDURE [dblRemoveServerFromDB] temp.sql
echo (@servername NVARCHAR(50),@ispublisher NVARCHAR(50)) AS temp.sql
echo BEGIN TRANSACTION temp.sql
echo DECLARE @nodeid NVARCHAR(50), @deviceid NVARCHAR(50), @pnsid NVARCHAR(50) temp.sql
echo -- temp.sql
echo PRINT 'Get the Node ID' temp.sql
echo SELECT @nodeid=pkid from ProcessNode where name=@servername temp.sql
echo -- temp.sql
echo PRINT 'Delete associated Device and MediaMixer' temp.sql
echo WHILE (SELECT COUNT(*) FROM Device WHERE fkProcessNode=@nodeid) ^> 0 temp.sql
echo BEGIN temp.sql
echo SELECT @deviceid=pkid from Device where fkProcessNode=@nodeid temp.sql
echo PRINT 'Delete MediaMixer' temp.sql
echo DELETE FROM MediaMixer WHERE fkDevice=@deviceid temp.sql
echo PRINT 'Delete MOHServer' temp.sql
echo DELETE FROM MOHServer WHERE fkDevice=@deviceid temp.sql
echo PRINT 'Delete Device' temp.sql
echo DELETE FROM Device WHERE pkid=@deviceid temp.sql
echo END temp.sql
echo -- temp.sql
echo PRINT 'Delete associated CallManager records' temp.sql
echo DELETE FROM CallManagerGroupMember FROM CallManagerGroupMember AS M temp.sql
echo JOIN CallManager AS C ON C.pkid=M.fkCallManager WHERE C.fkProcessNode=@nodeid temp.sql
echo DELETE FROM CallManager WHERE fkProcessNode=@nodeid temp.sql
echo -- temp.sql
echo PRINT 'Delete associated ProcessConfig records' temp.sql
echo DELETE FROM ProcessConfig WHERE fkProcessNode=@nodeid temp.sql
echo -- temp.sql
echo PRINT 'Delete associated AlarmConfig records' temp.sql
echo DELETE FROM AlarmConfig FROM AlarmConfig AS A JOIN ProcessNodeService temp.sql
echo AS S ON A.fkProcessNodeService=S.pkid WHERE S.fkProcessNode=@nodeid temp.sql
echo PRINT 'Delete associated ProcessNodeService records' temp.sql
echo DELETE FROM ProcessNodeService WHERE fkProcessNode=@nodeid temp.sql
echo -- temp.sql
echo PRINT 'Delete associated ComponentVersion records' temp.sql
echo DELETE FROM ComponentVersion WHERE fkProcessNode=@nodeid temp.sql
echo -- temp.sql
echo PRINT 'Delete the node' temp.sql
echo DELETE FROM ProcessNode WHERE pkid=@nodeid temp.sql
echo -- temp.sql
echo COMMIT TRANSACTION temp.sql
echo GO temp.sql
echo -- Execute procedure on server %1
echo exec dblRemoveServerFromDB '%3' temp.sql
osql -S %1 -d %2 -E -e -i temp.sql
del temp.sql
echo USE %2 temp1.sql
echo sp_dropsubscription @publication = %2, @subscriber = '%3', @article='all' temp1.sql
echo GO temp1.sql
osql -S %1 -d %2 -E -e -i temp1.sql
del temp1.sql
goto endd
:Usage
@echo Usage: RemoveServerFromDB "server" "database" "name_of_server_to_delete_from_ProcessNode.Name"
@echo Example: RemoveServerFromDB . CCM0300 fred.cisco.com
:endd