腾讯云Debian12配置COSMD
参考文档 https://cloud.tencent.com/document/product/436/10976
1. 安装pipx
直接按照官方的安装 pip 可能会报错
error: externally-managed-environment
改用pipx安装
apt install pipx
2. 安装cosmd
pipx install coscmd
installed package coscmd 1.8.6.32, installed using Python 3.11.2
These apps are now globally available
– coscmd
⚠️ Note: ‘/root/.local/bin’ is not on your PATH environment variable. These apps will not be globally accessible until your PATH is updated.
Run `pipx ensurepath` to automatically add it, or manually modify your PATH in your shell’s config file (i.e. ~/.bashrc).
done! ✨ 🌟 ✨
使用 pipx ensurepath
Success! Added /root/.local/bin to the PATH environment variable.
Consider adding shell completions for pipx. Run ‘pipx completions’ for instructions.
You will need to open a new terminal or re-login for the PATH changes to take effect.
Otherwise pipx is ready to go! ✨ 🌟 ✨
source ~/.bashrc
更新cosmd pipx upgrade coscmd
再使用 coscmd -h
可以验证
3. 配置cosmd
coscmd config -a AChT4ThiXAbpBDEFGhT4ThiXAbp**** -s WE54wreefvds3462refgwewe**** -b configure-bucket-1250000000 -r ap-chengdu
4. 上传示例
coscmd upload -rs --delete --yes /www/wwwroot/jre.info/wp-content/uploads/2023/09 /wp-content/uploads/2023/
会在cos自动建立wp-content,2023等文件夹,会把09文件夹传至2023文件夹。
(推荐)或者 coscmd upload -rs --delete --yes /www/wwwroot/jre.info/wp-content/uploads/2023/09 /wp-content/uploads/2023/09
注意最后没有“/”。
5. 监测与同步
inotify-tools 的安装参见 监测文件变动同步到阿里云OSS
#!/bin/bash
watch_and_sync() {
local source=$1
local target=$2
inotifywait -m -r -e create,delete,modify,move --format '%w%f' $source | while read file
do
coscmd upload -rs --delete --yes $source $target
done
}
watch_and_sync "/www/wwwroot/jre.info/wp-content/uploads/2023/10" "/wp-content/uploads/2023/10" &
watch_and_sync "/www/wwwroot/jre.info/wp-content/uploads/2023/11" "/wp-content/uploads/2023/11" &
watch_and_sync "/www/wwwroot/jre.info/wp-content/themes/jreinfo/assets" "/wp-content/themes/jreinfo/assets" &
watch_and_sync "/www/wwwroot/jre.info/wp-content/plugins" "/wp-content/plugins" &