aws cli s3 同步,排除不工作

Mud*_*sin 5 amazon-s3 amazon-web-services aws-cli

我正在尝试使用排除选项将数据从 ec2 同步到 s3 存储桶

root@ir:ls /data/
f1 f2 f3 
root@ir:aws s3 sync /data/ s3://data/ --profile s3to --exclude "/data/f1/*"
root@ir:aws s3 sync /data/ s3://data/ --profile s3to --exclude "/data/f1/"
root@ir:aws s3 sync /data/ s3://data/ --profile s3to --exclude "/data/f1*"
root@ir:aws s3 sync /data/ s3://data/ --profile s3to --exclude "f1/*"

root@ir:aws --version
aws-cli/1.9.15 Python/2.7.6 Linux/3.13.0-48-generic botocore/1.3.15
Run Code Online (Sandbox Code Playgroud)

但是以上选项都不起作用,f1 继续同步到 S3 存储桶。

Met*_*urf 9

没有一个答案明确说明为什么--exclude参数似乎不起作用。

为什么

--exclude使用正在同步的目录的相对路径。

例如,以下命令会失败,因为该sync命令正在同步/data/目录,并且--exclude参数是绝对路径。

aws s3 sync /data/ s3://data/ --exclude "/data/f1/*"
Run Code Online (Sandbox Code Playgroud)

解决方案是使用从正在同步的文件夹到通过--exclude参数排除的文件夹的相对路径:

aws s3 sync /data/ s3://data/ --exclude "f1/*"
Run Code Online (Sandbox Code Playgroud)

注意差异

   Fails: --exclude "/data/f1/*"
Succeeds: --exclude "f1/*"
Run Code Online (Sandbox Code Playgroud)


Fré*_*nri 3

你能试一下吗

aws s3 sync /data/ s3://data/ --profile s3to --exclude "*f1/*"
Run Code Online (Sandbox Code Playgroud)