分类目录归档:Uncategorized

多平台实时同步方案比较(cp,scp,rsync,DRBD,lsyncd,Syncthing,seafile,Nextcloud)

cp命令实现增量同步

可用于linux/mac,可以增量,不能跨机器。

使用-u参数实现增量,-r递归,使用实例

cp -ru dir1/* dir2/

详细参数

用法:cp [选项]... [-T] 源文件 目标文件
 或:cp [选项]... 源文件... 目录
 或:cp [选项]... -t 目录 源文件...
将源文件复制至目标文件,或将多个源文件复制至目标目录。

长选项必须使用的参数对于短选项时也是必需使用的。
  -a, --archive                 等于-dR --preserve=all
      --backup[=CONTROL         为每个已存在的目标文件创建备份
  -b                            类似--backup 但不接受参数
      --copy-contents           在递归处理是复制特殊文件内容
  -d                            等于--no-dereference --preserve=links
  -f, --force                   如果目标文件无法打开则将其移除并重试(当 -n 选项
                                        存在时则不需再选此项)
  -i, --interactive             覆盖前询问(使前面的 -n 选项失效)
  -H                            跟随源文件中的命令行符号链接
  -l, --link                    链接文件而不复制
  -L, --dereference             总是跟随符号链接
  -n, --no-clobber              不要覆盖已存在的文件(使前面的 -i 选项失效)
  -P, --no-dereference          不跟随源文件中的符号链接
  -p                            等于--preserve=模式,所有权,时间戳
      --preserve[=属性列表      保持指定的属性(默认:模式,所有权,时间戳),如果
                                        可能保持附加属性:环境、链接、xattr 等
  -c                           same as --preserve=context
      --sno-preserve=属性列表   不保留指定的文件属性
      --parents                 复制前在目标目录创建来源文件路径中的所有目录
  -R, -r, --recursive           递归复制目录及其子目录内的所有内容
      --reflink[=WHEN]          控制克隆/CoW 副本。请查看下面的内如。
      --remove-destination      尝试打开目标文件前先删除已存在的目的地
                                        文件 (相对于 --force 选项)
      --sparse=WHEN             控制创建稀疏文件的方式
      --strip-trailing-slashes  删除参数中所有源文件/目录末端的斜杠
  -s, --symbolic-link           只创建符号链接而不复制文件
  -S, --suffix=后缀             自行指定备份文件的后缀
  -t,  --target-directory=目录  将所有参数指定的源文件/目录
                                           复制至目标目录
  -T, --no-target-directory     将目标目录视作普通文件
  -u, --update                 copy only when the SOURCE file is newer
                                 than the destination file or when the
                                 destination file is missing
  -v, --verbose                explain what is being done
  -x, --one-file-system        stay on this file system
  -Z, --context=CONTEXT        set security context of copy to CONTEXT
      --help            显示此帮助信息并退出
      --version         显示版本信息并退出

scp命令实现跨机器增量同步

可用于linux/mac系统,可以增量,可以跨机器,跨机器通过ssh。

使用实例

scp user@host1:/dir/* /home/www/

详细参数

usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2

-B  使用批处理模式(传输过程中不询问传输口令或短语) 
-C  允许压缩。(将-C标志传递给ssh,从而打开压缩功能) 
-p  保留原文件的修改时间,访问时间和访问权限。 
-q  不显示传输进度条。 
-r  递归复制整个目录。 
-v 详细方式显示输出。scp和ssh(1)会显示出整个过程的调试信息。这些信息用于调试连接,验证和配置问题。  
-c cipher  以cipher将数据传输进行加密,这个选项将直接传递给ssh。  
-F ssh_config  指定一个替代的ssh配置文件,此参数直接传递给ssh。 
-i identity_file  从指定文件中读取传输时使用的密钥文件,此参数直接传递给ssh。   
-l limit  限定用户所能使用的带宽,以Kbit/s为单位。    
-o ssh_option  如果习惯于使用ssh_config(5)中的参数传递方式,  
-P port  注意是大写的P, port是指定数据传输用到的端口号  
-S program  指定加密传输时所使用的程序。此程序必须能够理解ssh(1)的选项。

rsync 命令实现跨机器增量同步

可用于linux/mac系统,可以增量,可以跨机器,跨机器通过ssh。相对于scp推荐。可以显示进度、排除软链等。

用例

rsync -e "ssh -p22222" -avpgolr --progress  host:/dir/file /dir/file

详细参数


Usage: rsync [OPTION]... SRC [SRC]... DEST
  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST
  or   rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST
  or   rsync [OPTION]... [USER@]HOST:SRC [DEST]
  or   rsync [OPTION]... [USER@]HOST::SRC [DEST]
  or   rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect
to an rsync daemon, and require SRC or DEST to start with a module name.

Options
 -v, --verbose               increase verbosity
 -q, --quiet                 suppress non-error messages
     --no-motd               suppress daemon-mode MOTD (see manpage caveat)
 -c, --checksum              skip based on checksum, not mod-time & size
 -a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)
     --no-OPTION             turn off an implied OPTION (e.g. --no-D)
 -r, --recursive             recurse into directories
 -R, --relative              use relative path names
     --no-implied-dirs       don't send implied dirs with --relative
 -b, --backup                make backups (see --suffix & --backup-dir)
     --backup-dir=DIR        make backups into hierarchy based in DIR
     --suffix=SUFFIX         set backup suffix (default ~ w/o --backup-dir)
 -u, --update                skip files that are newer on the receiver
     --inplace               update destination files in-place (SEE MAN PAGE)
     --append                append data onto shorter files
     --append-verify         like --append, but with old data in file checksum
 -d, --dirs                  transfer directories without recursing
 -l, --links                 copy symlinks as symlinks
 -L, --copy-links            transform symlink into referent file/dir
     --copy-unsafe-links     only "unsafe" symlinks are transformed
     --safe-links            ignore symlinks that point outside the source tree
 -k, --copy-dirlinks         transform symlink to a dir into referent dir
 -K, --keep-dirlinks         treat symlinked dir on receiver as dir
 -H, --hard-links            preserve hard links
 -p, --perms                 preserve permissions
 -E, --executability         preserve the file's executability
     --chmod=CHMOD           affect file and/or directory permissions
 -A, --acls                  preserve ACLs (implies --perms)
 -X, --xattrs                preserve extended attributes
 -o, --owner                 preserve owner (super-user only)
 -g, --group                 preserve group
     --devices               preserve device files (super-user only)
     --copy-devices          copy device contents as regular file
     --specials              preserve special files
 -D                          same as --devices --specials
 -t, --times                 preserve modification times
 -O, --omit-dir-times        omit directories from --times
     --super                 receiver attempts super-user activities
     --fake-super            store/recover privileged attrs using xattrs
 -S, --sparse                handle sparse files efficiently
 -n, --dry-run               perform a trial run with no changes made
 -W, --whole-file            copy files whole (without delta-xfer algorithm)
 -x, --one-file-system       don't cross filesystem boundaries
 -B, --block-size=SIZE       force a fixed checksum block-size
 -e, --rsh=COMMAND           specify the remote shell to use
     --rsync-path=PROGRAM    specify the rsync to run on the remote machine
     --existing              skip creating new files on receiver
     --ignore-existing       skip updating files that already exist on receiver
     --remove-source-files   sender removes synchronized files (non-dirs)
     --del                   an alias for --delete-during
     --delete                delete extraneous files from destination dirs
     --delete-before         receiver deletes before transfer, not during
     --delete-during         receiver deletes during transfer (default)
     --delete-delay          find deletions during, delete after
     --delete-after          receiver deletes after transfer, not during
     --delete-excluded       also delete excluded files from destination dirs
     --ignore-errors         delete even if there are I/O errors
     --force                 force deletion of directories even if not empty
     --max-delete=NUM        don't delete more than NUM files
     --max-size=SIZE         don't transfer any file larger than SIZE
     --min-size=SIZE         don't transfer any file smaller than SIZE
     --partial               keep partially transferred files
     --partial-dir=DIR       put a partially transferred file into DIR
     --delay-updates         put all updated files into place at transfer's end
 -m, --prune-empty-dirs      prune empty directory chains from the file-list
     --numeric-ids           don't map uid/gid values by user/group name
     --timeout=SECONDS       set I/O timeout in seconds
     --contimeout=SECONDS    set daemon connection timeout in seconds
 -I, --ignore-times          don't skip files that match in size and mod-time
     --size-only             skip files that match in size
     --modify-window=NUM     compare mod-times with reduced accuracy
 -T, --temp-dir=DIR          create temporary files in directory DIR
 -y, --fuzzy                 find similar file for basis if no dest file
     --compare-dest=DIR      also compare destination files relative to DIR
     --copy-dest=DIR         ... and include copies of unchanged files
     --link-dest=DIR         hardlink to files in DIR when unchanged
 -z, --compress              compress file data during the transfer
     --compress-level=NUM    explicitly set compression level
     --skip-compress=LIST    skip compressing files with a suffix in LIST
 -C, --cvs-exclude           auto-ignore files the same way CVS does
 -f, --filter=RULE           add a file-filtering RULE
 -F                          same as --filter='dir-merge /.rsync-filter'
                             repeated: --filter='- .rsync-filter'
     --exclude=PATTERN       exclude files matching PATTERN
     --exclude-from=FILE     read exclude patterns from FILE
     --include=PATTERN       don't exclude files matching PATTERN
     --include-from=FILE     read include patterns from FILE
     --files-from=FILE       read list of source-file names from FILE
 -0, --from0                 all *-from/filter files are delimited by 0s
 -s, --protect-args          no space-splitting; only wildcard special-chars
     --address=ADDRESS       bind address for outgoing socket to daemon
     --port=PORT             specify double-colon alternate port number
     --sockopts=OPTIONS      specify custom TCP options
     --blocking-io           use blocking I/O for the remote shell
     --stats                 give some file-transfer stats
 -8, --8-bit-output          leave high-bit chars unescaped in output
 -h, --human-readable        output numbers in a human-readable format
     --progress              show progress during transfer
 -P                          same as --partial --progress
 -i, --itemize-changes       output a change-summary for all updates
     --out-format=FORMAT     output updates using the specified FORMAT
     --log-file=FILE         log what we're doing to the specified FILE
     --log-file-format=FMT   log updates using the specified FMT
     --password-file=FILE    read daemon-access password from FILE
     --list-only             list the files instead of copying them
     --bwlimit=KBPS          limit I/O bandwidth; KBytes per second
     --write-batch=FILE      write a batched update to FILE
     --only-write-batch=FILE like --write-batch but w/o updating destination
     --read-batch=FILE       read a batched update from FILE
     --protocol=NUM          force an older protocol version to be used
     --iconv=CONVERT_SPEC    request charset conversion of filenames
 -4, --ipv4                  prefer IPv4
 -6, --ipv6                  prefer IPv6
     --version               print version number
(-h) --help                  show this help (-h works with no other options)

DRBD 高性能网络磁盘同步

DRBD是linux的内核的存储层中的一个分布式存储系统,可用使用DRBD在两台Linux服务器之间共享块设备,共享文件系统和数据。
用于linux/mac,类似于一个网络RAID-1的功能,高性能。

rsync+inotify 实时增量同步

1、先安装好inotify包

  wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz  

tar zxf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14

 ./configure --prefix=/usr/local/inotify-3.14

make && make install

2、创建监控脚本inotify.sh

#!/bin/bash
#para
host01=192.168.0.144  #rsync服务器地址
src=/backup        #本地监控的目录
dst=backup         #rsync服务器的模块名称
user=nowview      #rsync服务器的虚拟用户
rsync_passfile=/etc/rsyncd.password   #本地调用rsync服务的密码文件
inotify_home=/usr/local/inotify-3.14    #inotify的安装目录
#judge
if [ ! -e "$src" ] \
|| [ ! -e "${rsync_passfile}" ] \
|| [ ! -e "${inotify_home}/bin/inotifywait" ] \
|| [ ! -e "/usr/bin/rsync" ];
then
echo "Check File and Folder"
exit 9
fi
${inotify_home}/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write,delete,create,attrib $src \
| while read file
do
#  rsync -avzP --delete --timeout=100 --password-file=${rsync_passfile} $src $user@$host01::$dst >/dev/null 2>&1
cd $src && rsync -aruz -R --delete ./  --timeout=100 $user@$host01::$dst --password-file=${rsync_passfile} >/dev/null 2>&1
done
exit 0

lsyncd 多机器实时同步文件神器

lsyncd 是一个支持实时、双向、多机器的多模式文件同步工具。

使用 Lua 语言封装了 inotify 和 rsync 工具,采用了 Linux 内核(2.6.13 及以后)里的 inotify 触发机制,然后通过 rsync 去差异同步,达到实时的效果。

Syncthing

支持Windows/linux/mac/android,采用go语言开发,提供多个平台的客户端。没有iOS客户端。

seafile

同样采用go开发,Seafile 是一款开源的企业云盘,注重可靠性和性能。支持 Windows, Mac, Linux, iOS, Android 平台。支持文件同步或者直接挂载到本地访问。

Nextcloud/ownCloud

采用PHP基于ownCloud开发,支持 Windows, Mac, Linux, iOS, Android 平台。

参考

开源CRM/ERP比较

名称 语言 协议 提供外部API 项目地址
悟空 PHP/JAVA 商业 否(但是管理后台采用rest) https://gitee.com/wukongcrm/72crm
PSI PHP GPLv3 插件化ERP https://gitee.com/crm8000/PSI
SugarCRM PHP GPLv3 开源版本已不更新 https://sourceforge.net/projects/sugarcrm/
SuiteCRM PHP GPLv3 基于SugarCRM,目前仍在更新 https://github.com/salesagility/SuiteCRM
VtigerCRM PHP GPLv3 基于SugarCRM,开源版本已不更新
Odoo Python GPLv3 插件化ERP https://github.com/odoo/odoo
OFBiz Java Apache 未知 https://ofbiz.apache.org/

最后得出,
CRM完全免费用SuiteCRM,悟空收费中文支持好。
小型ERP选择Odoo,大公司ERP选择OFBiz。

手机移动端富文本编辑器比较

Quill

Quill is a modern WYSIWYG editor built for compatibility and extensibility. https://quilljs.com - API Driven Design - Custom Content and Formatting - Cross Platform - Easy to Use 重要的是linkedin也在用

Eleditor

  • 兼容Android&ios
  • Eleditor的开发是为了解决移动端项目中的富文本编辑问题。具有
  • 轻量,可定制,注重用户体验等特点 -开源基于MIT协议,允许自由使用和修改代码

simditor

An Easy and Fast WYSIWYG Editor

  • 有插件和文档(非移动优先)

vue-html-editor

A Vue.js component implementing the HTML editor with the jQuery summernote plugin.

Squire

the textarea of the future

Angular-trix

A rich wysiwyg text editor directive for angularjs.

textAngular

textAngular is a super cool WYSIWYG Text Editor directive for AngularJS

Draft.js

Rich Text Editor Framework for React

HTML中的全角、半角空格

HTML提供了5种空格实体(space entity),它们拥有不同的宽度,非断行空格( )是常规空格的宽度,可运行于所有主流浏览器。其他几种空格(       ‌‍)在不同浏览器中宽度各异。

 

它叫不换行空格,全称No-Break Space,它是最常见和我们使用最多的空格,大多数的人可能只接触了 ,它是按下space键产生的空格。在HTML中,如果你用空格键产生此空格,空格是不会累加的(只算1个)。要使用html实体表示才可累加, 该空格占据宽度受字体影响明显而强烈。

 

它叫“半角空格”,全称是En Space,en是字体排印学的计量单位,为em宽度的一半。根据定义,它等同于字体度的一半(如16px字体中就是8px)。名义上是小写字母n的宽度。此空格传承空格家族一贯的特性:透明的,此空格有个相当稳健的特性, 就是其占据的宽度正好是1/2个中文宽度,而且基本上不受字体影响。

 

它叫“全角空格”,全称是Em Space,em是字体排印学的计量单位,相当于当前指定的点数。例如,1 em在16px的字体中就是16px。此空格也传承空格家族一贯的特性:透明的,此空格也有个相当稳健的特性, 就是其占据的宽度正好是1个中文宽度,而且基本上不受字体影响。

 

它叫窄空格,全称是Thin Space。我们不妨称之为“瘦弱空格”,就是该空格长得比较瘦弱,身体单薄,占据的宽度比较小。它是em之六分之一宽。

‌

它叫零宽不连字,全称是Zero Width Non Joiner,简称“ZWNJ”,是一个不打印字符,放在电子文本的两个字符之间,抑制本来会发生的连字,而是以这两个字符原本的字形来绘制。Unicode中的零宽不连字字符映射为“”(zero width non-joiner,U+200C),HTML字符值引用为: ‌

‍

它叫零宽连字,全称是Zero Width Joiner,简称“ZWJ”,是一个不打印字符,放在某些需要复杂排版语言(如阿拉伯语、印地语)的两个字符之间,使得这两个本不会发生连字的字符产生了连字效果。零宽连字符的Unicode码位是U+200D (HTML: ‍ ‍)。

此外,浏览器还会把以下字符当作空白进行解析:空格( )、制表位( )、换行( )和回车( )还有( )等等。

golang的包管理工具

dep - Go dependency tool

Dep is a prototype dependency management tool. It requires Go 1.7 or newer to compile.

dep is NOT an official tool. Yet. Check out the Roadmap! Current status

Alpha. Functionality is known to be broken, missing or incomplete. Changes are planned to the CLI commands soon. It would be unwise to write scripts atop dep before then. The repository is open to solicit feedback and contributions from the community. Please see below for feedback and contribution guidelines.

Gopkg.toml and Gopkg.lock have reached a stable structure, and it is safe to commit them in your projects. We plan to add more to these files, but we guarantee these changes will be backwards-compatible.

glide - Package Management for Golang https://glide.sh

Are you used to tools such as Cargo, npm, Composer, Nuget, Pip, Maven, Bundler, or other modern package managers? If so, Glide is the comparable Go tool.

Manage your vendor and vendored packages with ease. Glide is a tool for managing the vendor directory within a Go package. This feature, first introduced in Go 1.5, allows each package to have a vendor directory containing dependent packages for the project. These vendor packages can be installed by a tool (e.g. glide), similar to go get or they can be vendored and distributed with the package.

Golang Dep

An official package manager has been started for the Go community. We view this as a good thing to bring everyone together around one solution. It's currently pre-alpha so it's not ready for prime time usage.

If you start to poke it you'll see it has a similar style to Glide. While commands may have different names there are many of the same features such as semantic versions and ranges.

Our view is that Glide will be around until an official package manager is ready for production use by the masses. We support the common tool and look forward to the day it is capable of replacing Glide.

Features

  • Ease dependency management
  • Support versioning packages including Semantic Versioning 2.0.0 support. Any constraint the github.com/Masterminds/semver package can parse can be used.
  • Support aliasing packages (e.g. for working with github forks)
  • Remove the need for munging import statements
  • Work with all of the go tools
  • Support the VCS tools that Go supports:
    • git
    • bzr
    • hg
    • svn
  • Support custom local and global plugins (see docs/plugins.md)
  • Repository caching and data caching for improved performance.
  • Flatten dependencies resolving version differences and avoiding the inclusion of a package multiple times.
  • Manage and install dependencies on-demand or vendored in your version control system.

使用php转换URL从相对路径到绝对路径

Transfrom relative path into absolute URL using PHP

function rel2abs($rel, $base)
{
    /* return if already absolute URL */
    if (parse_url($rel, PHP_URL_SCHEME) != '')
        return ($rel);

    /* queries and anchors */
    if ($rel[0] == '#' || $rel[0] == '?')
        return ($base . $rel);

    /* parse base URL and convert to local variables: $scheme, $host, $path, $query, $port, $user, $pass */
    extract(parse_url($base));

    /* remove non-directory element from path */
    $path = preg_replace('#/[^/]*$#', '', $path);

    /* destroy path if relative url points to root */
    if ($rel[0] == '/')
        $path = '';

    /* dirty absolute URL */
    $abs = '';

    /* do we have a user in our URL? */
    if (isset($user)) {
        $abs .= $user;

        /* password too? */
        if (isset($pass))
            $abs .= ':' . $pass;

        $abs .= '@';
    }

    $abs .= $host;

    /* did somebody sneak in a port? */
    if (isset($port))
        $abs .= ':' . $port;

    $abs .= $path . '/' . $rel . (isset($query) ? '?' . $query : '');

    /* replace '//' or '/./' or '/foo/../' with '/' */
    $re = ['#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#'];
    for ($n = 1; $n > 0; $abs = preg_replace($re, '/', $abs, -1, $n)) {
    }

    /* absolute URL is ready! */

    return ($scheme . '://' . $abs);
}