Home > Operation and Maintenance > Linux Operation and Maintenance > How to configure scheduled custom snapshots through API

How to configure scheduled custom snapshots through API

坏嘻嘻
Release: 2018-09-29 16:00:12
Original
2087 people have browsed it

本篇文章给大家带来的内容是关于如何通过API配置定时自定义快照,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

如何通过API配置定时自定义快照

SSD云盘无法开启自动快照,那么就需要自己调用API来设定计划任务完成快照自动化

1、安装配置AliyunCli环境

参考官方文档:AliyunCli配置 

2、将如下内容保存为脚本/home/creare.sh

### 本脚本仅测试并执行于Linux下
#!/bin/bash
#source /etc/profile
#保留几份快照(无自定义快照情况下不能大于24)
num=3
num=$[$num - 1]
#检查AliyunCli执行路径
path=`which aliyuncli`
#检查AliyunCli和ECS SDK安装情况
check=`$path --help |wc -l`
check_sdk=`$path ecs |wc -l`
start_snapshot(){
for instance in `cat /home/instance.txt`;
do
disk=`$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 "\"" '{print $2}'`
for disk in $disk
do
id=`$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 $id
sleep 2
snapshot=ScriptsCreate
$path ecs CreateSnapshot --DiskId $disk --SnapshotName $snapshot
else
snapshot=ScriptsCreate
$path ecs CreateSnapshot --DiskId $disk --SnapshotName $snapshot
fi
sleep 1
done
sleep 1
done
}
if [[ "$check" -ge "38" ]];then
    if [[ "$check_sdk" -ge "56" ]]; then
    start_snapshot
    else
    echo "请先确保ECS SDK安装正确,再来执行该脚本!"
    fi
else
echo "请先确保AliyunCli安装正确,再来执行该脚本!"
fi
Copy after login

注意:上述脚本会自动删除备份个数以上的最早的脚本创建的快照

请确保脚本创建的快照额度够用,否则会导致脚本执行部分失败

例如:

设置NUM为3,有3个磁盘,那么快照剩余额度需要大于等于9个

3、将需要添加自动快照的ECS实例ID保存到/home/instance.txt文件中

4、添加crontab计划任务(每晚1点30分执行计划任务)

crontable -e插入如下内容:

30 1 * * * /bin/sh /home/create.sh
Copy after login

重启crond服务

service crond restart
Copy after login

5、快照执行完毕后我们会在控制台看到名称为ScriptsCreate的快照

How to configure scheduled custom snapshots through API


The above is the detailed content of How to configure scheduled custom snapshots through API. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template