Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

amazon s3 - Download/Copy tar.gz File from S3 to EC2

When I download a tar.gz file from AWS S3, and then I try to untar it, I am getting the following error:

tar -xzvf filename_backup_jan212021_01.tar.gz

gzip: stdin: not in gzip format

tar: Child returned status 1
tar: Error is not recoverable: exiting now

When I check what type of file it is, I get this:

file filename_backup_jan212021_01.tar.gz
filename_backup_jan212021_01.tar.gz: ASCII text

This is the command I am using to copy the file from S3 to my EC2:

aws s3 cp s3://bucket_name/filename_backup_jan212021_01.tar.gz .

Please, help me find a solution to extract a tar.gz file after downloading it from AWS S3.

question from:https://stackoverflow.com/questions/65828987/download-copy-tar-gz-file-from-s3-to-ec2

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
tar -xzvf filename_backup_jan212021_01.tar.gz

gzip: stdin: not in gzip format
file filename_backup_jan212021_01.tar.gz
filename_backup_jan212021_01.tar.gz: ASCII text

cat filename_backup_jan212021_01.tar.gz

/home/ec2-user/file_delete_01.txt
/home/ec2-user/file_jan2021.txt
/home/ec2-user/filename_backup_jan1.tar.gz
/home/ec2-user/filename_backup_jan1.txt
/home/ec2-user/filename_backup_jan2.tar.gz
/home/ec2-user/filename_backup_jan3.tar.gz

All of these indicate that the file that was uploaded to S3 itself is not gzip'd tar file, rather just a plain text file uploaded with a .tar.gz filename. While filenames and extensions are used to indicate content type to humans, computers think otherwise :)

You can create the file with

tar cvzf <archive name> </path/to/files/to/be/tarred> && aws s3 cp <bucket path> <archive name>

to create the archive and upload it to S3, and use the commands you mention in the question to download them. Of course replace the placeholders with the proper names and such


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...