script to backup azure sql database to local machine Edit
You would have used ms sql export data-tier application in ssms to create a bacpac backup to your local machine. Here is the sample script to backup azure sql database to local machine.
Solution
Microsoft has provided a command-line tool that can import/export DAC: sqlpackage.exe. You can download the same from the following link https://www.microsoft.com/en-us/download/details.aspx?id=58207. This would be installed to the C:\Program Files\Microsoft SQL Server\150\DAC\bin location.
To export a data-tier application, specify 3 parameters:
/Action:{Extract|DeployReport|DriftReport|Publish|Script|Export|Import} Specifies the action to be performed. (short form /a), we will only use Export in this example.
/SourceConnectionString:
/TargetFile:
Run the script in the command prompt
SqlPackage.exe /a:export /scs:"Server=yourserver;Database=dbname;User ID=username;Password=yourpassword;Trusted_Connection=True;" /tf:"c:\works\beginner.bacpac"