如何使用sqlpackage从onprem提取bacpac并将其直接发送到azure存储帐户?

时间:2018-10-04 11:04:20

标签: sql-server azure azure-sql-database

我们如何才能为严重SQL Server内的不同数据库提取不同的bacpac,并将其发送到azure存储帐户,并从该bacpac建立数据库?

2 个答案:

答案 0 :(得分:0)

您可以创建bacpac并将其使用SqlPackage存储在本地存储中。

-- Parameters 
sqlpackage.exe /Action:Export /ssn:{server name} /sdn:{database name} /tf:{target file}
-- Example
sqlpackage.exe /Action:Export /ssn:(local)\sql2014cs /sdn:AdventureWorksDW2014 /tf:c:\temp\AdventureWorksDW2014.bacpac

之后,您可以使用AzCopy将bacpac复制到Azure存储帐户。

AzCopy /Source:{source directory} /Dest:https://myaccount.blob.core.windows.net/mycontainer /DestKey:key /Pattern:"abc.bacpac"

-- Example
AzCopy /Source:C:\temp /Dest:https://morillo.blob.core.windows.net/blobcontainer /DestKey:key /Pattern:"AdventureWorksDW2014.bacpac"

答案 1 :(得分:0)

为什么在导入之前将它们复制到Azure存储帐户?为什么不直接从最初的BACPAC创建中直接加载呢?

## Set-Location to the DAC folder
Set-Location "C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin"

## Export the AdventureWorksLT2016 database
.\sqlpackage.exe /Action:Export /SourceDatabaseName:AdventureWorksLT2016 /SourceServerName:localhost /TargetFile:C:\Temp\DBExport.bacpac /OverwriteFiles:True

## Import the BACPAC and create the AdventureWorksLT2016 database
.\SqlPackage.exe /a:import /tcs:"Data Source=myazuredb.database.windows.net;Initial Catalog=AdventureWorksLT2016;User Id=mylogin;Password=mypassword" /sf:C:\Temp\AWExport.bacpac /p:DatabaseEdition=Basic