UNISON文件同步

1.使用环境

下载地址:可以百度搜索unison sync,也可以直接访问官网地址https://www.cis.upenn.edu/~bcpierce/unison/
两台windows设备(理论上服务端客户端在任意支持平台均可)

2.部署方式

一台作为服务端,侦听端口,另外一台作为客户端直接同步

2.1.服务端部署

下载后解压,直接使用命令行
可以使用命令行进入当前目录,也可以直接使用绝对路径直接打开(如果通过FTP或者ssh或者webdav等方式打通,可以不用部署服务端,直接进入客户端使用步骤)

// 参数-socket 54321对应为侦听端口,可以自定义
unison.exe -socket 54321

运行后可以返回以下信息,标识运行正常(可以通过netstat -ano | findstr 54321查看是否已启动侦听)

server started

后续如果需要自动开启,可以直接使用定时计划执行命令或者直接调用批处理

注意:由于该服务被telnet直接输入非法字符后会自动退出,可以考虑批处理增加进程检测脚本,检测有异常自动拉起,可以通过定时计划设置检查间隔(以下内容复制保存在批处理中,放在主程序所在目录)

//进入unison.exe主程序所在绝对路径
cd /d %~dp0
//检查54321端口是否侦听,如果没有侦听,启动对应服务
netstat -ano | findstr 54321| findstr LISTENING ||unison.exe -socket 54321

2.2.客户端配置

下载后解压,直接使用命令行
可以使用命令行进入当前目录,也可以直接使用绝对路径直接打开,当然也可以使用GUI形式(比较简单就不做展开了)

// 参数-batch 无需确认,-repeat 完成后sleep多少秒,可以按需自定义  源端和目标端可以根据需要调整位置,如果为ftp可以调整为ftp路径,磁盘映射可以直接调整盘符,本地直接写两个路径即可
unison.exe -batch -repeat 5 socket://服务端IP:端口/d:/test d:\test
//注意源端代表第一次作为基准,由于没有使用备份模式,其实没有明显差异,根据个人喜好设置即可
//借鉴服务端启动方式,可以用如下命令启动,避免多开,同时可以定时计划避免程序飞掉
//进入当前目录,把批处理放在主程序目录可以省略进入当前目录步骤
cd /d %~dp0
//查看进程是否在运行,如果没有则启动,有则启动同步
tasklist |findstr unison||unison.exe -batch -repeat 5 socket://IP:端口/d:/test d:\test

3.补充说明

定时计划设置细节:

因为存在可能使用批处理执行或者GUI执行,因此建议使用以上脚本,容错,避免双开。
定时计划设置时需要关注以下开关(win11不开启,触发任务时会非常卡顿,开启后通过启动脚本判断程序在运行直接退出即可,未运行则启动):
在这里插入图片描述

使用帮助说明

\bin>unison.exe --help
Usage: unison [options]
    or unison root1 root2 [options]
    or unison profilename [options]

Basic options:

  General:
   -doc xxx            show documentation ('-doc topics' lists topics)
   -version            print version and exit

  What to sync:
   -group              synchronize group attributes
   -ignore xxx         add a pattern to the ignore list
   -ignorenot xxx      add a pattern to the ignorenot list
   -nocreation xxx     prevent file creations on one replica
   -nodeletion xxx     prevent file deletions on one replica
   -noupdate xxx       prevent file updates and deletions on one replica
   -owner              synchronize owner
   -path xxx           path to synchronize
   -perms n            part of the permissions which is synchronized
   -root xxx           root of a replica (should be used exactly twice)
   -times              synchronize modification times

  How to sync:
   -batch              batch mode: ask no questions at all
   
  How to sync (text interface (CLI) only):
   -auto               automatically accept default (nonconflicting) actions
   -silent             print nothing except error messages
   -terse              suppress status messages

  Text interface (CLI):
   -i                  interactive profile mode (text UI); command-line only

Advanced options:

  Fine-tune sync:
   -acl                synchronize ACLs
   -atomic xxx         add a pattern to the atomic list
   -follow xxx         add a pattern to the follow list
   -force xxx          force changes from this replica to the other
   -forcepartial xxx   add a pattern to the forcepartial list
   -ignorecase xxx     identify upper/lowercase filenames (true/false/default)
   -immutable xxx      add a pattern to the immutable list
   -immutablenot xxx   add a pattern to the immutablenot list
   -links xxx          allow the synchronization of symbolic links
                       (true/false/default)
   -merge xxx          add a pattern to the merge list
   -nocreationpartial xxx add a pattern to the nocreationpartial list
   -nodeletionpartial xxx add a pattern to the nodeletionpartial list
   -noupdatepartial xxx add a pattern to the noupdatepartial list
   -prefer xxx         choose this replica's version for conflicting changes
   -preferpartial xxx  add a pattern to the preferpartial list
   -rsrc xxx           synchronize resource forks (true/false/default)
   -xattrignore xxx    add a pattern to the xattrignore list
   -xattrignorenot xxx add a pattern to the xattrignorenot list
   -xattrs             synchronize extended attributes (xattrs)

  How to sync:
   -backup xxx         add a pattern to the backup list
   -backupcurr xxx     add a pattern to the backupcurr list
   -backupcurrnot xxx  add a pattern to the backupcurrnot list
   -backupdir xxx      directory for storing centralized backups
   -backuploc xxx      where backups are stored ('local' or 'central')
   -backupnot xxx      add a pattern to the backupnot list
   -backupprefix xxx   prefix for the names of backup files
   -backups            (deprecated) keep backup copies of all files (see also
                       'backup')
   -backupsuffix xxx   a suffix to be added to names of backup files
   -confirmbigdel      ask about whole-replica (or path) deletes (default true)
   -confirmmerge       ask for confirmation before committing results of a merge
   -copyonconflict     keep copies of conflicting files
   -dontchmod          when set, never use the chmod system call
   -fastcheck xxx      do fast update detection (true/false/default)
   -fat                use appropriate options for FAT filesystems
   -ignoreinodenumbers ignore inode number changes when detecting updates
   -maxbackups n       number of backed up versions of a file
   -numericids         don't map uid/gid values by user/group names
   -sortbysize         list changed files by size, not name
   -sortfirst xxx      add a pattern to the sortfirst list
   -sortlast xxx       add a pattern to the sortlast list
   -sortnewfirst       list new before changed files

  How to sync (text interface (CLI) only):
   -repeat xxx         synchronize repeatedly (text interface only)
   -retry n            re-try failed synchronizations N times (text ui only)

  Text interface (CLI):
   -color xxx          use color output for text UI (true/false/default)
   -dumbtty            do not change terminal settings in text UI

  Graphical interface (GUI):
   -height n           height (in lines) of main window in graphical interface

  Remote connections:
   -addversionno       add version number to name of unison on server
   -clientHostName xxx set host name of client
   -halfduplex         (deprecated) force half-duplex communication with the
                       server
   -killserver         kill server when done (even when using sockets)
   -listen xxx         listen on this name or addr in server socket mode (can
                       repeat)
   -rsync              activate the rsync transfer mode (default true)
   -servercmd xxx      name of unison executable on remote server
   -socket xxx         act as a server on a socket
   -sshargs xxx        other arguments (if any) for remote shell command
   -sshcmd xxx         path to the ssh executable
   -stream             (deprecated) use a streaming protocol for transferring
                       file contents (default true)
   -testserver         exit immediately after the connection to the server
   -xferbycopying      optimize transfers using local copies (default true)

  Archive management:
   -ignorearchives     ignore existing archive files

  Other:
   -addprefsto xxx     file to add new prefs to
   -contactquietly     suppress the 'contacting server' message during startup
   -copymax n          maximum number of simultaneous copyprog transfers
   -copyprog xxx       external program for copying large files
   -copyprogrest xxx   variant of copyprog for resuming partial transfers
   -copyquoterem xxx   add quotes to remote file name for copyprog
                       (true/false/default)
   -copythreshold n    use copyprog on files bigger than this (if >=0, in Kb)
   -diff xxx           set command for showing differences between files
   -ignorelocks        ignore locks left over from previous run (dangerous!)
   -include xxx        include a profile's preferences
   -key xxx            define a keyboard shortcut for this profile (in some UIs)
   -label xxx          provide a descriptive string label for this profile
   -log                record actions in logfile (default true)
   -logfile xxx        logfile name
   -maxerrors n        maximum number of errors before a directory transfer is
                       aborted
   -maxsizethreshold n prevent transfer of files bigger than this (if >=0, in
                       Kb)
   -maxthreads n       maximum number of simultaneous file transfers
   -mountpoint xxx     abort if this path does not exist
   -rootalias xxx      register alias for canonical root names
   -showarchive        show 'true names' (for rootalias) of roots and archive
   -source xxx         include a file's preferences
   -ui xxx             select UI ('text' or 'graphic'); command-line only
   -unicode xxx        assume Unicode encoding in case insensitive mode
   -watch              when set, use a file watcher process to detect changes

Expert options:
   -debug xxx          debug module xxx ('all' -> everything, 'verbose' -> more)
   -dumparchives       dump contents of archives just after loading
   -fastercheckUNSAFE  skip computing fingerprints for new files (experts only!)
   -selftest           run internal tests and exit

unison.exe: unknown option `--help'.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Qwier

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值