简体   繁体   中英

How to extract bacpac using sqlpackage from onprem and directly send it to azure storage account?

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

You can create bacpacs and store them on the local storage using 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

After that you can copy the bacpac to an Azure Storage account using AzCopy.

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"

Why copy them to an Azure Storage Account before importing? Why not just load straight in from the initial BACPAC creation?

## 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM