S3 Client 的安裝與使用


原文:https://www.howtoing.com/install-s3cmd-manage-amazon-s3-buckets

 

摘要:

安裝s3cmd包

s3cmd是默認的RPM庫針對CentOS,RHEL和Ubuntu系統上可用,您可以簡單的在系統上執行以下命令進行安裝。

在CentOS / RHEL:
# yum install s3cmd
在Ubuntu / Debian:
$ sudo apt-get install s3cmd
在SUSE Linux Enterprise Server 11:
# zypper addrepo http://s3tools.org/repo/SLE_11/s3tools.repo # zypper install s3cmd
使用Source安裝最新s3cmd

如果使用上述軟件包管理器s3cmd,你沒有得到最新的版本,可以使用源代碼,在系統上安裝最新的s3cmd版本。訪問此網址或者使用下面的命令來下載最新版本的s3cmd。

$ wget http://ufpr.dl.sourceforge.net/project/s3tools/s3cmd/1.6.1/s3cmd-1.6.1.tar.gz $ tar xzf s3cmd-1.6.1.tar.gz

現在,使用下面的命令與源文件進行安裝。

$ cd s3cmd-1.6.1 $ sudo python setup.py install
配置s3cmd環境

為了配置s3cmd我們將要求有您S3 Amazon帳戶訪問key和鑰匙。獲取安全密鑰AWS securityCredentials 。將提示登錄到您的Amazon帳戶。 獲取密鑰文件后,請使用以下命令來配置s3cmd。

# s3cmd --configure
Enter new values or accept defaults in brackets with Enter. Refer to user manual for detailed description of all options. Access key and Secret key are your identifiers for Amazon S3 Access Key: xxxxxxxxxxxxxxxxxxxxxx Secret Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Encryption password is used to protect your files from reading by unauthorized persons while in transfer to S3 Encryption password: xxxxxxxxxx Path to GPG program [/usr/bin/gpg]: When using secure HTTPS protocol all communication with Amazon S3 servers is protected from 3rd party eavesdropping. This method is slower than plain HTTP and can't be used if you're behind a proxy Use HTTPS protocol [No]: Yes New settings: Access Key: xxxxxxxxxxxxxxxxxxxxxx Secret Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Encryption password: xxxxxxxxxx Path to GPG program: /usr/bin/gpg Use HTTPS protocol: True HTTP Proxy server name: HTTP Proxy server port: 0 Test access with supplied credentials? [Y/n] Y Please wait, attempting to list all buckets... Success. Your access key and secret key worked fine :-) Now verifying that encryption works... Success. Encryption and decryption worked fine :-) Save settings? [y/N] y Configuration saved to '/root/.s3cfg'
s3cmd命令行的使用

一旦配置成功完成。現在找到下面的命令細節,如何使用命令管理S3桶。

1.列出全部S3桶

使用以下命令列出在您的AWS賬戶中的所有S3桶。

# s3cmd ls
2.創建新桶

要在下面的命令Amazon S3上使用的新桶。這將創建S3帳戶名為howtoing桶。

# s3cmd mb s3://howtoing Bucket 's3://howtoing/' created
3. 上傳文件到S3桶

以下命令將使用s3cmd命令上傳文件file.txt的到S3桶。

# s3cmd put file.txt s3://howtoing/ file.txt -> s3://howtoing/file.txt [1 of 1] 190216 of 190216 100% in 0s 1668.35 kB/s done
4.上傳文件夾到s3桶

如果我們需要上傳整個目錄使用-r遞歸上傳,像下面這樣。

# s3cmd put -r backup s3://howtoing/ backup/file1.txt -> s3://howtoing/backup/file1.txt [1 of 2] 9984 of 9984 100% in 0s 18.78 kB/s done backup/file2.txt -> s3://howtoing/backup/file2.txt [2 of 2] 0 of 0 0% in 0s 0.00 B/s done

請確保您上傳目錄的結尾沒有斜杠 / (如:backup/),否則將只上傳備份目錄中的內容。

# s3cmd put -r backup/ s3://howtoing/ backup/file1.txt -> s3://howtoing/file1.txt [1 of 2] 9984 of 9984 100% in 0s 21.78 kB/s done backup/file2.txt -> s3://howtoing/file2.txt [2 of 2] 0 of 0 0% in 0s 0.00 B/s done
5.列出S3存儲數據

使用 ls 與 s3cmd 切換目錄S3桶的對象。

# s3cmd ls s3://howtoing/ DIR s3://howtoing/backup/ 2013-09-03 10:58 190216 s3://howtoing/file.txt
6.從s3下載文件

有些時候,如果我們需要從S3下載文件,使用下面的命令來下載。

# s3cmd get s3://howtoing/file.txt s3://howtoing/file.txt -> ./file.txt [1 of 1] 4 of 4 100% in 0s 10.84 B/s done
7.刪除S3桶的數據

要刪除的文件夾都是從S3桶使用下面的命令。

 Removing file from s3 bucket  # s3cmd del s3://howtoing/file.txt File s3://howtoing/file.txt deleted  Removing directory from s3 bucket  # s3cmd del s3://howtoing/backup File s3://howtoing/backup deleted
8.卸下S3桶

如果我們不需要S3存儲,我們可以用下面的命令直接刪除它。取出桶之前,請確保它是空的。

# s3cmd rb s3://howtoing ERROR: S3 error: 409 (BucketNotEmpty): The bucket you tried to delete is not empty

上面的命令失敗,因為S3桶不為空 要刪除s3 桶先刪除里面所有對象,然后再次使用命令。

# s3cmd rb s3://howtoing Bucket 's3://howtoing/' removed

感謝您使用這篇文章。 如果你想在你的系統安裝s3bucket,可以查看文章登錄S3bucket在Linux中使用s3fs 。 你也可以在S3桶和本地之間使用目錄s3cmd同步數據 。


免責聲明!

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



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