s3cmd用法總結


概述

S3是亞馬遜AWS提供的簡單存儲服務(可以理解為有公網域名的大容量高可用存儲)
S3配合CloudFront服務可作為CDN使用,它提供多節點全球發布

安裝

方法一:

yum install s3cmd

方法二:

yum install -y python-pip (python > version2.6)
pip install s3cmd

配置:

s3cmd --configure

#vim /root/.s3cfg

s3cmd相關指令

創建新Bucket:

s3cmd mb s3://mybucket

list當前bucket:

s3cmd ls

列出bucket中的文件:

s3cmd --recursive ls s3://mybucket2    #--recursive 遞歸列舉
s3cmd --recursive ls s3://mybucket2/rgw  

文件上傳:

s3cmd  put demo.xml  s3://mybucket2/demo.xml
#上傳目錄
s3cmd put --recursive dir1 dir2  s3://mybucket2/dir1  #目標目錄不用提前創建,上傳時會自動創建

文件下載:

s3cmd get s3://mybucket2/demo.xml demo2.xml
#下載目錄
s3cmd get --recursive s3://mybucket2/dir1

#帶目錄樹下載
s3cmd get --recursive s3://mybucket2/dir1/*

刪除:

s3cmd del s3://mybucket2/demo.xml
s3cmd del --recursive s3://mybucket2/dir1/  #整個目錄樹  

刪除bucket:

s3cmd rb  s3://mybucket2  # bucket 必須為empty,否則需要帶--force 強制刪除

同步:

s3cmd sync ./ s3://mybucket2  #同步當前目錄下所有文件
s3cmd sync --delete-removed ./ s3://mybucket2   # 會刪除本地不存在的文件
s3cmd sync --skip-existing ./ s3://mybucket2    # 不進行MD5校驗,直接跳過本地已存在的文件

高級同步操作

  • 排除、包含規則(- -exclude 、- -include)

    s3cmd sync --exclude '.doc' --include 'dir2/' ./ s3://mybucket2/

  • 從文件中載入排除或包含規則。(- -exclude-from、- -include-from)

    s3cmd sync --exclude-from exclude.txt ./ s3://mybucket2/

    exclude.txt 文件內容:

    #comments here

    *.jpg

    *.gif

  • 排除或包含規則支持正則表達式

    --rexclude 、--rinclude、--rexclude-from、--rinclude-from


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM