19

S3cmd的安装使用以及出错解决

 2 years ago
source link: http://www.hn-seo.com/seo_1386.shtml
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

一,安装s3cmd
咱们的环境是centos6 64位参照http://s3tools.org/repositories可以知道,通过命令可以直接安装

yum --enablerepo epel-testing install s3cmd

二,配置s3cmd
配置,主要是 Access Key ID 和 Secret Access Key

s3cmd --configure

然后根据提示输入Access Key ID 和 Secret Access Key,其他的选项直接回车忽略.最后确定测试,如果测试成功,即保存配置文件即可。
错误1:

ERROR: Test failed: 403 (RequestTimeTooSkewed): The difference between the request time and the current time is too large

这个一般是,时区出了问题。一般情况下只需要执行:

/usr/sbin/ntpdate us.pool.ntp.org

或者

/usr/sbin/ntpdate ntp.api.bz

如果还是不行:

cat /etc/sysconfig/clock
cd /usr/share/zoneinfo
rm /etc/localtime
ln -s /usr/share/zoneinfo/America/New_York /etc/localtime

再执行前面的即可。
错误2:

ERROR: Test failed: [Errno -3] Temporary failure in name resolution

这个错误是dns文件有问题,只要把/etc/resolv.conf这个文件原来的内容注释掉,修改为谷歌的dns即可:

nameserver 8.8.8.8
nameserver 8.8.4.4

到此基本错误解决,再运行一下命令:s3cmd –configure之前有输入了key这次只要不停的回车,最后测试的时候yes.反馈测试成功了。
三,s3cmd详细相关命令
1、列举所有 Buckets。(bucket 相当于根文件夹)

s3cmd ls

2、创建 bucket,且 bucket 名称是唯一的,不能重复。

s3cmd mb s3://my-bucket-name

3、删除空 bucket

s3cmd rb s3://my-bucket-name

4、列举 Bucket 中的内容

s3cmd ls s3://my-bucket-name

5、上传 file.txt 到某个 bucket,

s3cmd put file.txt s3://my-bucket-name/file.txt

6、上传并将权限设置为所有人可读

s3cmd put --acl-public file.txt s3://my-bucket-name/file.txt

7、批量上传文件

s3cmd put ./* s3://my-bucket-name/

8、下载文件

s3cmd get s3://my-bucket-name/file.txt file.txt

9、批量下载

s3cmd get s3://my-bucket-name/* ./

10、删除文件

s3cmd del s3://my-bucket-name/file.txt

11、来获得对应的bucket所占用的空间大小

s3cmd du -H s3://my-bucket-name

目录处理规则
以下命令都能将dir1 中的文件上传至my-bucket-name,但效果只截然不同的。
1)dir1 不带”/”斜杠,那么dir1会作为文件路径的一部分,相当于上传整个dir1目录,即类似 “cp -r dir1/”

s3cmd put -r dir1 s3://my-bucket-name/

dir1/file1-1.txt -> s3://my-bucket-name/dir1/file1-1.txt
2)带”/”斜杠的 dir1,相当于上传dir1目录下的所有文件,即类似 “cp ./* ”

s3cmd put -r dir1/ s3://my-bucket-name/

dir1/file1-1.txt -> s3://my-bucket-name/file1-1.txt
四、同步方法
这是s3cmd 使用难点,但却是最实用的功能。官方使用说明见《s3cmd sync HowTo
首先明确,同步操作是要进行MD5校验的,只有当文件不同时,才会被传输。
4.1、常规同步操作
1、同步当前目录下所有文件

s3cmd sync  ./  s3://my-bucket-name/

2、加 “–dry-run”参数后,仅列出需要同步的项目,不实际进行同步。

s3cmd sync  --dry-run ./  s3://my-bucket-name/

3、加 ” –delete-removed”参数后,会删除本地不存在的文件。

s3cmd sync  --delete-removed ./  s3://my-bucket-name/

4、加 ” –skip-existing”参数后,不进行MD5校验,直接跳过本地已存在的文件。

s3cmd sync  --skip-existing ./  s3://my-bucket-name/

4.2、高级同步操作
4.2.1、排除、包含规则(–exclude 、–include)
file1-1.txt被排除,file2-2.txt同样是txt格式却能被包含。

s3cmd sync --dry-run --exclude '*.txt' --include 'dir2/*' ./  s3://my-bucket-name/

exclude: dir1/file1-1.txt
upload: ./dir2/file2-2.txt -> s3://my-bucket-name/dir2/file2-2.txt
4.2.2、从文件中载入排除或包含规则。(–exclude-from、–include-from)

s3cmd sync  --exclude-from pictures.exclude ./  s3://my-bucket-name/

pictures.exclude 文件内容
# Hey, comments are allowed here
*.jpg
*.gif
4.2.3、排除或包含规则支持正则表达式
–rexclude 、–rinclude、–rexclude-from、–rinclude-from

广告位 
分享到: 0

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK