|
| 1 | +--- |
| 2 | +title: Backup and restore - Azure PowerShell - Azure Database for MySQL |
| 3 | +description: Learn how to backup and restore a server in Azure Database for MySQL by using Azure PowerShell. |
| 4 | +author: ajlam |
| 5 | +ms.author: andrela |
| 6 | +ms.service: mysql |
| 7 | +ms.devlang: azurepowershel |
| 8 | +ms.topic: conceptual |
| 9 | +ms.date: 4/28/2020 |
| 10 | +--- |
| 11 | +# How to back up and restore a server in Azure Database for MySQL using PowerShell |
| 12 | + |
| 13 | +Azure Database for MySQL servers is backed up periodically to enable restore features. Using this |
| 14 | +feature you may restore the server and all its databases to an earlier point-in-time, on a new |
| 15 | +server. |
| 16 | + |
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +To complete this how-to guide, you need: |
| 20 | + |
| 21 | +- The [Az PowerShell module](/powershell/azure/install-az-ps) installed locally or |
| 22 | + [Azure Cloud Shell](https://shell.azure.com/) in the browser |
| 23 | +- An [Azure Database for MySQL server](quickstart-create-mysql-server-database-using-azure-powershell.md) |
| 24 | + |
| 25 | +> [!IMPORTANT] |
| 26 | +> While the Az.MySql PowerShell module is in preview, you must install it separately from the Az |
| 27 | +> PowerShell module using the following command: `Install-Module -Name Az.MySql -AllowPrerelease`. |
| 28 | +> Once the Az.MySql PowerShell module is generally available, it becomes part of future Az |
| 29 | +> PowerShell module releases and available natively from within Azure Cloud Shell. |
| 30 | +
|
| 31 | +If you choose to use PowerShell locally, connect to your Azure account using the |
| 32 | +[Connect-AzAccount](/powershell/module/az.accounts/Connect-AzAccount) cmdlet. |
| 33 | + |
| 34 | +[!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)] |
| 35 | + |
| 36 | +## Set backup configuration |
| 37 | + |
| 38 | +At server creation, you make the choice between configuring your server for either locally redundant |
| 39 | +or geographically redundant backups. |
| 40 | + |
| 41 | +> [!NOTE] |
| 42 | +> After a server is created, the kind of redundancy it has, geographically redundant vs locally |
| 43 | +> redundant, can't be changed. |
| 44 | +
|
| 45 | +While creating a server via the `New-AzMySqlServer` command, the **GeoRedundantBackup** |
| 46 | +parameter decides your backup redundancy option. If **Enabled**, geo redundant backups are taken. Or |
| 47 | +if **Disabled**, locally redundant backups are taken. |
| 48 | + |
| 49 | +The backup retention period is set by the **BackupRetentionDay** parameter. |
| 50 | + |
| 51 | +For more information about setting these values during server creation, see |
| 52 | +[Create an Azure Database for MySQL server using PowerShell](quickstart-create-mysql-server-database-using-azure-powershell.md). |
| 53 | + |
| 54 | +The backup retention period of a server can be changed as follows: |
| 55 | + |
| 56 | +```azurepowershell-interactive |
| 57 | +Update-AzMySqlServer -Name mydemoserver -ResourceGroupName myresourcegroup -BackupRetentionDay 10 |
| 58 | +``` |
| 59 | + |
| 60 | +The preceding example changes the backup retention period of mydemoserver to 10 days. |
| 61 | + |
| 62 | +The backup retention period governs how far back a point-in-time restore can be retrieved, since |
| 63 | +it's based on available backups. Point-in-time restore is described further in the next section. |
| 64 | + |
| 65 | +## Server point-in-time restore |
| 66 | + |
| 67 | +You can restore the server to a previous point-in-time. The restored data is copied to a new server, |
| 68 | +and the existing server is left unchanged. For example, if a table is accidentally dropped, you can |
| 69 | +restore to the time just the drop occurred. Then, you can retrieve the missing table and data from |
| 70 | +the restored copy of the server. |
| 71 | + |
| 72 | +To restore the server, use the `Restore-AzMySqlServer` PowerShell cmdlet. |
| 73 | + |
| 74 | +### Run the restore command |
| 75 | + |
| 76 | +To restore the server, run the following example from PowerShell. |
| 77 | + |
| 78 | +```azurepowershell-interactive |
| 79 | +$restorePointInTime = (Get-Date).AddMinutes(-10) |
| 80 | +Get-AzMySqlServer -Name mydemoserver -ResourceGroupName myresourcegroup | |
| 81 | + Restore-AzMySqlServer -Name mydemoserver-restored -ResourceGroupName myresourcegroup -RestorePointInTime $restorePointInTime -UsePointInTimeRestore |
| 82 | +``` |
| 83 | + |
| 84 | +The **PointInTimeRestore** parameter set of the `Restore-AzMySqlServer` cmdlet requires the |
| 85 | +following parameters: |
| 86 | + |
| 87 | +| Setting | Suggested value | Description | |
| 88 | +| --- | --- | --- | |
| 89 | +| ResourceGroupName | myresourcegroup | The resource group where the source server exists. | |
| 90 | +| Name | mydemoserver-restored | The name of the new server that is created by the restore command. | |
| 91 | +| RestorePointInTime | 2020-03-13T13:59:00Z | Select a point in time to restore. This date and time must be within the source server's backup retention period. Use the ISO8601 date and time format. For example, you can use your own local time zone, such as **2020-03-13T05:59:00-08:00**. You can also use the UTC Zulu format, for example, **2018-03-13T13:59:00Z**. | |
| 92 | +| UsePointInTimeRestore | `<SwitchParameter>` | Use point-in-time mode to restore. | |
| 93 | + |
| 94 | +When you restore a server to an earlier point-in-time, a new server is created. The original server |
| 95 | +and its databases from the specified point-in-time are copied to the new server. |
| 96 | + |
| 97 | +The location and pricing tier values for the restored server remain the same as the original server. |
| 98 | + |
| 99 | +After the restore process finishes, locate the new server and verify that the data is restored as |
| 100 | +expected. The new server has the same server admin login name and password that was valid for the |
| 101 | +existing server at the time the restore was started. The password can be changed from the new |
| 102 | +server's **Overview** page. |
| 103 | + |
| 104 | +The new server created during a restore does not have the VNet service endpoints that existed on the |
| 105 | +original server. These rules must be set up separately for the new server. Firewall rules from the |
| 106 | +original server are restored. |
| 107 | + |
| 108 | +## Geo restore |
| 109 | + |
| 110 | +If you configured your server for geographically redundant backups, a new server can be created from |
| 111 | +the backup of the existing server. This new server can be created in any region that Azure Database |
| 112 | +for MySQL is available. |
| 113 | + |
| 114 | +To create a server using a geo redundant backup, use the `Restore-AzMySqlServer` command with the |
| 115 | +**UseGeoRestore** parameter. |
| 116 | + |
| 117 | +> [!NOTE] |
| 118 | +> When a server is first created it may not be immediately available for geo restore. It may take a |
| 119 | +> few hours for the necessary metadata to be populated. |
| 120 | +
|
| 121 | +To geo restore the server, run the following example from PowerShell: |
| 122 | + |
| 123 | +```azurepowershell-interactive |
| 124 | +Get-AzMySqlServer -Name mydemoserver -ResourceGroupName myresourcegroup | |
| 125 | + Restore-AzMySqlServer -Name mydemoserver-georestored -ResourceGroupName myresourcegroup -Location eastus -Sku GP_Gen5_8 -UseGeoRestore |
| 126 | +``` |
| 127 | + |
| 128 | +This example creates a new server called **mydemoserver-georestored** in the East US region that |
| 129 | +belongs to **myresourcegroup**. It is a General Purpose, Gen 5 server with 8 vCores. The server is |
| 130 | +created from the geo-redundant backup of **mydemoserver**, also in the resource group |
| 131 | +**myresourcegroup**. |
| 132 | + |
| 133 | +To create the new server in a different resource group from the existing server, specify the new |
| 134 | +resource group name using the **ResourceGroupName** parameter as shown in the following example: |
| 135 | + |
| 136 | +```azurepowershell-interactive |
| 137 | +Get-AzMySqlServer -Name mydemoserver -ResourceGroupName myresourcegroup | |
| 138 | + Restore-AzMySqlServer -Name mydemoserver-georestored -ResourceGroupName newresourcegroup -Location eastus -Sku GP_Gen5_8 -UseGeoRestore |
| 139 | +``` |
| 140 | + |
| 141 | +The **GeoRestore** parameter set of the `Restore-AzMySqlServer` cmdlet requires the following |
| 142 | +parameters: |
| 143 | + |
| 144 | +| Setting | Suggested value | Description | |
| 145 | +| --- | --- | --- | |
| 146 | +|ResourceGroupName | myresourcegroup | The name of the resource group the new server belongs to.| |
| 147 | +|Name | mydemoserver-georestored | The name of the new server. | |
| 148 | +|Location | eastus | The location of the new server. | |
| 149 | +|UseGeoRestore | `<SwitchParameter>` | Use geo mode to restore. | |
| 150 | + |
| 151 | +When creating a new server using geo restore, it inherits the same storage size and pricing tier as |
| 152 | +the source server unless the **Sku** parameter is specified. |
| 153 | + |
| 154 | +After the restore process finishes, locate the new server and verify that the data is restored as |
| 155 | +expected. The new server has the same server admin login name and password that was valid for the |
| 156 | +existing server at the time the restore was started. The password can be changed from the new |
| 157 | +server's **Overview** page. |
| 158 | + |
| 159 | +The new server created during a restore does not have the VNet service endpoints that existed on the |
| 160 | +original server. These rules must be set up separately for this new server. Firewall rules from the |
| 161 | +original server are restored. |
| 162 | + |
| 163 | +## Next steps |
| 164 | + |
| 165 | +- Learn more about the service's [backups](concepts-backup.md) |
| 166 | +- Learn about [replicas](concepts-read-replicas.md) |
| 167 | +- Learn more about [business continuity](concepts-business-continuity.md) options |
0 commit comments