我注意到似乎没有从AWS管理控制台下载整个s3桶的选项。
有什么简单的方法可以把所有东西都装进我的桶里吗?我正在考虑使根文件夹公共,使用wget抓取它,然后再次使它私有,但我不知道是否有更简单的方法。
我注意到似乎没有从AWS管理控制台下载整个s3桶的选项。
有什么简单的方法可以把所有东西都装进我的桶里吗?我正在考虑使根文件夹公共,使用wget抓取它,然后再次使它私有,但我不知道是否有更简单的方法。
当前回答
您可以使用MinIO客户端执行以下操作:mc cp -r https://s3-us-west-2.amazonaws.com/bucketName/ localdir
MinIO还支持会话、断点续传下载、上传等等。MinIO支持Linux、OS X和Windows操作系统。它是用Golang编写的,在Apache Version 2.0下发布。
其他回答
我已经为S3做了一些开发,我还没有找到一个简单的方法来下载整个存储桶。
如果您想用Java编写代码,那么jets3t库很容易用于创建存储桶列表并遍历该列表以下载它们。
首先,从AWS管理咨询器获取一个公共私钥集,这样您就可以创建一个S3service对象:
AWSCredentials awsCredentials = new AWSCredentials(YourAccessKey, YourAwsSecretKey);
s3Service = new RestS3Service(awsCredentials);
然后,获取bucket对象的数组:
S3Object[] objects = s3Service.listObjects(YourBucketNameString);
最后,遍历该数组,每次下载一个对象:
S3Object obj = s3Service.getObject(bucket, fileName);
file = obj.getDataInputStream();
我把连接代码放在线程安全的单例中。由于显而易见的原因,省略了必要的try/catch语法。
如果你更愿意用Python编写代码,你可以使用Boto。
在查看BucketExplorer之后,“下载整个桶”可能会满足你的需要。
使用awscli下载/上传文件到s3总是更好。同步将帮助您恢复没有任何麻烦。
aws s3 sync s3://bucketname/ .
正如@layke所说,从S3 cli下载文件是最好的做法,这是安全的。但在某些情况下,人们需要使用wget来下载文件,下面是解决方案
aws s3 presign s3://<your_bucket_name/>
这将presign将为您提供临时公共URL,您可以使用presign_url从S3下载内容,在您的情况下使用wget或任何其他下载客户端。
这里有一些东西可以下载所有桶,列出它们,列出它们的内容。
//connection string
private static void dBConnection() {
app.setAwsCredentials(CONST.getAccessKey(), CONST.getSecretKey());
conn = new AmazonS3Client(app.getAwsCredentials());
app.setListOfBuckets(conn.listBuckets());
System.out.println(CONST.getConnectionSuccessfullMessage());
}
private static void downloadBucket() {
do {
for (S3ObjectSummary objectSummary : app.getS3Object().getObjectSummaries()) {
app.setBucketKey(objectSummary.getKey());
app.setBucketName(objectSummary.getBucketName());
if(objectSummary.getKey().contains(CONST.getDesiredKey())){
//DOWNLOAD
try
{
s3Client = new AmazonS3Client(new ProfileCredentialsProvider());
s3Client.getObject(
new GetObjectRequest(app.getBucketName(),app.getBucketKey()),
new File(app.getDownloadedBucket())
);
} catch (IOException e) {
e.printStackTrace();
}
do
{
if(app.getBackUpExist() == true){
System.out.println("Converting back up file");
app.setCurrentPacsId(objectSummary.getKey());
passIn = app.getDataBaseFile();
CONVERT= new DataConversion(passIn);
System.out.println(CONST.getFileDownloadedMessage());
}
}
while(app.getObjectExist()==true);
if(app.getObjectExist()== false)
{
app.setNoObjectFound(true);
}
}
}
app.setS3Object(conn.listNextBatchOfObjects(app.getS3Object()));
}
while (app.getS3Object().isTruncated());
}
/---------------------------- 扩展方法 -------------------------------------/
//Unzip bucket after download
public static void unzipBucket() throws IOException {
unzip = new UnZipBuckets();
unzip.unZipIt(app.getDownloadedBucket());
System.out.println(CONST.getFileUnzippedMessage());
}
//list all S3 buckets
public static void listAllBuckets(){
for (Bucket bucket : app.getListOfBuckets()) {
String bucketName = bucket.getName();
System.out.println(bucketName + "\t" + StringUtils.fromDate(bucket.getCreationDate()));
}
}
//Get the contents from the auto back up bucket
public static void listAllBucketContents(){
do {
for (S3ObjectSummary objectSummary : app.getS3Object().getObjectSummaries()) {
if(objectSummary.getKey().contains(CONST.getDesiredKey())){
System.out.println(objectSummary.getKey() + "\t" + objectSummary.getSize() + "\t" + StringUtils.fromDate(objectSummary.getLastModified()));
app.setBackUpCount(app.getBackUpCount() + 1);
}
}
app.setS3Object(conn.listNextBatchOfObjects(app.getS3Object()));
}
while (app.getS3Object().isTruncated());
System.out.println("There are a total of : " + app.getBackUpCount() + " buckets.");
}
}
您有许多选项可以做到这一点,但最好的是使用AWS CLI。
下面是一篇简介:
Download and install AWS CLI in your machine: Install the AWS CLI using the MSI Installer (Windows). Install the AWS CLI using the Bundled Installer for Linux, OS X, or Unix. Configure AWS CLI: Make sure you input valid access and secret keys, which you received when you created the account. Sync the S3 bucket using: aws s3 sync s3://yourbucket /local/path In the above command, replace the following fields: yourbucket >> your S3 bucket that you want to download. /local/path >> path in your local system where you want to download all the files.