Search code examples
azureazure-resource-managerazure-database-mysql

How to copy a database using Azure ARM API's ?


There is an api to create or update a database.

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}?api-version=2014-04-0

How can I create a copy of a existing database?

Should I have to do GET on existing database to get the properties and then create a copy database using the properties? Will it create exactcopy of database ?


Solution

  • Looking at the rest api reference you should use the same call you are using, but in the body you must pass in createMode = copy and sourceDatabaseId = ID.

    {
        "subscriptionId": "00000000-1111-2222-3333-444444444444",
        "resourceGroupName": "sqlcrudtest-4799",
        "serverName": "sqlcrudtest-6440",
        "databaseName": "testdb",
        "api-version": "2014-04-01",
        "parameters": {
            "location": "Japan East",
            "properties": {
                "createMode": "Copy",
                "sourceDatabaseId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-4799/providers/Microsoft.Sql/servers/sqlcrudtest-3782/databases/testdb"
            }
        }
    },
    

    ps. scroll down (on the page I've linked) until you find an example called Create a database as a copy