syncoss

2.0.5 • Public • Published

SyncOSS 阿里云OSS文件同步工具

同步本地与OSS文件,并自动刷新CDN。

优点

  1. 不仅有上传和更新功能,还带有删除功能,不会浪费OSS的容量(省钱)。
  2. 在程序启动时,程序会把OSS和本地的文件进行MD5对比,所以由始至终,本地和OSS的文件都是相同的。
  3. 带有CDN刷新功能,所以你不必手动刷新文件。

缺点

  1. 监视同步功能(默认关闭)会耗费大量内存,如果你开发机内存较小(如只有1G),则不建议使用。
  2. 暂只能以“本地文件为准”方式同步,日后会添加更多模式。
  3. 目前没在服务器上使用过,只在windows开发机上运行过

使用方法

1.安装

npm install syncoss -g

2.配置

请在项目根目录下放置syncossConf.json文件,参考下面的写法:(请删除注释,json是没有注释的)

{
  "AccessKeyId": "xxx",
  "AccessKeySecret": "xx",
  "cdn": {
    "domain": "cdn.lazycoffee.com"
  },
  "oss": {
    "securityToken": "", //TSS
    "endpoint": "http://oss-cn-hangzhou.aliyuncs.com", //oss
    "region": "oss-cn-hangzhou", //endpoint  region endpointregion
    "internal": true, //region使internaltrue访,
    "secure": true, //region使securetrue使HTTPS访
    "cname": "", //endpoint使cnametrueendpoint
    "timeout": 60, //60访OSSAPI
    "autoRefreshCDN": true, //CDN
    "contentEncoding": "" // Content-Encoding
  },
  "AccessControlAllowOrigin": "www.lazycoffee.com",
  "bucket": "lazycoffee",
  "watch": {
    "ignored": ""
  },
  "keepWatching": false,
  "syncDir": "public", //
  "syncFilter": [ //
    "js", "css", "vendor", "!images"//
  ]
}

3.运行

打开命令行,cd到项目根目录,运行:

syncOSS

调试模式:

syncoss --debug

文件监视模式:

syncoss --watch

工作流程

  1. 获取设定的OSS父文件夹下所有文件的信息,用于文件对比。
  2. 对比本地和OSS的文件,如ETag不同或者远程没有这个文件,那么就会上传或更新OSS的文件。如果OSS有,但本地没有的文件,那么SyncOSS就会将OSS这个文件删除。
  3. 监视本地文件夹,当发现有文件“增删改”,即会触发相应的同步行为。例如本地删除一个文件,OSS也同样会将这个文件删除。

Author 作者

James Yinelantion@gmail.com

License

Copyright (c) 2015 James Yin, elantion@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

Package Sidebar

Install

npm i syncoss

Weekly Downloads

0

Version

2.0.5

License

MIT

Last publish

Collaborators

  • elantion