SQL 如何 遠程備份資料庫到本地

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   ar   使用   sp   檔案   

SQL 如何 遠程備份資料庫到本地

--1、啟用xp_cmdshellUSE masterEXEC sp_configure ‘show advanced options‘, 1RECONFIGURE WITH OVERRIDEEXEC sp_configure ‘xp_cmdshell‘, 1RECONFIGURE WITH OVERRIDEEXEC sp_configure   ‘show advanced options‘, 0RECONFIGURE WITH OVERRIDE

--2、使用變數進行備份declare @db sysnamedeclare @dbpath varchar(120)set @db=‘shenyin‘--檔案名稱根據資料庫名稱+日期YYYYMMDD+副檔名set @dbpath=‘D:\‘+@db+convert(varchar(10),getdate(),112)+‘.bak‘

--3、在sql中建個映射exec master..xp_cmdshell ‘net use Y: \\192.168.0.156\DBBackup "jindou" /user:192.168.0.156\Administrator‘/* 說明: Y:是映射網路路徑對應原生盤符 192.168.0.156是我原生IP DBBackup是我本機共用的檔案夾 Administrator是登陸的使用者名稱  "jindou" 是Administrator使用者的密碼*/ --4、備份(@db是要備份的資料庫名稱)Backup Database @db To [email protected]--5、COPYdeclare @copypath varchar(200)set @copypath = ‘copy ‘+@dbpath+‘ Y:‘select @copypathexec master..xp_cmdshell @copypath --6、刪除(這句可以去掉)declare @deletepath varchar(200)set @deletepath = ‘del ‘+@dbpathselect @deletepathexec master..xp_cmdshell @deletepath --7、完成後刪除映射exec master..xp_cmdshell ‘net use Y: /delete‘

--8、關閉xp_cmdshellUSE master EXEC sp_configure ‘show advanced options‘, 1 RECONFIGURE WITH OVERRIDE EXEC sp_configure ‘xp_cmdshell‘, 0 RECONFIGURE WITH OVERRIDE EXEC sp_configure   ‘show advanced options‘, 0RECONFIGURE WITH OVERRIDE 

SQL 如何 遠程備份資料庫到本地

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.