MS Sql server 總結(命令恢復)

iSQlServer發表於2009-11-25

一,如何建立連線伺服器

exec sp_addlinkedserver  'srv_lnk','','SQLOLEDB','遠端伺服器名或ip地址'
exec sp_addlinkedsrvlogin 'srv_lnk','false',null,'使用者名稱','密碼'
go

二,利用命令和本地的bak檔案恢復遠端資料庫,步驟:

1,建立共享資料夾,將存放bak檔案的資料夾設為共享資料夾

net share ShareFolder=D:\tmp\db.bak         該命令可以通過C#來呼叫

如果要取消共享,可以這樣寫

net share ShareFolder /delete

2,啟用xp_cmdshell,sql server 2005/2008 預設是禁用此儲存過程的。

--啟用

sp_configure 'show advanced options',1
reconfigure
go
sp_configure 'xp_cmdshell',1
reconfigure
go

--如果要禁用可以這樣寫

sp_configure 'xp_cmdshell',0
reconfigure

sp_configure 'show advanced options',0
reconfigure

3,建立共享信用關係,userName,pwd是登入192.224.109.64 這臺機器的使用者名稱和密碼。

<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gtEXEC xp_cmdshell 'net use \\192.224.109.64\ShareFolder pwd /user:userName';
GO

EXEC xp_cmdshell 'net use \\192.224.109.64\ShareFolder /del';
GO

第二句是如何撤消共享信用關係的。

 4,執行恢復命令

MS Sql server 總結(命令恢復)恢復資料庫

dbnew,dbnew_log   是備份時的資料庫名和日誌檔名。

其中,如下語句

 select  REVERSE (SUBSTRING(reverse(filename),charindex('\',reverse(filename)),8000)),name   from   sysfiles

可以獲取sql server 資料檔案,日誌檔案的存放路徑。

5,執行完畢後做一些相反操作即可,比如禁用xp_cmdshell,撤消共享信用關係,取消資料夾共享等。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16436858/viewspace-620544/,如需轉載,請註明出處,否則將追究法律責任。

相關文章