s3cmd藉助split分批實現檔案同步備份

來源:互聯網
上載者:User

s3cmd藉助split分批實現檔案同步備份 一直都在使用s3cmd工具對伺服器進行同步備份,可是最近卻出了點小問題,查證之後,發現是伺服器檔案打包後越來越大,達到了7G左右,導致s3cmd無法將其上傳至amazon雲端;解決辦法就是需要將打包的檔案藉助split先進行切割,在進行上傳;命令大致如下:[plain] tar -zcvf - db_backup.sql webserver/ | openssl des3 -salt -k password | split -b 1024m - mybackup.des3_   這樣,一個7.2G左右的檔案,按照1G的大小切割,得到了7個1G的檔案和一個0.2G的檔案,然後在逐個使用s3cmd進行上傳;[plain] for filename in `ls mybackup.des3_*`  do      s3cmd -v put $filename s3://mybackup/$filename  done   上傳完之後,在AWS上對各個檔案使用cat進行整合;[plain] cat mybackup.des3_* > mybackup.des3   關於s3cmd的安裝使用,做一下備忘:一、安裝方法 方法一:(Debian/Ubuntu )[plain] wget -O- -q http://s3tools.org/repo/deb-all/stable/s3tools.key | sudo apt-key add -  wget -O/etc/apt/sources.list.d/s3tools.list http://s3tools.org/repo/deb-all/stable/s3tools.list  apt-get update && sudo apt-get install s3cmd   方法二:[plain] wget http://nchc.dl.sourceforge.net/project/s3tools/s3cmd/1.0.0/s3cmd-1.0.0.tar.gz  tar -zxf s3cmd-1.0.0.tar.gz -C /usr/local/  mv /usr/local/s3cmd-1.0.0/ /usr/local/s3cmd/  ln -s /usr/local/s3cmd/s3cmd /usr/bin/s3cmd   二、使用方法 1、配置,主要是 Access Key ID 和 Secret Access Key    s3cmd --configure 2、列舉所有 Buckets。(bucket 相當於根資料夾)    s3cmd ls 3、建立 bucket,且 bucket 名稱是唯一的,不能重複。    s3cmd mb s3://my-bucket-name 4、刪除空 bucket    s3cmd rb s3://my-bucket-name 5、列舉 Bucket 中的內容    s3cmd ls s3://my-bucket-name 6、上傳 file.txt 到某個 bucket,    s3cmd put file.txt s3://my-bucket-name/file.txt 7、上傳並將使用權限設定為所有人可讀    s3cmd put --acl-public file.txt s3://my-bucket-name/file.txt 8、批量上傳檔案    s3cmd put ./* s3://my-bucket-name/ 9、下載檔案    s3cmd get s3://my-bucket-name/file.txt file.txt 10、批量下載    s3cmd get s3://my-bucket-name/* ./ 11、刪除檔案    s3cmd del s3://my-bucket-name/file.txt 12、來獲得對應的bucket所佔用的空間大小    s3cmd du -H s3://my-bucket-name 三、目錄處理規則 以下命令都能將dir1 中的檔案上傳至my-bucket-name,但效果只截然不同的。 1)dir1 不帶"/"斜杠,那麼dir1會作為檔案路徑的一部分,相當於上傳整個dir1目錄,即類似 "cp -r dir1/"[plain] ~/demo$ s3cmd put -r dir1 s3://my-bucket-name/  dir1/file1-1.txt -> s3://my-bucket-name/dir1/file1-1.txt  [1 of 1]   2)帶"/"斜杠的 dir1,相當於上傳dir1目錄下的所有檔案,即類似 "cp ./* "~/demo$ s3cmd put -r dir1/ s3://my-bucket-name/dir1/file1-1.txt -> s3://my-bucket-name/file1-1.txt  [1 of 1] 四、同步方法 這是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格式卻能被包含。[plain] ~/demo$ 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、排除或包含規則支援Regex    --rexclude 、--rinclude、--rexclude-from、--rinclude-from

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.