System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

创建一个名叫Processor的EC2实例,登陆到CommandHost实例,通过AWS CLI对Processor实例的EBS卷做snapshot,设置周期性snapshot的计划任务,

登陆到Processor实例,通过AWS CLI上传并管理日志文件到S3存储桶

1.1 创建一个S3的桶

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

1.2 创建一个IAM策略

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

1.3 创建一个IAM角色

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

1.4 创建一个安全组

System Operations on AWS - Lab 3W - Managing Storage (Windows)

1.5 创建一个EC2实例

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

2.1 连接到CommandHost实例

System Operations on AWS - Lab 3W - Managing Storage (Windows)

System Operations on AWS - Lab 3W - Managing Storage (Windows)

2.2 创建一个初始化snapshot

2.2.1 获得Processor实例的描述

aws ec2 describe-instances --filter 'Name=tag:Name,Values=Processor'

2.2.2 只显示该实例EBS卷的Id

aws ec2 describe-instances --filter 'Name=tag:Name,Values=Processor' --query 'Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.{VolumeId:VolumeId}'

System Operations on AWS - Lab 3W - Managing Storage (Windows)

2.2.3 只显示该实例InstanceId

aws ec2 describe-instances --filters 'Name=tag:Name,Values=Processor' --query 'Reservations[0].Instances[0].InstanceId'

System Operations on AWS - Lab 3W - Managing Storage (Windows)

2.2.4 停止该实例

aws ec2 stop-instances --instance-ids i-3bc0b3fc

2.2.5 检查该实例停止状态

aws ec2 describe-instance-status --instance-id i-3bc0b3fc

System Operations on AWS - Lab 3W - Managing Storage (Windows)

2.2.6 创建一个snapshot

aws ec2 create-snapshot --volume-id vol-09e651ff

2.2.7 检查该snapshot状态

aws ec2 describe-snapshots --snapshot-id snap-fa894fa9

System Operations on AWS - Lab 3W - Managing Storage (Windows)

2.2.8 重新启动Processor实例

aws ec2 start-instances --instance-ids i-3bc0b3fc

System Operations on AWS - Lab 3W - Managing Storage (Windows)

2.2.9 检查该实例启动状态

aws ec2 describe-instance-status --instance-id i-3bc0b3fc

System Operations on AWS - Lab 3W - Managing Storage (Windows)

2.3 创建一个周期性snapshot的计划任务

2.3.1 检查当前Region

type C:\Users\Administrator\.aws\config

System Operations on AWS - Lab 3W - Managing Storage (Windows)

2.3.2 创建用于计划任务的脚本文件c:\temp\backup.bat,内容如下:

aws ec2 create-snapshot --volume-id vol-09e651ff --region us-west-2 >c:\temp\output.txt 2>&1

2.3.3 创建执行计划任务的用户

net user backupuser passw0rd! /ADD

2.3.4 给该用户赋予执行脚本的权限

c:\temp\ntrights +R SeBatchLogonRight -u backupuser

2.3.5 创建一个计划任务

schtasks /create /sc MINUTE /mo 1 /tn "Volume Backup Task" /ru backupuser /rp passw0rd! /tr c:\temp\backup.bat

System Operations on AWS - Lab 3W - Managing Storage (Windows)

2.3.6 等待几分钟,检查新的snapshots是否被创建

aws ec2 describe-snapshots --filters "Name=volume-id,Values=vol-09e651ff"

2.4 保留最后两个snapshots

2.4.1 删除之前创建的计划任务

schtasks /Delete /tn "Volume Backup Task"

2.4.2 检查当前所有snapshots的数量

aws ec2 describe-snapshots --filters "Name=volume-id,Values=vol-09e651ff" --query 'Snapshots[*].SnapshotId'

2.4.3 执行snapshotter.ps1

c:\temp\snapshotter.ps1 us-west-2

2.4.4 再次检查当前snapshots的数量

aws ec2 describe-snapshots --filters "Name=volume-id,Values=vol-09e651ff" --query 'Snapshots[*].SnapshotId'

3.1 移动日志文件到S3

3.1.1 登录到Processor实例

System Operations on AWS - Lab 3W - Managing Storage (Windows)

3.1.2 配置AWS CLI

PS C:\Users\Administrator> aws configure
AWS Access Key ID [None]:
AWS Secret Access Key [None]:
Default region name [None]: us-west-2
Default output format [None]:

3.1.3 下载loggen.ps1

(New-Object System.Net.WebClient).DownloadFile("https://d2lrzjb0vjvpn5.cloudfront.net/sys-ops/v2.4/lab-3-storage-windows/static/loggen.ps1", "c:\temp\loggen.ps1")

3.2.1 运行loggen.ps1

c:\temp\loggen.ps1

3.2.2 打开一个新的PowerShell窗口,并切换到c:\temp

cd \temp

3.2.3 移动一个log文件到之前创建的S3存储桶中

aws s3 mv timestamp.log "s3://s3-bucket-edward/logfiles/timestamp-$(Get-Date -Format 'M-d-yyyy-h:m:s')"

System Operations on AWS - Lab 3W - Managing Storage (Windows)

3.2.4 再次执行该命令

aws s3 mv timestamp.log "s3://s3-bucket-edward/logfiles/timestamp-$(Get-Date -Format 'M-d-yyyy-h:m:s')"

3.2.5 列出该S3存储桶里的内容

aws s3 ls s3://s3-bucket-edward

System Operations on AWS - Lab 3W - Managing Storage (Windows)

3.2.6 列出所有以/logfiles/打头的对象

aws s3 ls s3://s3-bucket-edward/logfiles/

System Operations on AWS - Lab 3W - Managing Storage (Windows)

3.2.7 移动文件到/logfiles/archive/位置

aws s3 mv s3://s3-bucket-edward/logfiles/<file-name> s3://s3-bucket-edward/logfiles/archive/<file-name>

3.2.8 检查是否移动到该位置

aws s3 ls s3://s3-bucket-edward/logfiles/

4 同步文件(从Processor实例到S3存储桶)

4.1 下载sample文件,并解压缩

(New-Object System.Net.WebClient).DownloadFile("https://d2lrzjb0vjvpn5.cloudfront.net/sys-ops/v2.4/lab-3-storage-windows/static/files.zip", "c:\temp\files.zip")

4.2 在该存储桶上开启版本控制

aws s3api put-bucket-versioning --bucket s3-bucket-edward --versioning-configuration Status=Enabled

4.3 同步文件到S3存储桶

aws s3 sync files s3://s3-bucket-edward/files/

4.4 删除file1.txt

del files\file1.txt

4.5 同步文件,删除掉源目录中没有的文件

aws s3 sync files s3://s3-bucket-edward/files/ --delete

4.6 确认文件已从S3存储桶中删除

aws s3 ls s3://s3-bucket-edward/files/

4.7 列出S3存储桶中file1.txt的各个版本

aws s3api list-object-versions --bucket s3-bucket-edward --prefix files/file1.txt

4.8 还原上个版本中的file1.txt到本地系统

aws s3api get-object --bucket s3-bucket-edward --key files/file1.txt --version-id <version-id> files/file1.txt

4.9 确认文件已还原到本地

dir files

4.10 重新同步文件到S3存储桶

aws s3 sync files s3://s3-bucket-edward/files/

4.11 确认该文件已经被还原到S3存储桶

aws s3 ls s3://s3-bucket-edward/files/
上一篇:ios之极光推送消息收到以后对消息的处理总结


下一篇:C#多线程实践——锁和线程安全