Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of configuring timed custom snapshots through API

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail the method of configuring timed custom snapshots through API. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

How to customize snapshots regularly through API configuration

SSD cloud disk cannot open automatic snapshots, so you need to call API to set scheduled tasks to complete snapshot automation.

1. Install and configure the AliyunCli environment

Refer to the official documentation: AliyunCli configuration

2. Save the following as script / home/creare.sh

# this script is only tested and executed under Linux #! / bin/bash#source / etc/profile# keep several snapshots (cannot be larger than 24 without custom snapshots) num=3num=$ [$num-1] # check AliyunCli execution path path= `which aliyuncli` # check AliyunCli and ECS SDK installation check= `$ path-- help | wc-l`check _ sdk= `$path ecs | wc-l`start _ snapshot () {for instance in `cat / home/ instance.txt` Dodisk= `$ path ecs DescribeDisks-- InstanceId $instance-- output json-- filter Disks.Disk [*] .DiskId | awk-F "\"'{print $2} '`region= `$ path ecs DescribeDisks-- InstanceId $instance-- output json-- filter Disks.Disk [0] .RegionId | awk-F "\"' `for disk in $diskdoid= `$path ecs DescribeSnapshots-RegionId $region-DiskId $disk-Status accomplished-SnapshotName ScriptsCreate-output json-filter Snapshots.Snapshot [$num] .SnapshotId | awk-F "\" {print $2} '`if [["$id"! = "]] Then$path ecs DeleteSnapshot-- SnapshotId $idsleep 2snapshot=ScriptsCreate$path ecs CreateSnapshot-- DiskId $disk-- SnapshotName $snapshotelsesnapshot=ScriptsCreate$path ecs CreateSnapshot-- DiskId $disk-- SnapshotName $snapshotfisleep 1donesleep 1done} if [["$check"-ge "38"]; then if [["$check_sdk"-ge "56"]]; then start_snapshot else echo "Please make sure ECS SDK is installed correctly before executing the script!" Fielseecho "Please make sure that AliyunCli is installed correctly before you execute the script!" Fi

Note: the above script automatically deletes snapshots created by the earliest script with more than the number of backups.

Make sure that the snapshot created by the script is sufficient, otherwise the execution of the script will fail.

For example:

If the NUM is set to 3 and there are 3 disks, then the remaining limit of the snapshot needs to be greater than or equal to 9.

3. Save the ECS instance ID that needs to add automatic snapshots to the / home/instance.txt file

4. Add crontab scheduled tasks (perform scheduled tasks at 01:30 every night)

Crontable-e inserts the following:

30 1 * / bin/sh / home/create.sh

Restart the crond service

Service crond restart

5. After the snapshot is executed, we will see the snapshot named ScriptsCreate on the console.

This is the end of the method of configuring timed custom snapshots through API. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report