mac安裝s3命令客戶端(4)
下面的示例對上一示例進行了擴展,顯示了其工作方式。// Delete local file
$ rm ./MyFile1.txt
// Attempt sync without --delete option - nothing happens
$ aws s3 sync . s3://my-bucket/path
// Sync with deletion - object is deleted from bucket
$ aws s3 sync . s3://my-bucket/path --delete
delete: s3://my-bucket/path/MyFile1.txt
// Delete object from bucket
$ aws s3 rm s3://my-bucket/path/MySubdirectory/MyFile3.txt
delete: s3://my-bucket/path/MySubdirectory/MyFile3.txt
// Sync with deletion - local file is deleted
$ aws s3 sync s3://my-bucket/path . --delete
delete: MySubdirectory\MyFile3.txt
// Sync with Infrequent Access storage class
$ aws s3 sync . s3://my-bucket/path --storage-class STANDARD_IA
使用 --exclude 和 --include 選項可以指定規則來篩選要在同步操作期間復制的文件或對象。默認情況下,指定目錄中的所有項都包含在同步中。因此,僅當指定 --exclude 選項的例外情況(例如,–include 實際上意味著“不排除”)時才需要使用 --include。這些選項按指定順序應用,如下例所示。
Local directory contains 3 files:
MyFile1.txt
MyFile2.rtf
MyFile88.txt
'''
$ aws s3 sync . s3://my-bucket/path --exclude '*.txt'
upload: MyFile2.rtf to s3://my-bucket/path/MyFile2.rtf
'''
$ aws s3 sync . s3://my-bucket/path --exclude '*.txt' --include 'MyFile*.txt'
upload: MyFile1.txt to s3://my-bucket/path/MyFile1.txt
upload: MyFile88.txt to s3://my-bucket/path/MyFile88.txt
upload: MyFile2.rtf to s3://my-bucket/path/MyFile2.rtf
'''
$ aws s3 sync . s3://my-bucket/path --exclude '*.txt' --include 'MyFile*.txt' --exclude 'MyFile?.txt'
upload: MyFile2.rtf to s3://my-bucket/path/MyFile2.rtf
upload: MyFile88.txt to s3://my-bucket/path/MyFile88.txt
–exclude 和 --include 選項也可以與 --delete 選項一起使用來篩選要在同步操作期間刪除的文件或對象。在這種情況下,參數字符串必須指定要在目標目錄或存儲桶上下文中包含或排除在刪除操作中的文件。下面是一個示例。
Assume local directory and s3://my-bucket/path currently in sync and each contains 3 files:
MyFile1.txt
MyFile2.rtf
MyFile88.txt
'''
// Delete local .txt files
$ rm *.txt
// Sync with delete, excluding files that match a pattern. MyFile88.txt is deleted, while remote MyFile1.txt is not.
$ aws s3 sync . s3://my-bucket/path --delete --exclude 'my-bucket/path/MyFile?.txt'
delete: s3://my-bucket/path/MyFile88.txt
'''
// Delete MyFile2.rtf
$ aws s3 rm s3://my-bucket/path/MyFile2.rtf
// Sync with delete, excluding MyFile2.rtf - local file is NOT deleted
$ aws s3 sync s3://my-bucket/path . --delete --exclude './MyFile2.rtf'
download: s3://my-bucket/path/MyFile1.txt to MyFile1.txt
'''
// Sync with delete, local copy of MyFile2.rtf is deleted
$ aws s3 sync s3://my-bucket/path . --delete
delete: MyFile2.rtf
sync 命令還可以接受 --acl 選項,使用該選項可以設置對復制到 Amazon S3 中的文件的訪問權限。該選項接受 private、public-read 和 public-read-write 值。
$ aws s3 sync . s3://my-bucket/path --acl public-read
頁:
[1]