七牛API服務的命名行測試工具,參考文檔 七牛開發者中心 命令行工具(qshell)
- 實踐目的
- 安裝
- buckets/listbucket/domains/ip/unzip/qetag bucket等通用操作類
- fput/rput/qdownload/prefop/qupload 上傳下載類
- chgm/copy/move/delete 文件操作類
- fetch/sync/prefetch/cdnrefresh 刷新預取類
- b64encode/b64decode/urlencode/urldecode 編碼解碼類
- ts2d/tms2d/d2ts 時間戳日期類
- saveas/reqid/batchsign/privateurl/batchdelete/batchchgm/m3u8delete 其他(批量,私有外鏈)
實踐目的
- 熟悉存儲 API、熟悉 qshell 大部分命令的使用
- 方便快速解決 qshell 常見問題
- 記錄了輸入命令和輸出結果圖,方便理解,也可以作為他人快速理解的材料
- 為后期的其他內部系統工作做准備,文檔及操作的文件在放在 Github
安裝
本質上是單個命令文件,只要放在環境變量能訪問的地方即可。
Mac 版操作步驟如下,其他系統參考 命令行工具(qshell)
- 下載 qshell
- 移動qshell到
/usr/local/bin/qshell
account 設置ak、sk
配置AK、SK:qshell acount ak sk。配置后在會生成/Users/jingliu/.qshell/account.json
文件,保存ak、sk(加密)
stat 查看文件狀態
qshell stat test-pub test/test-fput.mp4
buckets/listbucket/domains/ip/unzip/qetag bucket等通用操作類
buckets 獲取當前賬號下所有的空間名稱
qshell buckets
listbucket 獲取test-pub的文件列表
qshell listbucket test-pub test-pub-listbucket.txt
獲取/mp4開頭的文件列表
qshell listbucket test-pub '/mp4' test-pub-mp4-listbucket.txt
domains 獲取指定空間的所有關聯域名
qshell domains test-pub
ip 根據淘寶的公開API查詢ip地址的地理位置
qshell ip 112.74.185.158
unzip 解壓zip文件,支持UTF-8編碼和GBK編碼
qshell unzip 1.txt.zip
qetag 根據七牛的qetag算法來計算文件的hash
qshell qetag ~/Desktop/11111.mp4
fput/rput/qdownload/prefop/qupload 上傳下載類
fput 以文件表單的方式上傳一個文件
一般建議如果文件大小超過100MB的話,都使用分片上傳rput。
qshell fput test-pub test-fput.mp4 /Users/jingliu/Desktop/test-fput.mp4
前綴,路徑,上傳入口 覆蓋 低頻
qshell fput test-pub test/test-fput.ppt /Users/jingliu/Desktop/test-fput.mp4 http://upload.qiniu.com true 1
rput 以分片上傳的方式上傳一個文件,前綴,路徑,上傳入口 覆蓋 低頻
qshell rput test-pub test/qiniu-introduce-4M.pdf /Users/jingliu/Desktop/
qshell-test/fput/test-fput.mp4 http://upload.qiniu.com true 1
qdownload 從七牛空間同步數據到本地,支持只同步某些前綴的文件,支持增量同步
qshell qdownload 3 config.conf
prefop 查詢七牛數據處理的結果,通過處理的結果id
qshell prefop z0.5b0b8a8538b9f324a5ea1b3a
qupload 是用來將本地目錄中的文件同步到七牛空間中的命令
可以同步父子目錄下的所有文件到七牛的對象存儲空間中。
mac 示例
輸入命令
qshell qupload 1 /Users/jingliu/Desktop/config.json
配置文件
{
"src_dir" : "/Users/jingliu/Desktop/test-dir",
"bucket" : "test-pub"
}
示例圖片
結果展示
win qshell 安裝
安裝qshell和配置環境變量
配置賬號密碼
上傳成功
chgm/copy/move/delete 文件操作類
chgm 修改七牛空間中的一個文件的MimeType,文件類型
qshell chgm test-pub 11.mp4 video/mov
copy 復制七牛空間中的一個文件,可以是 同/不同 一個空間
qshell copy [-overwrite] <SrcBucket> <SrcKey> <DestBucket> [<DestKey>]
不同區域,報錯400
qshell copy -overwrite test-pub 11.mp4 test-pub1 test-pub/mp4/11.mp4
同區域
qshell copy -overwrite test-pub 11.mp4 test-pub-hd test-pub/mp4/11.mp4
move 移動或重命名七牛 同/不同 空間中的一個文件
qshell move -overwrite test-pub 11.mp4 test-pub 22.mp4
qshell move -overwrite test-pub 22.mp4 test-pub-hd test-pub/mp4/22-move.mp4
delete 刪除七牛空間中的一個文件
qshell delete test-pub-hd test-pub/mp4/22-move.mp4
fetch/sync/prefetch/cdnrefresh 刷新預取類
fetch 從Internet上抓取一個資源並存儲到七牛空間中
適合於中小文件的抓取,根據實際經驗,基本上適合50MB以下的文件抓取。
如果指定的Key都是一樣的,那么會默認覆蓋這個Key所對應的文件。
不指定名稱則保存hash值。
功能同接口 第三方資源抓取
qshell fetch https://www.baidu.com/img/bdlogo.png test-pub bpng/dlog.png
sync 從Internet上抓取一個資源並存儲到七牛空間中
適合大文件的場合,比如1G,100G。
sync指令的基本原理是使用Range方式按照4MB一個塊從資源服務器獲取數據,然后使用七牛支持的分片上傳功能直接傳到七牛存儲空間中。並不用擔心網絡中斷導致的同步中斷,因為采用了分片上傳的機制,我們會把每一個成功上傳的塊的位置記錄下來,當下次網絡恢復的時候,只需要運行原始命令即可從斷點處恢復。
qshell sync <SrcResUrl> <Bucket> <Key> [<UpHostIp>]
UpHostIp #獲取,指定ip可減少DNS環節,提升同步速度
華東機房
$ dig up.qiniu.com
華北機房
$ dig up-z1.qiniu.com
華南機房
$ dig up-z2.qiniu.com
北美機房
$ dig up-na0.qiniu.com
qshell sync https://www.baidu.com/img/bdlogo.png test-pub bpng/dlog2.png 115.238.101.35
如下圖,可見sync不支持覆蓋,必須加上https協議(fetch可忽略)
prefetch 更新七牛空間中從源站鏡像過來的文件
配置了鏡像存儲的空間,在一個文件首次回源源站拉取資源后,就不再回源了。如果源站更新了一個文件,那么這個文件不會自動被同步更新到七牛空間。
同接口文檔:鏡像資源更新 (prefetch)
qshell prefetch test-pub demo/iconfont/miga/iconfont.css
qshell prefetch test-pub demo/iconfont/miga/demo.css
下圖分別是更新和拉新,效果是一樣的
cdnrefresh 批量刷新cdn的訪問外鏈
可刷新文件 或 目錄。刷新是把cdn節點上的緩存刷新到cdn節點。
注意需要刷新的目錄,必須以/結尾。
qshell cdnrefresh torefresh.txt
cat torefresh.txt
cdnprefetch 批量預取cdn的訪問外鏈
可刷新文件 或 目錄。預取是把cdn節點上的數據,從源站拉取到cdn節點。
qshell cdnprefetch torefresh.txt
b64encode/b64decode/urlencode/urldecode 編碼解碼類
b64encode base64編碼工具
可選是否使用UrlSafe方式,默認UrlSafe
qshell b64encode 'hello world'
b64decode base64解碼工具
可選是否使用UrlSafe方式,默認UrlSafe
qshell b64decode aGVsbG8gd29ybGQ=
urlencode url編碼工具
qshell urlencode url帶中文
urldecode url解碼工具
qshell urldecode url%E5%B8%A6%E4%B8%AD%E6%96%87
ts2d/tms2d/d2ts 時間戳日期類
ts2d 將timestamp(單位秒)轉為UTC+8:00中國日期
qshell ts2d 1427252311
主要用來檢查上傳策略的deadline參數
tms2d 將timestamp(單位毫秒)轉為UTC+8:00中國日期
qshell tms2d 1427252311000
d2ts(useless) 該命令用來生成一個Unix時間戳(單位秒)
值是當前時間加上指定的秒數的和。如果可以設置指定時間就好了。
qshell d2ts 3600
qshell d2ts -3600