Azure PowerShell Scripts ported to BASH. This script solves the very same purpose for people who are BASH lovers and are not comfortable with PowerShell.
This repository contains scripts that are used by Microsoft Customer Service and Support (CSS) to aid in gaining better insight into, or troubleshooting issues with, deployments in Microsoft Azure. A goal of this repository is provide transparency to Azure customers who want to better understand the scripts being used and to make these scripts accessible for self-help scenarios outside of Microsoft support.
These scripts are generally intended address a particular scenario and are not published as samples of best practices for inclusion in applications.
For code and scripting examples of best practice see OneCode, OneScript, and the Microsoft Azure Script Center.
For documentation on how to build and deploy applications to Microsoft Azure, please see the Microsoft Azure Documentation Center.
For more information about support in Microsoft Azure see http://azure.microsoft.com/support
If an Azure VM is inaccessible it may be necessary to attach the OS disk to another Azure VM in order to perform recovery steps. The VM recovery scripts automate the recovery steps below.
- Stops the problem VM.
- Takes a snapshot of the problem VM's OS disk.
- Creates a new temporary VM ("rescue VM").
- Attaches the problem VM's OS disk as a data disk on the rescue VM.
- You can then connect to the rescue VM to investigate and mitigate issues with the problem VM's OS disk.
- Detaches the problem VM's OS disk from the rescue VM.
- Performs a disk swap to swap the problem VM's OS disk from the rescue VM back to the problem VM.
- Removes the resources that were created for the rescue VM.
You may run this script if you may require a temporary (Rescue) VM for troubleshooting of the OS Disk. This Script Performs the following operation :
- Stop and Deallocate the Problematic Original VM
- Make a OS Disk Copy of the Original Problematic VM depending on the type of Disks
- Create a Rescue VM (based on the Original VM's Distribution and SKU) and attach the OS Disk copy to the Rescue VM
- Start the Rescue VM for troubleshooting.
You may run this script once the troubleshooting of the OS Disk is performed on a Rescue VM. This Script Performs the following operation :
- Detach the Attached OS Disk to the Rescue VM
- Stop and Deallocate the Problematic Original VM
- Perform OS Disk Swap with Detached OS Disk with the Problematic VM
- Start the Fixed (Problematic) Original VM with the swapped OS Disk
The Support for this script is limited to the Non-Encrypted Virtual Machines available as part of Microsoft Azure Resource Manager. The script does not store the Encryption Settings of the Virtual Machines and hence absolutely not to be run on an Encrypted Azure Virtual Machine for Troubleshooting.
The Script fails for special custom Virtual Machines Images which follow the following criterion:
- Only one Virtual Machine may be created in a Single resource group.
The following Requirements are Mandatory inorder to run the scripts successfully
-
Python - (Any verison as long as Azure CLI is supported)
-
BASH command processor or BASH Terminal.
-
An Active Azure Subscription.
-
JSON commandline Processing | jq command for BASH terminal
In RHEL/Centos Operating System
yum install jq
In Ubuntu/Debian Operating System
apt install jq
The best way to run the above script is to use the Cloud Shell in Microsoft Azure Portal. Cloud Shell satisfies all the above requirements and is the best option. For more information, please look at the usage page.
-
Launch BASH in Azure Cloud Shell
-
If it is your first time connecting to Azure Cloud Shell, select
BASH
when you seeWelcome to Azure Cloud Shell
. -
If you then see
You have no storage mounted
, select the subscription where the VM you are troubleshooting resides, then selectCreate storage
.
You may skip the above steps if you already possess a BASH terminal which satisfies the Requirement section.
- The time has now arrived to start executing scripts. First clone the git repository to our cloud shell.
git clone https://github.com/sribs/azure-support-scripts
- Change directory to the Repository directory that is now available in the cloud shell after performing Step 4.
cd azure-support-scripts
- Execute the commands as per the requirement as stated in the Component Specification section.
./restore-original.sh -s <Subscription Id> --rescue-vm-name <Rescue VM Name> --rescue-resource-group <Rescue VM Resource Group> -g <Original VM's resource group> -n <Original VM Name> --os-disk <FIxed OS Disk now used for OS Disk Swap>
./new-rescue.sh --rescue-vm-name <Rescue VM Name> -g <Original VM Resource Group> -n <Original VM Name> -s <Subscription Id> -u <Admin Username for Rescue VM> -p <Admin Password for Rescue VM>