ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

s3cmd sync命令常用选项说明

2022-04-08 00:33:25  阅读:545  来源: 互联网

标签:选项 -- bucket sync s3cmd s3 backup


1. s3cmd sync命令常用选项说明

  • --list-md5:结合list一起使用,打印md5
  • -H, --human-readable-sizes:人性化文件大小
  • -v, --verbose:显示详细的输出
  • -d, --debug:调试信息
  • --limit-rate=LIMITRATE:将上传或下载速度限制为每秒字节数。 数量可以用字节、k 后缀的千字节或 m 后缀的兆字节表示。
  • -n, --dry-run:只显示应该上传或下载的内容,但实际上并不这样做。 仍可能执行 S3 请求以获取存储桶列表和其他信息(仅适用于文件传输命令)
  • --skip-existing:跳过存在于目的地的文件(仅适用于 [get] 和 [sync] 命令)。请谨慎使用此选项!
  • --delete-removed:删除没有对应源文件的目标对象 [sync]。请谨慎使用此选项!
  • -p, --preserve:保留文件系统属性(模式、所有权、时间戳)。 [sync] 命令的默认值。
  • -q, --quiet:不输出信息到标准输出。

文件同步相关:

  • --exclude=GLOB:通配
  • --exclude-from=FILE:从文件读取排除列表
  • --rexclude=REGEXP:正则形式的匹配排除
  • --rexclude-from=FILE:从文件读取正则形式的匹配排除
  • --include=GLOB:通配
  • --include-from=FILE:从文件读取文件列表
  • --rinclude=REGEXP:正则匹配
  • --rinclude-from=FILE:从文件读取正则匹配

ACL:

$ s3cmd modify s3://files/link.png --acl-private
$ s3cmd modify s3://files/link.png --acl-public

生命周期:

# 设置文件1天后过期
$ s3cmd modify s3://testabc/sqr.py --add-header x-delete-after:1

2. 安装s3cmd

$ pip install s3cmd
# 或:
$ yum install python-s3cmd
# 或:
$ yum install s3cmd
推荐版本2.0.1+,2.0.0版本上传大文件时有Bug。

3. 配置s3cmd

执行 s3cmd --configure 生成配置文件,一路Enter,注意跳过认证并保存配置。
......
...
Test access with supplied credentials? [Y/n] n

Save settings? [y/N] y
Configuration saved to '/root/.s3cfg'
修改一下几项:
$ vim /root/.s3cfg
access_key = <access_key>
secret_key = <secret_key>
bucket_location = <region>
host_base = <endpoint>
host_bucket = <endpoint>
use_https = False
human_readable_sizes = True
website_index = index.html
signature_v2 = True
  • 其中,access_key和secret_key是在本地创建S3用户时获得。
  • host_base是S3服务所使用的ip地址(包括端口号)。
  • host_bucket为S3用户下的一个bucket(可在配置之后再创建,但该字段不能为空)。
s3cmd 2.2.0(最新版),在某些不兼容v4的情况下,需要使用signature_v2,否则会发起两次签名重试请求。

4. 例子

      One of the most powerful commands of s3cmd is s3cmd sync used for synchronising complete directory trees to or from
       remote S3 storage. To some extent s3cmd put and s3cmd get share a similar behaviour with sync.

       Basic usage common in backup scenarios is as simple as:
            s3cmd sync /local/path/ s3://test-bucket/backup/

       This  command  will  find  all  files  under  /local/path  directory  and  copy  them  to corresponding paths under
       s3://test-bucket/backup on the remote side.  For example:
            /local/path/file1.ext         ->  s3://bucket/backup/file1.ext
            /local/path/dir123/file2.bin  ->  s3://bucket/backup/dir123/file2.bin

       However if the local path doesn't end with a slash the last directory's name is used on the remote  side  as  well.
       Compare these with the previous example:
            s3cmd sync /local/path s3://test-bucket/backup/
       will sync:
            /local/path/file1.ext         ->  s3://bucket/backup/path/file1.ext
            /local/path/dir123/file2.bin  ->  s3://bucket/backup/path/dir123/file2.bin

       To retrieve the files back from S3 use inverted syntax:
            s3cmd sync s3://test-bucket/backup/ ~/restore/
       that will download files:
            s3://bucket/backup/file1.ext         ->  ~/restore/file1.ext
            s3://bucket/backup/dir123/file2.bin  ->  ~/restore/dir123/file2.bin

       Without the trailing slash on source the behaviour is similar to what has been demonstrated with upload:
            s3cmd sync s3://test-bucket/backup ~/restore/
       will download the files as:
            s3://bucket/backup/file1.ext         ->  ~/restore/backup/file1.ext
            s3://bucket/backup/dir123/file2.bin  ->  ~/restore/backup/dir123/file2.bin

5. 使用注意事项

  • 上传大文件时,使用 --multipart-chunk-size-mb=size 指定的分片大小必须是4的倍数,否则上传会报 400(InvalidPartOrder)。
 

标签:选项,--,bucket,sync,s3cmd,s3,backup
来源: https://www.cnblogs.com/varden/p/16115012.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有