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

來源:互聯網
上載者:User

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

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 disk=@dbpath--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遠端資料庫備份到本機資料 的方法

1、可以在遠程伺服器上備份資料庫,然後下載.bak檔案在本地恢複

2、連結上遠程伺服器,選中要備份的資料庫--》右擊--》任務--》產生指令碼
然後根據嚮導執行,但是在“選擇指令碼選項”頁面要把 編寫資料的指令碼 的選項 設定成TRUE,
然後下一步,選擇你要備份的表、預存程序、視圖等 知道最後產生一個.sql檔案,在本地執行就好了。
 
遠程伺服器上的SQL資料庫怎備份到本地??

有多種方法,常用的兩種有:
1.從資料庫上備份資料為檔案形式,下載到本地,匯入即可.
2.在MSSQL的安裝路徑,即:MSSQL\Data\找到你想要的資料庫,比如:111.ldf,111.mdf,下載到本地,在本地操作,附加資料庫,選中這兩個檔案,即可.
 

相關文章

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.