How To Run Time Machine Backup

broken image


Create a simple scheduled daily backup to a Recovery Services vault. In the menu on the left, select Virtual machines. From the list, choose a VM to back up. If you used the sample VM quickstart. Run this command to see the delta between each of the Time Machine backups on your backup disk or volume: tmutil calculatedrift backupfolder Replace backupfolder with the path of the folder.

-->

How long will my battery run. Battery Life: I have a battery and I want to run an (app) application against it. How long will it run? This calculator will tell you how long your battery will run. Here's how to backup with Time Machine and an external storage device: 1. Connect the device; once your computer recognizes that you've done so, a popup window may appear asking if you want to use.

You can troubleshoot errors encountered while using Azure Backup with the information listed below: How to upload something as a pdf.

Backup

This section covers backup operation failure of Azure Virtual machine.

Basic troubleshooting

  • Ensure that the VM Agent (WA Agent) is the latest version.
  • Ensure that the Windows or Linux VM OS version is supported, refer to the IaaS VM Backup Support Matrix.
  • Verify that another backup service isn't running.
    • To ensure there are no snapshot extension issues, uninstall extensions to force reload and then retry the backup.
  • Verify that the VM has internet connectivity.
    • Make sure another backup service isn't running.
  • From Services.msc, ensure the Windows Azure Guest Agent service is Running. If the Windows Azure Guest Agent service is missing, install it from Back up Azure VMs in a Recovery Services vault.
  • The Event log may show backup failures that are from other backup products, for example, Windows Server backup, and aren't due to Azure Backup. Use the following steps to determine whether the issue is with Azure Backup:
    • If there's an error with the entry Backup in the event source or message, check whether Azure IaaS VM Backup backups were successful, and whether a Restore Point was created with the desired snapshot type.
    • If Azure Backup is working, then the issue is likely with another backup solution.
    • Here is an example of an Event Viewer error 517 where Azure Backup was working fine but 'Windows Server Backup' was failing:
    • If Azure Backup is failing, then look for the corresponding Error Code in the section Common VM backup errors in this article.

Common issues

The following are common issues with backup failures on Azure virtual machines.

VMRestorePointInternalError - Antivirus configured in the VM is restricting the execution of backup extension

Error code: VMRestorePointInternalError

If at the time of backup, the Event Viewer Application logs displays the message Faulting application name: IaaSBcdrExtension.exe then it's confirmed that the antivirus configured in the VM is restricting the execution of backup extension.To resolve this issue, exclude the directories below in the antivirus configuration and retry the backup operation.

  • C:PackagesPluginsMicrosoft.Azure.RecoveryServices.VMSnapshot
  • C:WindowsAzureLogsPluginsMicrosoft.Azure.RecoveryServices.VMSnapshot

CopyingVHDsFromBackUpVaultTakingLongTime - Copying backed up data from vault timed out

Error code: CopyingVHDsFromBackUpVaultTakingLongTime 
Error message: Copying backed up data from vault timed out

This could happen due to transient storage errors or insufficient storage account IOPS for backup service to transfer data to the vault within the timeout period. Configure VM backup using these best practices and retry the backup operation.

UserErrorVmNotInDesirableState - VM is not in a state that allows backups

Error code: UserErrorVmNotInDesirableState
Error message: VM is not in a state that allows backups.

The backup operation failed because the VM is in Failed state. For a successful backup, the VM state should be Running, Stopped, or Stopped (deallocated).

  • If the VM is in a transient state between Running and Shut down, wait for the state to change. Then trigger the backup job.
  • If the VM is a Linux VM and uses the Security-Enhanced Linux kernel module, exclude the Azure Linux Agent path /var/lib/waagent from the security policy and make sure the Backup extension is installed.

UserErrorFsFreezeFailed - Failed to freeze one or more mount-points of the VM to take a file-system consistent snapshot

Error code: UserErrorFsFreezeFailed
Error message: Failed to freeze one or more mount-points of the VM to take a file-system consistent snapshot.

  • Unmount the devices for which the file system state wasn't cleaned, using the umount command.
  • Run a file system consistency check on these devices by using the fsck command.
  • Mount the devices again and retry backup operation.

If you can't un-mount the devices then you can update the VM backup configuration to ignore certain mount points. For example, if '/mnt/resource' mount point can't be un-mounted and causing the VM backup failures, you can update the VM backup configuration files with the MountsToSkip property as follows.

ExtensionSnapshotFailedCOM / ExtensionInstallationFailedCOM / ExtensionInstallationFailedMDTC - Extension installation/operation failed due to a COM+ error

Error code: ExtensionSnapshotFailedCOM
Error message: Snapshot operation failed due to COM+ error

Error code: ExtensionInstallationFailedCOM
Error message: Extension installation/operation failed due to a COM+ error

Error code: ExtensionInstallationFailedMDTC
Error message: Extension installation failed with the error 'COM+ was unable to talk to the Microsoft Distributed Transaction Coordinator

The Backup operation failed due to an issue with Windows service COM+ System application. To resolve this issue, follow these steps:

  • Try starting/restarting Windows service COM+ System Application (from an elevated command prompt - net start COMSysApp).
  • Ensure Distributed Transaction Coordinator service is running as Network Service account. If not, change it to run as Network Service account and restart COM+ System Application.
  • If unable to restart the service, then reinstall Distributed Transaction Coordinator service by following the steps below:
    • Stop the MSDTC service
    • Open a command prompt (cmd)
    • Run the command msdtc -uninstall
    • Run the command msdtc -install
    • Start the MSDTC service
  • Start the Windows service COM+ System Application. After the COM+ System Application starts, trigger a backup job from the Azure portal.

ExtensionFailedVssWriterInBadState - Snapshot operation failed because VSS writers were in a bad state

Error code: ExtensionFailedVssWriterInBadState
Error message: Snapshot operation failed because VSS writers were in a bad state.

This error occurs because the VSS writers were in a bad state. Azure Backup extensions interact with VSS Writers to take snapshots of the disks. To resolve this issue, follow these steps:

Step 1: Restart VSS writers that are in a bad state.

  • From an elevated command prompt, run vssadmin list writers.
  • The output contains all VSS writers and their state. For every VSS writer with a state that's not [1] Stable, restart the respective VSS writer's service.
  • To restart the service, run the following commands from an elevated command prompt:

net stop serviceName
net start serviceName

Note

Restarting some services can have an impact on your production environment. Ensure the approval process is followed and the service is restarted at the scheduled downtime.

Step 2: If restarting the VSS writers did not resolve the issue, then run the following command from an elevated command-prompt (as an administrator) to prevent the threads from being created for blob-snapshots.

Step 3: If steps 1 and 2 did not resolve the issue, then the failure could be due to VSS writers timing out due to limited IOPS.

To verify, navigate to System and Event Viewer Application logs and check for the following error message:
The shadow copy provider timed out while holding writes to the volume being shadow copied. This is probably due to excessive activity on the volume by an application or a system service. Try again later when activity on the volume is reduced.

Solution:

  • Check for possibilities to distribute the load across the VM disks. This will reduce the load on single disks. You can check the IOPs throttling by enabling diagnostic metrics at storage level.
  • Change the backup policy to perform backups during off peak hours, when the load on the VM is at its lowest.
  • Upgrade the Azure disks to support higher IOPs. Learn more here

ExtensionFailedVssServiceInBadState - Snapshot operation failed due to VSS (Volume Shadow Copy) service in bad state

Error code: ExtensionFailedVssServiceInBadState
Error message: Snapshot operation failed due to VSS (Volume Shadow Copy) service in bad state.

This error occurs because the VSS service was in a bad state. Azure Backup extensions interact with VSS service to take snapshots of the disks. To resolve this issue, follow these steps:

Restart VSS (Volume Shadow Copy) service.

  • Navigate to Services.msc and restart 'Volume Shadow Copy service'.
    (or)
  • Run the following commands from an elevated command prompt:

net stop VSS
net start VSS

If the issue still persists, restart the VM at the scheduled downtime.

UserErrorSkuNotAvailable - VM creation failed as VM size selected is not available

Error code: UserErrorSkuNotAvailableError message: VM creation failed as VM size selected is not available.

This error occurs because the VM size selected during the restore operation is an unsupported size.

To resolve this issue, use the restore disks option during the restore operation. Use those disks to create a VM from the list of available supported VM sizes using PowerShell cmdlets.

UserErrorMarketPlaceVMNotSupported - VM creation failed due to Market Place purchase request being not present

Error code: UserErrorMarketPlaceVMNotSupportedError message: VM creation failed due to Market Place purchase request being not present.

Azure Backup supports backup and restore of VMs which are available in Azure Marketplace. This error occurs when you are trying to restore a VM (with a specific Plan/Publisher setting) which is no longer available in Azure Marketplace, Learn more here.

  • To resolve this issue, use the restore disks option during the restore operation and then use PowerShell or Azure CLI cmdlets to create the VM with the latest marketplace information corresponding to the VM.
  • If the publisher does not have any Marketplace information, you can use the data disks to retrieve your data and you can attach them to an existing VM.

ExtensionConfigParsingFailure - Failure in parsing the config for the backup extension

Error code: ExtensionConfigParsingFailure
Error message: Failure in parsing the config for the backup extension.

This error happens because of changed permissions on the MachineKeys directory: %systemdrive%programdatamicrosoftcryptorsamachinekeys.Run the following command and verify that permissions on the MachineKeys directory are default ones:icacls %systemdrive%programdatamicrosoftcryptorsamachinekeys.

Default permissions are as follows:

  • Everyone: (R,W)
  • BUILTINAdministrators: (F)

If you see permissions in the MachineKeys directory that are different than the defaults, follow these steps to correct permissions, delete the certificate, and trigger the backup:

  1. Fix permissions on the MachineKeys directory. By using Explorer security properties and advanced security settings in the directory, reset permissions back to the default values. Remove all user objects except the defaults from the directory and make sure the Everyone permission has special access as follows:

    • List folder/read data
    • Read attributes
    • Read extended attributes
    • Create files/write data
    • Create folders/append data
    • Write attributes
    • Write extended attributes
    • Read permissions
  2. Delete all certificates where Issued To is the classic deployment model or Windows Azure CRP Certificate Generator:

    • Open certificates on a local computer console.
    • Under Personal > Certificates, delete all certificates where Issued To is the classic deployment model or Windows Azure CRP Certificate Generator.
  3. Trigger a VM backup job.

ExtensionStuckInDeletionState - Extension state is not supportive to backup operation

Error code: ExtensionStuckInDeletionState 
Error message: Extension state is not supportive to backup operation

The Backup operation failed due to inconsistent state of Backup Extension. To resolve this issue, follow these steps:

  • Ensure Guest Agent is installed and responsive
  • From the Azure portal, go to Virtual Machine > All Settings > Extensions
  • Select the backup extension VmSnapshot or VmSnapshotLinux and select Uninstall.
  • After deleting backup extension, retry the backup operation
  • The subsequent backup operation will install the new extension in the desired state

ExtensionFailedSnapshotLimitReachedError - Snapshot operation failed as snapshot limit is exceeded for some of the disks attached

Error code: ExtensionFailedSnapshotLimitReachedError
Error message: Snapshot operation failed as snapshot limit is exceeded for some of the disks attached

The snapshot operation failed as the snapshot limit has exceeded for some of the disks attached. Complete the following troubleshooting steps and then retry the operation.

  • Delete the disk blob-snapshots that aren't required. Be careful to not delete disk blobs. Only snapshot blobs should be deleted.

  • If Soft-delete is enabled on VM disk Storage-Accounts, configure soft-delete retention so existing snapshots are less than the maximum allowed at any point of time.

  • If Azure Site Recovery is enabled in the backed-up VM, then perform the steps below:

    • Ensure the value of isanysnapshotfailed is set as false in /etc/azure/vmbackup.conf
    • Schedule Azure Site Recovery at a different time, so it doesn't conflict the backup operation.

ExtensionFailedTimeoutVMNetworkUnresponsive - Snapshot operation failed due to inadequate VM resources

Error code: ExtensionFailedTimeoutVMNetworkUnresponsive
Error message: Snapshot operation failed due to inadequate VM resources.

Backup operation on the VM failed due to delay in network calls while performing the snapshot operation. To resolve this issue, perform Step 1. If the issue persists, try steps 2 and 3.

Step 1: Create snapshot through Host

How to schedule time machine backups

From an elevated (admin) command-prompt, run the following command:

This will ensure the snapshots are taken through host instead of Guest. Retry the backup operation.

Step 2: Try changing the backup schedule to a time when the VM is under less load (like less CPU or IOPS)

Step 3: Try increasing the size of the VM and retry the operation

320001, ResourceNotFound - Could not perform the operation as VM no longer exists / 400094, BCMV2VMNotFound - The virtual machine doesn't exist / An Azure virtual machine wasn't found

Error code: 320001, ResourceNotFound
Error message: Could not perform the operation as VM no longer exists.
Error code: 400094, BCMV2VMNotFound
Error message: The virtual machine doesn't exist
An Azure virtual machine wasn't found.

This error happens when the primary VM is deleted, but the backup policy still looks for a VM to back up. To fix this error, take the following steps:

  • Re-create the virtual machine with the same name and same resource group name, cloud service name,
    or
  • Stop protecting the virtual machine with or without deleting the backup data. For more information, see Stop protecting virtual machines.

UserErrorBCMPremiumStorageQuotaError - Could not copy the snapshot of the virtual machine, due to insufficient free space in the storage account

Error code: UserErrorBCMPremiumStorageQuotaError
Error message: Could not copy the snapshot of the virtual machine, due to insufficient free space in the storage account

For premium VMs on VM backup stack V1, we copy the snapshot to the storage account. This step makes sure that backup management traffic, which works on the snapshot, doesn't limit the number of IOPS available to the application using premium disks.
We recommend that you allocate only 50 percent, 17.5 TB, of the total storage account space. Then the Azure Backup service can copy the snapshot to the storage account and transfer data from this copied location in the storage account to the vault.

380008, AzureVmOffline - Failed to install Microsoft Recovery Services extension as virtual machine is not running

Error code: 380008, AzureVmOffline
Error message: Failed to install Microsoft Recovery Services extension as virtual machine is not running

The VM Agent is a prerequisite for the Azure Recovery Services extension. Install the Azure Virtual Machine Agent and restart the registration operation.

  1. Check if the VM Agent is installed correctly.
  2. Make sure that the flag on the VM config is set correctly.
Read more about installing the VM Agent and how to validate the VM Agent installation.

ExtensionSnapshotBitlockerError - The snapshot operation failed with the Volume Shadow Copy Service (VSS) operation error

Error code: ExtensionSnapshotBitlockerError
Error message: The snapshot operation failed with the Volume Shadow Copy Service (VSS) operation error This drive is locked by BitLocker Drive Encryption. You must unlock this drive from the Control Panel.

Turn off BitLocker for all drives on the VM and check if the VSS issue is resolved.

VmNotInDesirableState - The VM isn't in a state that allows backups

Error code: VmNotInDesirableState
Error message: The VM isn't in a state that allows backups.

  • If the VM is in a transient state between Running and Shut down, wait for the state to change. Then trigger the backup job.

  • If the VM is a Linux VM and uses the Security-Enhanced Linux kernel module, exclude the Azure Linux Agent path /var/lib/waagent from the security policy and make sure the Backup extension is installed.

  • The VM Agent isn't present on the virtual machine:
    Install any prerequisite and the VM Agent. Then restart the operation. |Read more about VM Agent installation and how to validate VM Agent installation.

ExtensionSnapshotFailedNoSecureNetwork - The snapshot operation failed because of failure to create a secure network communication channel

Error code: ExtensionSnapshotFailedNoSecureNetwork
Error message: The snapshot operation failed because of failure to create a secure network communication channel.

  • Open the Registry Editor by running regedit.exe in an elevated mode.
  • Identify all versions of the .NET Framework present in your system. They're present under the hierarchy of registry key HKEY_LOCAL_MACHINESOFTWAREMicrosoft.
  • For each .NET Framework present in the registry key, add the following key:
    SchUseStrongCrypto'=dword:00000001.

ExtensionVCRedistInstallationFailure - The snapshot operation failed because of failure to install Visual C++ Redistributable for Visual Studio 2012

Error code: ExtensionVCRedistInstallationFailure
Error message: The snapshot operation failed because of failure to install Visual C++ Redistributable for Visual Studio 2012.

  • Navigate to C:PackagesPluginsMicrosoft.Azure.RecoveryServices.VMSnapshotagentVersion and install vcredist2013_x64.
    Make sure that the registry key value that allows the service installation is set to the correct value. That is, set the Start value in HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesMsiserver to 3 and not 4.
    If you still have issues with installation, restart the installation service by running MSIEXEC /UNREGISTER followed by MSIEXEC /REGISTER from an elevated command prompt.
  • Check the event log to verify if you're noticing access related issues. For example: Product: Microsoft Visual C++ 2013 x64 Minimum Runtime - 12.0.21005 -- Error 1401.Could not create key: SoftwareClasses. System error 5. Verify that you have sufficient access to that key, or contact your support personnel.
    Ensure the administrator or user account has sufficient permissions to update the registry key HKEY_LOCAL_MACHINESOFTWAREClasses. Provide sufficient permissions and restart the Windows Azure Guest Agent.
  • If you have antivirus products in place, ensure they have the right exclusion rules to allow the installation.

UserErrorRequestDisallowedByPolicy - An invalid policy is configured on the VM which is preventing Snapshot operation

Error code: UserErrorRequestDisallowedByPolicy
Error message: An invalid policy is configured on the VM which is preventing Snapshot operation.

If you have an Azure Policy that governs tags within your environment, either consider changing the policy from a Deny effect to a Modify effect, or create the resource group manually according to the naming schema required by Azure Backup.

Jobs

Error detailsWorkaround
Cancellation isn't supported for this job type:
Wait until the job finishes.
None
The job isn't in a cancelable state:
Wait until the job finishes.
or
The selected job isn't in a cancelable state:
Wait for the job to finish.
It's likely that the job is almost finished. Wait until the job is finished.
Backup can't cancel the job because it isn't in progress:
Cancellation is supported only for jobs in progress. Try to cancel an in-progress job.
This error happens because of a transitory state. Wait a minute and retry the cancel operation.
Backup failed to cancel the job:
Wait until the job finishes.
None

Restore

Disks appear offline after File Restore

If after restore, you notice the disks are offline then:

  • Verify if the machine where the script is executed meets the OS requirements. Learn more.
  • Ensure you are not restoring to the same source, Learn more.

UserErrorInstantRpNotFound - Restore failed because the Snapshot of the VM was not found

Error code: UserErrorInstantRpNotFound
Error message: Restore failed because the snapshot of the VM was not found. The snapshot could have been deleted, please check.

This error occurs when you are trying to restore from a recovery point that was not transferred to the vault and was deleted in the snapshot phase.
To resolve this issue, try to restore the VM from a different restore point.

Common errors

Error detailsWorkaround
Restore failed with a cloud internal error.
  1. The cloud service to which you're trying to restore is configured with DNS settings. You can check:
    $deployment = Get-AzureDeployment -ServiceName 'ServiceName' -Slot 'Production' Get-AzureDns -DnsSettings $deployment.DnsSettings.
    If Address is configured, then DNS settings are configured.
  2. The cloud service to which to you're trying to restore is configured with ReservedIP, and existing VMs in the cloud service are in the stopped state. You can check that a cloud service has reserved an IP by using the following PowerShell cmdlets: $deployment = Get-AzureDeployment -ServiceName 'servicename' -Slot 'Production' $dep.ReservedIPName.
  3. You're trying to restore a virtual machine with the following special network configurations into the same cloud service:
    • Virtual machines under load balancer configuration, internal and external.
    • Virtual machines with multiple reserved IPs.
    • Virtual machines with multiple NICs.
  4. Select a new cloud service in the UI or see restore considerations for VMs with special network configurations.
The selected DNS name is already taken:
Specify a different DNS name and try again.
This DNS name refers to the cloud service name, usually ending with .cloudapp.net. This name needs to be unique. If you get this error, you need to choose a different VM name during restore.
This error is shown only to users of the Azure portal. The restore operation through PowerShell succeeds because it restores only the disks and doesn't create the VM. The error will be faced when the VM is explicitly created by you after the disk restore operation.
The specified virtual network configuration isn't correct:
Specify a different virtual network configuration and try again.
None
The specified cloud service is using a reserved IP that doesn't match the configuration of the virtual machine being restored:
Specify a different cloud service that isn't using a reserved IP. Or choose another recovery point to restore from.
None
The cloud service has reached its limit on the number of input endpoints:
Retry the operation by specifying a different cloud service or by using an existing endpoint.
None
The Recovery Services vault and target storage account are in two different regions:
Make sure the storage account specified in the restore operation is in the same Azure region as your Recovery Services vault.
None
The storage account specified for the restore operation isn't supported:
Only Basic or Standard storage accounts with locally redundant or geo-redundant replication settings are supported. Select a supported storage account.
None
The type of storage account specified for the restore operation isn't online:
Make sure that the storage account specified in the restore operation is online.
This error might happen because of a transient error in Azure Storage or because of an outage. Choose another storage account.
The resource group quota has been reached:
Delete some resource groups from the Azure portal or contact Azure Support to increase the limits.
None
The selected subnet doesn't exist:
Select a subnet that exists.
None
The Backup service doesn't have authorization to access resources in your subscription.To resolve this error, first restore disks by using the steps in Restore backed-up disks. Then use the PowerShell steps in Create a VM from restored disks.

Backup or restore takes time

If your backup takes more than 12 hours, or restore takes more than 6 hours, review best practices, andperformance considerations

VM Agent

Set up the VM Agent

Typically, the VM Agent is already present in VMs that are created from the Azure gallery. But virtual machines that are migrated from on-premises datacenters won't have the VM Agent installed. For those VMs, the VM Agent needs to be installed explicitly.

Windows VMs - Set up the agent

  • Download and install the agent MSI. You need Administrator privileges to finish the installation.
  • For virtual machines created by using the classic deployment model, update the VM property to indicate that the agent is installed. This step isn't required for Azure Resource Manager virtual machines.

Linux VMs - Set up the agent

  • Install the latest version of the agent from the distribution repository. For details on the package name, see the Linux Agent repository.
  • For VMs created by using the classic deployment model, update the VM property and verify that the agent is installed. This step isn't required for Resource Manager virtual machines.

Update the VM Agent

Create New Time Machine Backup

Windows VMs - Update the agent

  • To update the VM Agent, reinstall the VM Agent binaries. Before you update the agent, make sure no backup operations occur during the VM Agent update.

Linux VMs - Update the agent

  • To update the Linux VM Agent, follow the instructions in the article Updating the Linux VM Agent.

    Note

    Always use the distribution repository to update the agent.

    Don't download the agent code from GitHub. If the latest agent isn't available for your distribution, contact the distribution support for instructions to acquire the latest agent. You can also check the latest Windows Azure Linux agent information in the GitHub repository.

Validate VM Agent installation

Verify the VM Agent version on Windows VMs:

  1. Sign in to the Azure virtual machine and navigate to the folder C:WindowsAzurePackages. You should find the WaAppAgent.exe file.
  2. Right-click the file and go to Properties. Then select the Details tab. The Product Version field should be 2.6.1198.718 or higher.

Troubleshoot VM snapshot issues

VM backup relies on issuing snapshot commands to underlying storage. Not having access to storage or delays in a snapshot task run can cause the backup job to fail. The following conditions can cause snapshot task failure:

  • VMs with SQL Server backup configured can cause snapshot task delay. By default, VM backup creates a VSS full backup on Windows VMs. VMs that run SQL Server, with SQL Server backup configured, can experience snapshot delays. If snapshot delays cause backup failures, set following registry key:

  • VM status is reported incorrectly because the VM is shut down in RDP. If you used the remote desktop to shut down the virtual machine, verify that the VM status in the portal is correct. If the status isn't correct, use the Shutdown option in the portal VM dashboard to shut down the VM.

  • If more than four VMs share the same cloud service, spread the VMs across multiple backup policies. Stagger the backup times, so no more than four VM backups start at the same time. Try to separate the start times in the policies by at least an hour.

  • The VM runs at high CPU or memory. If the virtual machine runs at high memory or CPU usage, more than 90 percent, your snapshot task is queued and delayed. Eventually it times out. If this issue happens, try an on-demand backup.

Networking

DHCP must be enabled inside the guest for IaaS VM backup to work. If you need a static private IP, configure it through the Azure portal or PowerShell. Make sure the DHCP option inside the VM is enabled.Get more information on how to set up a static IP through PowerShell:

Even though Azure SQL Database provides built-in backup, you may still want to create a local copy of your Azure SQL database. This could be handy for example when you want to keep database backup copy for free longer than allowed by Microsoft Azure built-in tools which is usually 7 to 35 days, depending on your service tier. Here we will explain in details how to backup Azure SQL Database to Local Machine.

There are several ways to download Azure database to your computer. The table below summarizes several key methods with pros, cons and usage scenarios. Click the name for more details about each method.

    • Simple process
    • Works even with old SQL Server / SSMS
    • Can export data into different file formats
    • Only data is imported, all other objects will be lost
    • Requires SQL Server Management Studio
    • Manual procedure
    Use if you need to move data from Azure to a specific destination (e.g. your old SQL Server) or in a particular format (e.g. flat file) with SQL Server Management Studio tools
    • Can export data into different file formats
    • Can be run unattended/automatically
    • Only data is imported, all other objects will be lost
    Similar to SQL Server Import and Export Wizard, but enables automatic process
    • Creates the most exact copy of the database
    • Simple user interface
    • Requires the latest DAC library installed
    • Creates a specific BACPAC file
    • Manual procedure
    Use when you need to create BACPAC file with SQL Server Management Studio tools
    • Creates the most exact copy of the database
    • Can be run unattended/automatically
    • Requires the latest DAC library installed
    • Creates a specific BACPAC file
    Use if you need to create BACPAC file from a command line
    • Can export data into different file formats
    • Can be run unattended/automatically
    • Only data is imported, all other objects will be lost
    • Imports only one table at a time
    Use if you need to save data from one or several tables in a readable format
    • Simple UI
    • Can create scheduled backups
    • Doesn't require DAC library installed
    Use when you need to perform automatic backups into BACPAC file regularly
    • Everything online, no software installation required
    • Creates a specific BACPAC file
    • Azure storage account is required

Azure SQL Database Firewall Setup

Since we are going to connect to Azure SQL Database from outside, we need to set up built-in firewall accordingly by adding IP address of the machine to which we want to download our database copy.

For that go to Azure Portal, select 'SQL databases' > Your database > 'Set server firewall':

Then, add the new rule and don't forget clicking 'Save'. For convenience, you can click on 'Add client IP' and the rule for the current IP address will be generated automatically:

How to Backup Azure SQL Database Using SQL Server Import and Export Wizard

Using built-in SSMS SQL Server Import and Export Wizard you can convert data between any sources, including ODBC, OLE DB, MS Access, MS Excel, and even flat file. This is exactly what we will use to copy data from Azure SQL Database to a local computer.

For starters, open SQL Server Management Studio and connect to your Azure SQL Database. If upon connecting you see the following message:

Cannot open server ‘azure_server_name' requested by the login. Client with IP address ‘83.219.146.206' is not allowed to access the server. To enable access, use the Windows Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect.

then you need to add your IP address to Azure Firewall.

Following a successful connection, select the database you need (in this case its AdventureWorks), right-click of the mouse and select 'Tasks' > 'Import Data' (or 'Export Data'):

This will prompt SQL Server Import and Export Wizard where you need to select '.Net Framework Data Provider for SqlServer' as a source and then enter the details of your Azure databasе:

The easiest way of doing that is to enter a ConnectionString which you can obtain on Azure Portal:

Don't forget to change {your_username} and {your_password} in connection string into real values.

Clicking the 'Next' button will trigger connection testing. If everything goes well you will be asked for the Destination parameters. From the drop-down list you will be able select not only SQL Server, but Excel, Access, and even Flat File as well:

If you want to export data to SQL Server, you can obtain a Connection String using the following query:

Following a successful connection to the destination, you will be prompted to select export of all data or only the result of a specific query. Selecting all data will require you to select tables for export. Selecting only query data will ask you to enter the query text.

The last step will run the export. A successful export screen will look similar to the one below:

If should be noted that during one of the interim steps you will be prompted to save the export as SSIS Package. This will enable export with SSIS tools, which are reviewed in the next section.

How to Backup Azure SQL Database Using SQL Server Integration Services (SSIS)

SQL Server Integration Services is a powerful platform that allows to integrate and transform data between various applications. We have already faced it in the previous section when we exported Azure Database with SQL Server Import and Export Wizard.

SSIS allows running such export automatically (e.g. from a command line) if you have .dtsx file (SSIS Package) that contain all the necessary information about the export procedure. You can create such file with SSMS (as described above), and then run it either with DTEXEC.EXE command line utility, or with DTEXECUI application, or with SQL Server Agent Job.

For example, if you saved export parameters into AzureExport.dtsx, you can run it again by using the following command:

If you prefer a graphical interface, you can use The Execute Package Utility (DTEXECUI) app, although it requires Management Tools – Basic or Business Intelligence Studio to be installed by the SQL Server.

How to Export Azure SQL Database to BACPAC File

SQL Server Management Studio includes a simple option to export your Azure SQL Database into a .bacpac file. In this tutorial, we will show how to do it using SSMS.

Requirements

  1. You will need SSMS Installed
  2. Make sure that the firewall rule is enabled in the Azure SQL Server
  3. An Azure SQL Database installed
  4. Internet Connection

You will first need to connect to your Azure SQL Database using SSMS.

Once that you are in SSMS right click on your Azure SQL database and select Task and Export Data-tier Application:

This option will open a Wizard. In the first part, it will show an introduction. In the introduction, press Next.

In the Export Settings section go to Save to local disk and specify a local path in your machine to install the bacpac file.

The wizard will go to Summary to show all the settings configured. Press next in that section.

Eventually, if everything is OK will show a green status. The exporting process includes exporting data, schemas, tables, references and all other database components. Once that you receive the message, you can verify the bacpac of the file exported and used to recover the database to another SQL Server.

How to Backup Azure SQL Database Using SqlPackage Utility

The SqPackage Utility allows to import or export data using the command line. It can be very useful if we need to automate and program import and export tasks. This software is usually installed with SSMS or SSDT. To search it you can use in the cmd with the following commands (make sure to run the cd first):

The command will show the path of sqlpackage utility. The path is usually similar to this one:

How

From an elevated (admin) command-prompt, run the following command:

This will ensure the snapshots are taken through host instead of Guest. Retry the backup operation.

Step 2: Try changing the backup schedule to a time when the VM is under less load (like less CPU or IOPS)

Step 3: Try increasing the size of the VM and retry the operation

320001, ResourceNotFound - Could not perform the operation as VM no longer exists / 400094, BCMV2VMNotFound - The virtual machine doesn't exist / An Azure virtual machine wasn't found

Error code: 320001, ResourceNotFound
Error message: Could not perform the operation as VM no longer exists.
Error code: 400094, BCMV2VMNotFound
Error message: The virtual machine doesn't exist
An Azure virtual machine wasn't found.

This error happens when the primary VM is deleted, but the backup policy still looks for a VM to back up. To fix this error, take the following steps:

  • Re-create the virtual machine with the same name and same resource group name, cloud service name,
    or
  • Stop protecting the virtual machine with or without deleting the backup data. For more information, see Stop protecting virtual machines.

UserErrorBCMPremiumStorageQuotaError - Could not copy the snapshot of the virtual machine, due to insufficient free space in the storage account

Error code: UserErrorBCMPremiumStorageQuotaError
Error message: Could not copy the snapshot of the virtual machine, due to insufficient free space in the storage account

For premium VMs on VM backup stack V1, we copy the snapshot to the storage account. This step makes sure that backup management traffic, which works on the snapshot, doesn't limit the number of IOPS available to the application using premium disks.
We recommend that you allocate only 50 percent, 17.5 TB, of the total storage account space. Then the Azure Backup service can copy the snapshot to the storage account and transfer data from this copied location in the storage account to the vault.

380008, AzureVmOffline - Failed to install Microsoft Recovery Services extension as virtual machine is not running

Error code: 380008, AzureVmOffline
Error message: Failed to install Microsoft Recovery Services extension as virtual machine is not running

The VM Agent is a prerequisite for the Azure Recovery Services extension. Install the Azure Virtual Machine Agent and restart the registration operation.

  1. Check if the VM Agent is installed correctly.
  2. Make sure that the flag on the VM config is set correctly.
Read more about installing the VM Agent and how to validate the VM Agent installation.

ExtensionSnapshotBitlockerError - The snapshot operation failed with the Volume Shadow Copy Service (VSS) operation error

Error code: ExtensionSnapshotBitlockerError
Error message: The snapshot operation failed with the Volume Shadow Copy Service (VSS) operation error This drive is locked by BitLocker Drive Encryption. You must unlock this drive from the Control Panel.

Turn off BitLocker for all drives on the VM and check if the VSS issue is resolved.

VmNotInDesirableState - The VM isn't in a state that allows backups

Error code: VmNotInDesirableState
Error message: The VM isn't in a state that allows backups.

  • If the VM is in a transient state between Running and Shut down, wait for the state to change. Then trigger the backup job.

  • If the VM is a Linux VM and uses the Security-Enhanced Linux kernel module, exclude the Azure Linux Agent path /var/lib/waagent from the security policy and make sure the Backup extension is installed.

  • The VM Agent isn't present on the virtual machine:
    Install any prerequisite and the VM Agent. Then restart the operation. |Read more about VM Agent installation and how to validate VM Agent installation.

ExtensionSnapshotFailedNoSecureNetwork - The snapshot operation failed because of failure to create a secure network communication channel

Error code: ExtensionSnapshotFailedNoSecureNetwork
Error message: The snapshot operation failed because of failure to create a secure network communication channel.

  • Open the Registry Editor by running regedit.exe in an elevated mode.
  • Identify all versions of the .NET Framework present in your system. They're present under the hierarchy of registry key HKEY_LOCAL_MACHINESOFTWAREMicrosoft.
  • For each .NET Framework present in the registry key, add the following key:
    SchUseStrongCrypto'=dword:00000001.

ExtensionVCRedistInstallationFailure - The snapshot operation failed because of failure to install Visual C++ Redistributable for Visual Studio 2012

Error code: ExtensionVCRedistInstallationFailure
Error message: The snapshot operation failed because of failure to install Visual C++ Redistributable for Visual Studio 2012.

  • Navigate to C:PackagesPluginsMicrosoft.Azure.RecoveryServices.VMSnapshotagentVersion and install vcredist2013_x64.
    Make sure that the registry key value that allows the service installation is set to the correct value. That is, set the Start value in HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesMsiserver to 3 and not 4.
    If you still have issues with installation, restart the installation service by running MSIEXEC /UNREGISTER followed by MSIEXEC /REGISTER from an elevated command prompt.
  • Check the event log to verify if you're noticing access related issues. For example: Product: Microsoft Visual C++ 2013 x64 Minimum Runtime - 12.0.21005 -- Error 1401.Could not create key: SoftwareClasses. System error 5. Verify that you have sufficient access to that key, or contact your support personnel.
    Ensure the administrator or user account has sufficient permissions to update the registry key HKEY_LOCAL_MACHINESOFTWAREClasses. Provide sufficient permissions and restart the Windows Azure Guest Agent.
  • If you have antivirus products in place, ensure they have the right exclusion rules to allow the installation.

UserErrorRequestDisallowedByPolicy - An invalid policy is configured on the VM which is preventing Snapshot operation

Error code: UserErrorRequestDisallowedByPolicy
Error message: An invalid policy is configured on the VM which is preventing Snapshot operation.

If you have an Azure Policy that governs tags within your environment, either consider changing the policy from a Deny effect to a Modify effect, or create the resource group manually according to the naming schema required by Azure Backup.

Jobs

Error detailsWorkaround
Cancellation isn't supported for this job type:
Wait until the job finishes.
None
The job isn't in a cancelable state:
Wait until the job finishes.
or
The selected job isn't in a cancelable state:
Wait for the job to finish.
It's likely that the job is almost finished. Wait until the job is finished.
Backup can't cancel the job because it isn't in progress:
Cancellation is supported only for jobs in progress. Try to cancel an in-progress job.
This error happens because of a transitory state. Wait a minute and retry the cancel operation.
Backup failed to cancel the job:
Wait until the job finishes.
None

Restore

Disks appear offline after File Restore

If after restore, you notice the disks are offline then:

  • Verify if the machine where the script is executed meets the OS requirements. Learn more.
  • Ensure you are not restoring to the same source, Learn more.

UserErrorInstantRpNotFound - Restore failed because the Snapshot of the VM was not found

Error code: UserErrorInstantRpNotFound
Error message: Restore failed because the snapshot of the VM was not found. The snapshot could have been deleted, please check.

This error occurs when you are trying to restore from a recovery point that was not transferred to the vault and was deleted in the snapshot phase.
To resolve this issue, try to restore the VM from a different restore point.

Common errors

Error detailsWorkaround
Restore failed with a cloud internal error.
  1. The cloud service to which you're trying to restore is configured with DNS settings. You can check:
    $deployment = Get-AzureDeployment -ServiceName 'ServiceName' -Slot 'Production' Get-AzureDns -DnsSettings $deployment.DnsSettings.
    If Address is configured, then DNS settings are configured.
  2. The cloud service to which to you're trying to restore is configured with ReservedIP, and existing VMs in the cloud service are in the stopped state. You can check that a cloud service has reserved an IP by using the following PowerShell cmdlets: $deployment = Get-AzureDeployment -ServiceName 'servicename' -Slot 'Production' $dep.ReservedIPName.
  3. You're trying to restore a virtual machine with the following special network configurations into the same cloud service:
    • Virtual machines under load balancer configuration, internal and external.
    • Virtual machines with multiple reserved IPs.
    • Virtual machines with multiple NICs.
  4. Select a new cloud service in the UI or see restore considerations for VMs with special network configurations.
The selected DNS name is already taken:
Specify a different DNS name and try again.
This DNS name refers to the cloud service name, usually ending with .cloudapp.net. This name needs to be unique. If you get this error, you need to choose a different VM name during restore.
This error is shown only to users of the Azure portal. The restore operation through PowerShell succeeds because it restores only the disks and doesn't create the VM. The error will be faced when the VM is explicitly created by you after the disk restore operation.
The specified virtual network configuration isn't correct:
Specify a different virtual network configuration and try again.
None
The specified cloud service is using a reserved IP that doesn't match the configuration of the virtual machine being restored:
Specify a different cloud service that isn't using a reserved IP. Or choose another recovery point to restore from.
None
The cloud service has reached its limit on the number of input endpoints:
Retry the operation by specifying a different cloud service or by using an existing endpoint.
None
The Recovery Services vault and target storage account are in two different regions:
Make sure the storage account specified in the restore operation is in the same Azure region as your Recovery Services vault.
None
The storage account specified for the restore operation isn't supported:
Only Basic or Standard storage accounts with locally redundant or geo-redundant replication settings are supported. Select a supported storage account.
None
The type of storage account specified for the restore operation isn't online:
Make sure that the storage account specified in the restore operation is online.
This error might happen because of a transient error in Azure Storage or because of an outage. Choose another storage account.
The resource group quota has been reached:
Delete some resource groups from the Azure portal or contact Azure Support to increase the limits.
None
The selected subnet doesn't exist:
Select a subnet that exists.
None
The Backup service doesn't have authorization to access resources in your subscription.To resolve this error, first restore disks by using the steps in Restore backed-up disks. Then use the PowerShell steps in Create a VM from restored disks.

Backup or restore takes time

If your backup takes more than 12 hours, or restore takes more than 6 hours, review best practices, andperformance considerations

VM Agent

Set up the VM Agent

Typically, the VM Agent is already present in VMs that are created from the Azure gallery. But virtual machines that are migrated from on-premises datacenters won't have the VM Agent installed. For those VMs, the VM Agent needs to be installed explicitly.

Windows VMs - Set up the agent

  • Download and install the agent MSI. You need Administrator privileges to finish the installation.
  • For virtual machines created by using the classic deployment model, update the VM property to indicate that the agent is installed. This step isn't required for Azure Resource Manager virtual machines.

Linux VMs - Set up the agent

  • Install the latest version of the agent from the distribution repository. For details on the package name, see the Linux Agent repository.
  • For VMs created by using the classic deployment model, update the VM property and verify that the agent is installed. This step isn't required for Resource Manager virtual machines.

Update the VM Agent

Create New Time Machine Backup

Windows VMs - Update the agent

  • To update the VM Agent, reinstall the VM Agent binaries. Before you update the agent, make sure no backup operations occur during the VM Agent update.

Linux VMs - Update the agent

  • To update the Linux VM Agent, follow the instructions in the article Updating the Linux VM Agent.

    Note

    Always use the distribution repository to update the agent.

    Don't download the agent code from GitHub. If the latest agent isn't available for your distribution, contact the distribution support for instructions to acquire the latest agent. You can also check the latest Windows Azure Linux agent information in the GitHub repository.

Validate VM Agent installation

Verify the VM Agent version on Windows VMs:

  1. Sign in to the Azure virtual machine and navigate to the folder C:WindowsAzurePackages. You should find the WaAppAgent.exe file.
  2. Right-click the file and go to Properties. Then select the Details tab. The Product Version field should be 2.6.1198.718 or higher.

Troubleshoot VM snapshot issues

VM backup relies on issuing snapshot commands to underlying storage. Not having access to storage or delays in a snapshot task run can cause the backup job to fail. The following conditions can cause snapshot task failure:

  • VMs with SQL Server backup configured can cause snapshot task delay. By default, VM backup creates a VSS full backup on Windows VMs. VMs that run SQL Server, with SQL Server backup configured, can experience snapshot delays. If snapshot delays cause backup failures, set following registry key:

  • VM status is reported incorrectly because the VM is shut down in RDP. If you used the remote desktop to shut down the virtual machine, verify that the VM status in the portal is correct. If the status isn't correct, use the Shutdown option in the portal VM dashboard to shut down the VM.

  • If more than four VMs share the same cloud service, spread the VMs across multiple backup policies. Stagger the backup times, so no more than four VM backups start at the same time. Try to separate the start times in the policies by at least an hour.

  • The VM runs at high CPU or memory. If the virtual machine runs at high memory or CPU usage, more than 90 percent, your snapshot task is queued and delayed. Eventually it times out. If this issue happens, try an on-demand backup.

Networking

DHCP must be enabled inside the guest for IaaS VM backup to work. If you need a static private IP, configure it through the Azure portal or PowerShell. Make sure the DHCP option inside the VM is enabled.Get more information on how to set up a static IP through PowerShell:

Even though Azure SQL Database provides built-in backup, you may still want to create a local copy of your Azure SQL database. This could be handy for example when you want to keep database backup copy for free longer than allowed by Microsoft Azure built-in tools which is usually 7 to 35 days, depending on your service tier. Here we will explain in details how to backup Azure SQL Database to Local Machine.

There are several ways to download Azure database to your computer. The table below summarizes several key methods with pros, cons and usage scenarios. Click the name for more details about each method.

    • Simple process
    • Works even with old SQL Server / SSMS
    • Can export data into different file formats
    • Only data is imported, all other objects will be lost
    • Requires SQL Server Management Studio
    • Manual procedure
    Use if you need to move data from Azure to a specific destination (e.g. your old SQL Server) or in a particular format (e.g. flat file) with SQL Server Management Studio tools
    • Can export data into different file formats
    • Can be run unattended/automatically
    • Only data is imported, all other objects will be lost
    Similar to SQL Server Import and Export Wizard, but enables automatic process
    • Creates the most exact copy of the database
    • Simple user interface
    • Requires the latest DAC library installed
    • Creates a specific BACPAC file
    • Manual procedure
    Use when you need to create BACPAC file with SQL Server Management Studio tools
    • Creates the most exact copy of the database
    • Can be run unattended/automatically
    • Requires the latest DAC library installed
    • Creates a specific BACPAC file
    Use if you need to create BACPAC file from a command line
    • Can export data into different file formats
    • Can be run unattended/automatically
    • Only data is imported, all other objects will be lost
    • Imports only one table at a time
    Use if you need to save data from one or several tables in a readable format
    • Simple UI
    • Can create scheduled backups
    • Doesn't require DAC library installed
    Use when you need to perform automatic backups into BACPAC file regularly
    • Everything online, no software installation required
    • Creates a specific BACPAC file
    • Azure storage account is required

Azure SQL Database Firewall Setup

Since we are going to connect to Azure SQL Database from outside, we need to set up built-in firewall accordingly by adding IP address of the machine to which we want to download our database copy.

For that go to Azure Portal, select 'SQL databases' > Your database > 'Set server firewall':

Then, add the new rule and don't forget clicking 'Save'. For convenience, you can click on 'Add client IP' and the rule for the current IP address will be generated automatically:

How to Backup Azure SQL Database Using SQL Server Import and Export Wizard

Using built-in SSMS SQL Server Import and Export Wizard you can convert data between any sources, including ODBC, OLE DB, MS Access, MS Excel, and even flat file. This is exactly what we will use to copy data from Azure SQL Database to a local computer.

For starters, open SQL Server Management Studio and connect to your Azure SQL Database. If upon connecting you see the following message:

Cannot open server ‘azure_server_name' requested by the login. Client with IP address ‘83.219.146.206' is not allowed to access the server. To enable access, use the Windows Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect.

then you need to add your IP address to Azure Firewall.

Following a successful connection, select the database you need (in this case its AdventureWorks), right-click of the mouse and select 'Tasks' > 'Import Data' (or 'Export Data'):

This will prompt SQL Server Import and Export Wizard where you need to select '.Net Framework Data Provider for SqlServer' as a source and then enter the details of your Azure databasе:

The easiest way of doing that is to enter a ConnectionString which you can obtain on Azure Portal:

Don't forget to change {your_username} and {your_password} in connection string into real values.

Clicking the 'Next' button will trigger connection testing. If everything goes well you will be asked for the Destination parameters. From the drop-down list you will be able select not only SQL Server, but Excel, Access, and even Flat File as well:

If you want to export data to SQL Server, you can obtain a Connection String using the following query:

Following a successful connection to the destination, you will be prompted to select export of all data or only the result of a specific query. Selecting all data will require you to select tables for export. Selecting only query data will ask you to enter the query text.

The last step will run the export. A successful export screen will look similar to the one below:

If should be noted that during one of the interim steps you will be prompted to save the export as SSIS Package. This will enable export with SSIS tools, which are reviewed in the next section.

How to Backup Azure SQL Database Using SQL Server Integration Services (SSIS)

SQL Server Integration Services is a powerful platform that allows to integrate and transform data between various applications. We have already faced it in the previous section when we exported Azure Database with SQL Server Import and Export Wizard.

SSIS allows running such export automatically (e.g. from a command line) if you have .dtsx file (SSIS Package) that contain all the necessary information about the export procedure. You can create such file with SSMS (as described above), and then run it either with DTEXEC.EXE command line utility, or with DTEXECUI application, or with SQL Server Agent Job.

For example, if you saved export parameters into AzureExport.dtsx, you can run it again by using the following command:

If you prefer a graphical interface, you can use The Execute Package Utility (DTEXECUI) app, although it requires Management Tools – Basic or Business Intelligence Studio to be installed by the SQL Server.

How to Export Azure SQL Database to BACPAC File

SQL Server Management Studio includes a simple option to export your Azure SQL Database into a .bacpac file. In this tutorial, we will show how to do it using SSMS.

Requirements

  1. You will need SSMS Installed
  2. Make sure that the firewall rule is enabled in the Azure SQL Server
  3. An Azure SQL Database installed
  4. Internet Connection

You will first need to connect to your Azure SQL Database using SSMS.

Once that you are in SSMS right click on your Azure SQL database and select Task and Export Data-tier Application:

This option will open a Wizard. In the first part, it will show an introduction. In the introduction, press Next.

In the Export Settings section go to Save to local disk and specify a local path in your machine to install the bacpac file.

The wizard will go to Summary to show all the settings configured. Press next in that section.

Eventually, if everything is OK will show a green status. The exporting process includes exporting data, schemas, tables, references and all other database components. Once that you receive the message, you can verify the bacpac of the file exported and used to recover the database to another SQL Server.

How to Backup Azure SQL Database Using SqlPackage Utility

The SqPackage Utility allows to import or export data using the command line. It can be very useful if we need to automate and program import and export tasks. This software is usually installed with SSMS or SSDT. To search it you can use in the cmd with the following commands (make sure to run the cd first):

The command will show the path of sqlpackage utility. The path is usually similar to this one:

The syntax for the SqlPackage to export is the following:

Let's run a simple example:

We are exporting a file (Export) to an Azure SQL Server named sqlftpbackupserver.database.windows.net and the source database name is sqlftpbackup. The source user is daniel and the target file where we will export is in the c:sqlsqlftpbackup.bacpac sp is to specify the Azure SQL database password of the Azure SQL user. Finally, we will store in a file.

Common errors

A typical error is this one:

*** Error exporting database: Could not connect to database server.
Cannot open server ‘sqlftpbackupserver' requested by the login. Client with IP address ‘181.114.103.171' is not allowed to access the server. To enable access, use the Windows Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect.

If this is your error, set the firewall. We already wrote how to do it at the beginning of this article.

Another typical error is this one:

*** Error exporting database: The database compatibility level '12' is not within the supported range of 80 to 130.

This is a problem with Azure. The level in SQL Server on premisses is between 80 and 130, however in Azure SQL, hte level is 12. To do this we will need to run the following T-SQL in Azure. You can use SSMS, but I prefer to use the Query Editor in the Portal because you do not need to install anything:

How to Backup Azure SQL Database Using BCP Utility

In this example, we will have a table named xxx and we want to export it to a file using the bcp utility (bulk copy program). In the command line check if you have the BCP utility. If you do not have it, you will receive the following message:

bcp is not a recognized as an external/internal command or operable program or batch file

If you receive this message, you can download the bcp utility here. Once installed, in the command line write this:

Sqlftpbackupdb is the database name. SalesLT is the schema and CustomerAddress is the table to export. We will export the table to a local file in the c: drive in the sqlfile folder and the name of the file will be cust.dat. -c is used to convert to char data type. -U is used to specify the user name and -S the Azure Server name.

The command line will ask for a password. Write the password.

A typical error message here is:

SQLState = 37000, NativeError = 40615

Error = [Microsoft][ODBC Driver 13 for SQL Server][SQL Server] Cannot open server ‘sqlftpbackupserver' requested by the login. Client with IP address ‘181.114.102.51' is not allowed to access the server. To enable access, use the Windows Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect.

To solve this error, go to the Azure Portal and go to Firewall/Virtual Networks:

In Firewall/Virtual Networks press + Add client IP and press Save:

If everything is OK, you will be able to copy the files and it will show the number of rows copied:

Some tips:

  • If there are millions of rows, you will need to specify the batch size. You can use the -b to specify the number of rows per batch.
  • Make sure that the account in the command line has access to write data in the local folder specified.
  • Also, the internet connection is important. If you do not have a good internet connection, the bcp operation may fail.
  • To increase the performance, the hint TABLOCK may be useful (-h tablock) this hint locks the table during the bcp operations to improve the bcp performance.
  • By default, the triggers are not fired in these operations.

How to Backup Azure SQL Database Using SqlBackupAndFtp

Time Machine Online Backup

SqlBackupAndFtp is an extremely powerful tool to backup SQL databases to Azure, Dropbox, FTP a local file, Amazon S3, Box, Google Drive and other options. In this example, we will backup an Azure SQL database in a local file named sqlftpbackupdb201803082133.zip.

You will first need to download and install SqlBackupAndFtp. The application will ask the Server type. In this example, it is Azure SQL Database. It will ask the Azure SQL Server name, a user name and a password. This information is set when you create the Azure SQL Server.

The next step will be to select the database. In this example, the Azure SQL Database name is sqlftpbackupdb. Press Select databases and check the database. You can also see system databases (the master database in Azure SQL):

In 'Store backups' section select destination, you can store in a local folder, a network folder, NAS, an FTP Server, Amazon S3, Dropbox, Google Drive, Onedrive, Box and many other options. In this example, we will store the backup in a locally.

The last step would be to Run the job. You can Run immediately with the 'Run Now' option or you can schedule the backup. You can also receive emails if the backup succeed or if it fails. This is extremely useful if the backup process takes a long time because you don't need to wait until it's done as you will be notified in case of success or failure. It is not necessary to install SMTP-server or something extra to send these emails.

If everything goes OK, a zip file with the backup will be created.

How to Export Azure SQL Database from Azure Portal

You can save your Azure SQL Database in a BACPAC file, which is intrinsically a ZIP file containing the metadata and data from it. You can download the BACPAC file locally and later import it back to Azure or to a SQL Server on-premises installation. However, keep in mind that in order to guarantee transaction consistency a copy of your Azure Database will be created during the export process. This copy is treated as a second database and is billed as such. So, if your database is quite big it might take significant time and money to export it locally.

Let's create an Azure Storage Account first. A Storage Account is a place in the cloud where you can store files, blobs, queues. It is redundant and secure. In order to create it, enter the Azure Portal, go to the search and write Storage and go to Storage accounts (classic). Note that you can only create bacpac in classic storage accounts:

It is now time to export the database backup to the Azure Storage account just created. Select your Azure database and then select export:

Specify a file name, make sure that the subscription is OK. Configure the login and password. In Configure Required settings, press the button to configure it:

Select the Classic Azure Storage account created before and press + to create a new container. Specify a name for the container and save the bacpac file in that container:

If you need to check the bacpac, click on the container just created:

In the container, you will be able to see the file. Right-click and press Download to have on your local machine:

References





broken image