官方文档:
https://docs.ucloud.cn/ufile/tools/tools/tools_file

一、创建存储空间

ucloud 广州地域
Ucloud云存储filemgr命令介绍_第1张图片

Ucloud云存储filemgr命令介绍_第2张图片

Ucloud云存储filemgr命令介绍_第3张图片

二、公私钥地址具体配置

公私钥内容如下:

公钥:TOKEN_d2baa99-ba02-4570-a952-390f0e0fc27c
私钥:d3f33c6b-6a4-4555-9517-b9c0c235a75f

[root@localhost soft]# cat /data/soft/linux64/guangdong-config.cfg 
{
    "public_key" : "TOKEN_d2bbaa99-ba02-4570-a952-390f0e0fc27c",
    "private_key" : "d3f33c6b-6ba4-4555-9517-b9c0c235a75f",
    "proxy_host" : "www.cn-gd.ufileos.com",
    "api_host" : "api.spark.ucloud.cn"
}

提示:
上海地区的proxy_host地址为:www.cn-sh2.ufileos.com
北京地区的proxy_host地址为:www.cn-bj.ufileos.com
广州地区的proxy_host地址为:www.cn-gd.ufileos.com
命令存放路径:
[root@localhost linux64]# which filemgr
/usr/local/bin/filemgr

三、命令应用简单测试

[root@localhost pic]# pwd
/data/www/code/upload/pic

测试:
对于文件夹中大文件较多的情况分片上传文件夹相比普通上传文件夹要快:
--dir ./pic # 指定上传的目录
--trimpath /data/www/code/upload/ #去掉前缀目录
--bucket wbgz-test # 指定bucket名称
--speedlimit 102400000 #限制上传的速度为100M (单位bytes/s )

3.1大文件较多的情况分片上传:

filemgr -config /data/soft/linux64/guangdong-config.cfg --action mput --dir ./pic   --trimpath /data/www/code/upload/ --bucket wbgz-test   --speedlimit 102400000

提示:上传报错的话,可以更新下./filemgr --update

3.2增量上传:

[root@localhost upload]# filemgr -config /data/soft/linux64/guangdong-config.cfg --action mput --dir ./pic   --trimpath /data/www/code/upload/ --bucket wbgz-test   --speedlimit 102400
2020/05/23 15:41:11.905781 [INFO]Upload File[ wbgz-test : pic/2.txt ] Success
2020/05/23 15:41:12.006077 [INFO]Upload File[ wbgz-test : pic/4.txt ] Success
2020/05/23 15:41:12.106297 [INFO]Upload File[ wbgz-test : pic/6.txt ] Success
2020/05/23 15:41:12.206557 [INFO]Upload File[ wbgz-test : pic/3.txt ] Success
2020/05/23 15:41:12.306843 [INFO]Upload File[ wbgz-test : pic/5.txt ] Success
2020/05/23 15:41:12.407103 [INFO]Upload File[ wbgz-test : pic/1.txt ] Success
[root@localhost upload]# filemgr -config /data/soft/linux64/guangdong-config.cfg --action sync  --dir ./pic   --trimpath /data/www/code/upload/ --bucket wbgz-test   --speedlimit 102400 
2020/05/23 15:46:36.518613 [INFO]Syncing...
========================
|      succ|      fail|
------------------------
|         0|         0|
========================

创建测试文件增量上传:

[root@localhost upload]# pwd
/data/www/code/upload
[root@localhost upload]# touch pic/7.txt
[root@localhost upload]# filemgr -config /data/soft/linux64/guangdong-config.cfg --action sync  --dir ./pic   --trimpath /data/www/code/upload/ --bucket wbgz-test   --speedlimit 102400 
2020/05/23 15:47:52.674122 [INFO]Syncing...
2020/05/23 15:47:52.736405 [INFO]   Sync Successed[ /data/www/code/upload/pic/7.txt ] => wbgz-test : 7.txt
========================
|      succ|      fail|
------------------------
|         1|         0|
========================

3.3批量删除文件的命令:

1.带有文件夹类型的:
a. 删除testA 文件夹所有的文件,完全匹配testA,这种形式不匹配:testAA,testAB

./filemgr --action batch-delete  --bucket demo --pattern "^testA\/"

[root@localhost upload]# filemgr -config /data/soft/linux64/config.cfg --action batch-delete --bucket wbtdspcdn-shanghai --pattern "^userpic\/"
2020/01/11 12:16:54.507451 [INFO]batch delete starting...
2020/01/11 12:16:54.635836 [INFO]Delete [wbtdspcdn-shanghai:userpic/10/1577505964286811.jpg] success
2020/01/11 12:16:54.635931 [INFO]DeleteFile Success|FileName:userpic/10/1577505964286811.jpg|CreateTime:1578715588
2020/01/11 12:16:54.638053 [INFO]Delete [wbtdspcdn-shanghai:userpic/3/1578281112975545.jpg] success
2020/01/11 12:16:54.638105 [INFO]DeleteFile Success|FileName:userpic/3/1578281112975545.jpg|CreateTime:1578715588
2020/01/11 12:16:54.643059 [INFO]Delete [wbtdspcdn-shanghai:userpic/1/1577424617373039.jpg] success
2020/01/11 12:16:54.643109 [INFO]DeleteFile Success|FileName:userpic/1/1577424617373039.jpg|CreateTime:1578715588
2020/01/11 12:16:54.643148 [INFO]End without next marker

b. 删除testA 文件夹所有的文件,匹配testA,这种形式也匹配: AAtestA/

./filemgr --action batch-delete  --bucket demo --pattern "testA\/"

c. 删除testA 文件夹下指定文件类型jpg,完全匹配testA,这种形式不匹配:testAA,testAB AAtest

./filemgr --action batch-delete  --bucket demo --pattern "^testA\/.*\.jpg$"

删除存储wbtdpdn-shanghai 文件夹userpic 下的后缀为png的文件:

[root@localhost upload]# filemgr -config /data/soft/linux64/config.cfg --action batch-delete --bucket wbtdspcdn-shanghai  --pattern "^userpic\/.*\.png$"
2020/01/11 12:28:55.535250 [INFO]batch delete starting...
2020/01/11 12:28:55.670083 [INFO]Delete [wbtdspcdn-shanghai:userpic/1/112211.png] success
2020/01/11 12:28:55.670198 [INFO]DeleteFile Success|FileName:userpic/1/112211.png|CreateTime:1578716799
2020/01/11 12:28:55.719129 [INFO]Delete [wbtdspcdn-shanghai:userpic/10/112211.png] success
2020/01/11 12:28:55.719173 [INFO]DeleteFile Success|FileName:userpic/10/112211.png|CreateTime:1578716694
2020/01/11 12:28:55.719206 [INFO]End without next marker

提示:要想在控制台删除云存储buckets目录下的文件。必须先保证云存储buckets里面是空的,然后就是删除掉buckets中文件夹下的key文件, 然后删除buckets,最后才是删除云存储
简单演示到此处

附带一个简单脚本:

[root@mysql-redis ~]# cat /data/scripts/sync_bj_oss.sh 
#/bin/bash
source /etc/profile
cd /data/www/code
/usr/local/bin/filemgr  -config /data/soft/linux64/beijing-config.cfg --action sync --dir ./upload/ --trimpath /data/www/code/ --bucket wsp-cdn-beijing >/dev/null 2>&1