Hi, everyone, 2018 Spring Festival just passed, I think we must feel short holiday, did not have fun, but we IT workers life is so helpless pain, think also can only roll up sleeves hard work.


Secret sharing: Backup and clone SLB instances


1. Greetings 🙂


Hi, everyone, 2018 Spring Festival just passed, I think we must feel that the holiday is short, did not have fun, but we IT workers life is so helpless pain, think can only roll up sleeves hard work. But it would be great if there were some clever way to increase productivity and get people out of work earlier every day. Today I will share with you an exclusive secret, SLB instance clone.


2. Why clone instances


Because some partners SLB instance configuration is very complex. For example, there are many virtual server groups, primary and secondary server groups, and back-end servers; Or there are many listeners, and each listener is configured with many access control whitelists, and different health check ports and paths; Or n forwarding rules are configured on layer 7 listening, and each forwarding rule matches a different domain name, URL, and back-end server. OMG, it’s complicated to think about it. My head is going to explode. If the CTO grabs you and says, “We’re going to do instation-level high availability, and we need you to prepare a new SLB instance with the same configuration as the original one,” you’re going to cry. I know there is an API for batch processing of similar things, but I forgot all the code.


3. Help is here


Aliyun-slb-helper is a small tool that can backup and clone SLB instances using the SLB SDK package of Aliyun Cloud. It can export the SLB instance configuration file online to the local computer, and clone a new instance using the local configuration file, or directly clone an online instance. Isn’t that awesome? Here’s how to use it:


3.1 Preparations


1. Install JRE or JDK1.8 or later, please download it from Baidu (if you only want to run the version compiled by me, you only need to download JRE. If you need to modify the code by yourself, and compile, you need to download JDK, MAVEN and other tools)
2. Download and decompress the aliyun-slb-helper.jar file. See the attachment
3. Prepare the ak.json file and store it in the same directory as the aliyun-slb-helper.jar file. The ak.json file is a JSON string
{ “accessKeyId”: “xxxx”, “accessKeySecret”: “xxxx” }


Replace XXXX with your own AccessKey. To obtain the AccessKey, visit the AccessKey management page
Please take good care of the AccessKey. Disclosing the AccessKey means disclosing the account and password of the cloud account


3.2 Backing up and Cloning SLB Instances


Enter the following command on the console and press Enter


java -jar aliyun-slb-helper.jar


If you see the following message, everything is OK
Let’s run it with parameters:
java -jar aliyun-slb-helper.jar export all


This command exports all SLB instances of all regions on the line to the current directory SLBS. The following figure shows the command output
Run the following command
java -jar aliyun-slb-helper.jar clone local ‘filename’


To clone an instance using the SLB configuration file exported locally, filename must be a locally existing file, as shown below:
In the above figure, we clone a new instance using the clone local parameter with a local file path, and display the ID of the new instance. Log in to the console to check and confirm that the instance is successfully generated
You can also clone an online instance by specifying its location and instance ID as follows:


java -jar aliyun-slb-helper.jar clone online ‘region’ ‘loadbalancerId’


Look, we cloned the instance and generated a new instance ID


4. Precautions and Instructions


1. The instance cloning function ignores the charging mode of the original instance. Regardless of whether the original instance is paid by volume or by year, the new instance is cloned in the same region as the original instance
2. Currently, only listening configurations and back-end servers, virtual server groups, and primary and secondary server groups are cloned. Forwarding rules and access control whitelists are not implemented
3. Disclaimer: Use this tool in production environment at your own risk
4. Github: Papaorange/Aliyun-slb-Helper
5. The level is limited, there may be bugs in the code, welcome all masters to criticize


The original link


To read more articles, please scan the following QR code: