Instant File Recovery from Azure VM – image credit: Microsoft
Contents of this Article
Azure Backup is the Azure based service you can use to backup and restore your data in Microsoft Azure Cloud Platform. Azure Backup replaces your existing on-premises or off-site backup solution with a cloud-based solution that is reliable, secure, and cost-effective. Please check the following article for the complete overview of the features in Azure Backup.
Earlier this year, Microsoft announced the preview of File and Folder Recovery from Azure Linux VM and Azure Windows VM backups. Last month, Microsoft announced the generally availability (GA) of this service. You can read all about here.
In this blog post, I will show you how to restore files and folders from Azure Linux VM using Azure Backup.
You need to have a Linux VM deployed in Azure with Azure Backup enabled. Please check the following post to learn more about how to enable back up for Azure virtual machines.
You need to have Linux machine running on-premises to recover Files and Folders and vice versa for Azure Windows VM as well. This is very important, more on that on How it works… section.
You need to ensure that the OS of the recovery Linux machine on-premises is compatible with the backed up VM in Azure. The supported versions are as follows:
- Ubuntu – V12.04 and above
- CentOS – V6.5 and above
- RHEL – V6.7 and above
- Debian – V7 and above
- Oracle Linux – V6.4 and above
How to do it…
Assuming you have all the prerequisites in place. Now take the following steps:
- Login to Azure portal.
- Browse to Virtual machines blade and select the Linux VM that you want to recover from.
- Click on Backup under SETTINGS, and then click on File Recovery.
- The File Recovery blade will open as shown in the next screenshot. Select which recovery point you want to recover from the drop-down list.
- Click on “Download Script *” and then save it on your local machine.
- You need to copy this script to your Linux machine running on-premises. There are certain ways to do that. In this example, I will use WinSCP a free tool for SFTP, SCP and FTP client for Windows.
- Connect using WinSCP to your Linux machine and then copy the script to your home directory.
- Login to your Linux machine and Open Terminal window.
- Type: sudo bash and enter your credentials.
- Type: chmod +x followed by the script file name as shown in the next screenshot.
- chmod is the command and system call which may change the access permissions to file system objects (files and directories). The mode +x will apply execute permissions to the file that we just copied.
- Type: bash followed by the script file name as shown in the next screenshot. The script requires administrative privilege to run.
- Microsoft Azure VM Backup – File Recovery will launch. Enter the password as shown on the portal. The connection will succeed and the mount path for the attached volume will be displayed as shown in below screenshot.
- Enter ‘q‘ or ‘Q‘ to exit.
- You can simply browse to the relevant mount path by typing cd followed by the MountPath. After that you can list the file system and see all the files and folders.
- Finally, you can copy the desired file and folder to your local machine by running the following command: cp -a /SourcePath/ . /DestinationPath/
The “-a” option is an improved recursive option, that preserve all file attributes, and also preserve symlinks. The “.” at end of the source path is a specific “cp” syntax that allow to copy all files and folders, included hidden ones.
How it works…
When you click on File Recovery, you need to select which recovery point you want to recover, the latest recovery point is selected by default. Next, you need to download a script. The script and password will be generated instantly. You will require this password to run the script.
What this script do is, when you are trying to do a file or folder recovery for the first time, the script will open an iSCSI and LSHW component to be installed on the Linux machine to connect to the recovery point. The script has a time bomb in it and it is valid only for 6 hours, after that the script is not valid anymore, and you have to download it again. This is very important for security reasons.
As mentioned earlier in this post, the script should be run on a Linux machine because this is a Linux VM that you are trying to mount, it will expose that iSCSI device, it does NOT download everything from the cloud, and then it will mount the iSCSI device to your local machine. The script is a shell script with .sh extension.
After running the script, you are required to enter a password generated automatically from the portal specifically for that script. The iSCSI device will be mounted into your file system, and that mount will be valid only for 12 hours, after that it will automatically disconnect that mount point. You can also click “Unmount Disks” in Step 3 of the portal once the recovery is done. The connection will be closed to the recovery point.
That’s all there is to it.