Amazon Simple Storage Solution (Amazon S3)允许您将(Amazon Simple Storage Solution (Amazon S3))Windows Server中的数据备份到其海量云存储上。备份数据至关重要,因为它可以防止在发生意外事件时丢失数据。
将Windows Server 自动(Automate Windows Server)备份到Amazon S3
在本教程中,我将向您展示如何自动化备份过程,使其每天、每周或每月运行一次。操作很简单,但您必须严格遵循指南以避免并发症。
安装亚马逊 AWS CLI
自动化您的Amazon AWS(Amazon AWS)备份的第一步是安装AWS CLI。您可以在此页面上找到有关安装(this page)AWS CLI版本 1 和 2的详细说明。
完成安装后,您现在必须配置默认用户配置文件、访问 ID 和密钥。为此,请运行以下命令:
aws configure
AWS Access Key ID [None]: <AccessID>
AWS Secret Access Key [None]: secretkey
Default region name [None]: us-east-1
Default output format [None]: json
关于 Amazon S3 命令
您必须在 s3 命令中指定路径参数。对于这些路径,您可以使用S3 Uri,这是您的 S3 存储桶的URI ,也可以使用localpath(本地目录)。例如,您可以使用以下命令:
localpath - C://Desktop/backups
S3URI: - s3://yourbucket/yourkey
因此,完整的 S3 操作可以采用以下形式:
aws s3 s3command souce_file/folder destinationpath
操作从 localpath到S3URI, 从S3URI到 S3URI, 从S3URI 到 localpath。
要将名为samplefile.txt(samplefile.txt)的示例文件复制 到名为sample-bucket 的存储桶(sample-bucket)中,您可以使用以下 S3 命令:
aws s3 cp "C://Desktop/backups/samplefile.txt" s3://sample-bucket
在上面的命令中,我们没有选择区域。这是因为我们已经在 aws configure中完成了该操作。–region标志用于指定存储桶的区域。
要将 备份(backups)文件夹中的所有内容复制到sample-bucket存储桶,请运行以下命令:
aws s3 sync "C://Desktop/backups/" s3://sample-bucket
要使用上述 S3 命令,请注意以下几点:
- 本地文件不能存在于所选存储桶和前缀中。
- 确保 S3 对象的大小与本地文件的大小不同。
- S3 对象的最新修改必须早于本地文件的修改。
在 S3 命令中使用过滤器标志的提示
您在 S3 命令中使用的过滤器标志包括 –exclude和 –include标志。您可以在一个命令中多次使用它们。
-- include
:这会在 S3 命令之后添加选定的文件夹或文件。-- exclude
:这会在 S3 命令之后删除选定的文件夹或文件。
以下(Below)是使用上述过滤器的示例:
aws s3 sync "C://Desktop/backups/" s3://sample-bucket --exclude "*" --include "*.jpg" --include "*.png" --include "*.txt"
要排除名为 backups的文件夹中的每个文件并包含此文件夹中扩展名为 jpg、png 和 text(jpg, png, and text)的所有文件,请运行以下命令。
在这里,我们还借助--dryrun
标志测试了我们的设置:
aws s3 sync "C://Desktop/backups/" s3://sample-bucket "*" --include "*.jpg" --include "*.png" --include "*.txt" --dryrun
注意: (NOTE: )如果没有这些标志,系统会在 S3 操作中包含每个文件。此外,应用最后一个过滤器。
如何使用批处理文件创建Amazon S3备份
1]创建批处理文件
启动记事本(Notepad),以便它打开一个空白的.txt文件。
输入(Enter)以下 S3 命令以将备份文件夹同步到您的 S3 存储桶:
aws s3 sync "C://Desktop/backups/" s3://your-bucket
使用.bat(.bat)扩展名保存 txt 文件 ,使其成为批处理文件。
2]在任务计划程序中(Task Scheduler)创建(Create)一个新任务
按(Press)Windows键并搜索 任务计划程序(task scheduler)。
从结果中选择 任务计划程序(Task Scheduler)。
在任务计划程序中,单击 操作(Actions)并选择创建任务(Create Task)。插入任务名称并编写描述。
为一次、每天、每周或每月添加一个触发器。
3]添加动作
切换到 操作(Actions)选项卡并从下拉菜单中选择以下操作:启动程序(Start a program)。
在 Program/script框中,浏览新创建的批处理文件。
保存新创建的任务。
我希望你觉得这个教程很容易理解。
How to automate Windows Server backup to Amazon S3
Amazon Simple Storage Solution (Amazon S3) allows you to back up data from your Windows Server on its massive cloud storage. Backing up your data is crucial, as it prevents data loss in the event of unexpected events.
Automate Windows Server backup to Amazon S3
In this tutorial, I’ll show you how to automate the backup process to run once, daily, weekly, or monthly. The operation is straightforward, but you have to follow the guide closely to avoid complications.
Install the Amazon AWS CLI
The first step for automating your Amazon AWS backups is to install the AWS CLI. You can find detailed instructions for installing the AWS CLI version 1 and 2 on this page.
When you complete the installation, you now have to configure the default user profiles, access ID, and key. To do this, run the command below:
aws configure
AWS Access Key ID [None]: <AccessID>
AWS Secret Access Key [None]: secretkey
Default region name [None]: us-east-1
Default output format [None]: json
About Amazon S3 commands
You have to specify a path argument in s3 commands. For these paths, you may use either an S3 Uri, which is your S3 bucket’s URI or utilize a localpath (the local directory). For example, you can use the following commands:
localpath - C://Desktop/backups
S3URI: - s3://yourbucket/yourkey
The complete S3 operation can therefore take the following form:
aws s3 s3command souce_file/folder destinationpath
The operation goes from the localpath to S3URI, S3URI to S3URI, and S3URI to localpath.
To copy an example file called samplefile.txt to your bucket called sample-bucket, you can use the S3 command below:
aws s3 cp "C://Desktop/backups/samplefile.txt" s3://sample-bucket
In the above command, we didn’t choose a region. This is because we’ve already done that in the aws configure. The –region flag is used to specify your bucket’s region.
To copy everything in the backups folder to the sample-bucket bucket, run the command that follows:
aws s3 sync "C://Desktop/backups/" s3://sample-bucket
To use the above S3 command, take note of the following:
- The local file mustn’t exist in the chosen bucket and prefix.
- Ensure that the size of the S3 object is different from that of the local file.
- The most recent modification of the S3 object must be older than that of the local file.
Tips for using filter flags in S3 commands
The filter flags that you use in S3 commands include the –exclude and –include flags. You can make use of them several times in one command.
-- include
: This adds chosen folders or files following an S3 command.-- exclude
: This gets rid of chosen folders or files following an S3 command.
Below is an example of the above filters in use:
aws s3 sync "C://Desktop/backups/" s3://sample-bucket --exclude "*" --include "*.jpg" --include "*.png" --include "*.txt"
To exclude every file in a folder named backups and include all the files in this folder that have the extensions jpg, png, and text, run the command below.
Here, we also tested our settings with the help of the --dryrun
flag:
aws s3 sync "C://Desktop/backups/" s3://sample-bucket "*" --include "*.jpg" --include "*.png" --include "*.txt" --dryrun
NOTE: Without the flags, the system includes every file in S3 operations. Also, the last filter is applied.
How to create Amazon S3 backups using batch files
1] Create the batch file
Launch Notepad so that it opens a blank .txt file.
Enter the following S3 command for synchronizing the backups folders to your S3 bucket:
aws s3 sync "C://Desktop/backups/" s3://your-bucket
Save the txt file with the .bat extension, which makes it a batch file.
2] Create a new task in Task Scheduler
Press the Windows key and search for task scheduler.
Select the Task Scheduler from the results.
In Task Scheduler, click on Actions and select Create Task. Insert a task name and write a description.
Add a trigger for either one time, daily, weekly, or monthly.
3] Add action
Switch to the Actions tab and select the following action from the dropdown menu: Start a program.
In the Program/script box, browse for the newly created batch file.
Save the newly created task.
I hope you find this tutorial easy to understand.