{"id":241,"date":"2022-05-27T20:22:34","date_gmt":"2022-05-27T12:22:34","guid":{"rendered":"https:\/\/frogvps.com\/?p=241"},"modified":"2022-05-27T20:24:38","modified_gmt":"2022-05-27T12:24:38","slug":"inotifyrsyncshell%e8%84%9a%e6%9c%ac%e5%ae%9e%e7%8e%b0%e5%ae%9e%e6%97%b6%e6%95%b0%e6%8d%ae%e5%90%8c%e6%ad%a5","status":"publish","type":"post","link":"https:\/\/frogvps.com\/?p=241","title":{"rendered":"inotify+rsync+shell\u811a\u672c\u5b9e\u73b0\u5b9e\u65f6\u6570\u636e\u540c\u6b65"},"content":{"rendered":"\n<p>\u5728\u751f\u4ea7\u73af\u5883\uff0c\u6709\u65f6\u4f1a\u9700\u8981\u4e24\u53f0\u4e3b\u673a\u7684\u7279\u5b9a\u76ee\u5f55\u5b9e\u73b0\u5b9e\u65f6\u540c\u6b65\u3002\u6bd4\u5982\uff0c\u5c06NFS\u5171\u4eab\u76ee\u5f55\u7684\u6570\u636e\u6587\u4ef6\uff0c\u81ea\u52a8\u5b9e\u65f6\u540c\u6b65\u5230\u5907\u4efd\u670d\u52a1\u5668\u7279\u5b9a\u76ee\u5f55\u4e2d\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"409\" height=\"207\" src=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/05\/20220527a1.jpg\" alt=\"\" class=\"wp-image-242\" srcset=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/05\/20220527a1.jpg 409w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/05\/20220527a1-300x152.jpg 300w\" sizes=\"auto, (max-width: 409px) 100vw, 409px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u65f6\u540c\u6b65\u6280\u672f\u4ecb\u7ecd<\/h2>\n\n\n\n<p>\u5b9e\u73b0\u5b9e\u65f6\u540c\u6b65\u7684\u65b9\u6cd5<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>inotify + rsync \u65b9\u5f0f\u5b9e\u73b0\u6570\u636e\u540c\u6b65<\/li><li>sersync \uff1a\u524d\u91d1\u5c71\u516c\u53f8\u5468\u6d0b\uff08\u82b1\u6912\u76f4\u64ad\uff09\u5728 inotify \u8f6f\u4ef6\u57fa\u7840\u4e0a\u8fdb\u884c\u5f00\u53d1\u7684\uff0c\u529f\u80fd\u66f4\u52a0\u5f3a\u5927<\/li><\/ul>\n\n\n\n<p>\u5de5\u4f5c\u539f\u7406\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5229\u7528\u76d1\u63a7\u670d\u52a1\uff08inotify\uff09\uff0c\u76d1\u63a7\u540c\u6b65\u6570\u636e\u670d\u52a1\u5668\u76ee\u5f55\u4e2d\u4fe1\u606f\u7684\u53d8\u5316<\/li><li>\u53d1\u73b0\u76ee\u5f55\u4e2d\u6570\u636e\u4ea7\u751f\u53d8\u5316\uff0c\u5c31\u5229\u7528rsync\u670d\u52a1\u63a8\u9001\u5230\u5907\u4efd\u670d\u52a1\u5668\u4e0a<\/li><\/ul>\n\n\n\n<p>inotify\uff1a<\/p>\n\n\n\n<p>\u5f02\u6b65\u7684\u6587\u4ef6\u7cfb\u7edf\u4e8b\u4ef6\u76d1\u63a7\u673a\u5236\uff0c\u5229\u7528\u4e8b\u4ef6\u9a71\u52a8\u673a\u5236\uff0c\u800c\u65e0\u987b\u901a\u8fc7\u8bf8\u5982cron\u7b49\u7684\u8f6e\u8be2\u673a\u5236\u6765\u83b7\u53d6\u4e8b\u4ef6\uff0clinux\u5185\u6838\u4ece2.6.13\u8d77\u652f\u6301 inotify\uff0c\u901a\u8fc7inotify\u53ef\u4ee5\u76d1\u63a7\u6587\u4ef6\u7cfb\u7edf\u4e2d\u6dfb\u52a0\u3001\u5220\u9664\uff0c\u4fee\u6539\u3001\u79fb\u52a8\u7b49\u5404\u79cd\u4e8b\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@DMIT-iJboSKPbP4:~# grep -i inotify \/boot\/config-5.4.0-113-generic \nCONFIG_INOTIFY_USER=y<\/code><\/pre>\n\n\n\n<p>\u5b9e\u73b0inotify\u8f6f\u4ef6\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>inotify-tools<\/li><li>sersync<\/li><li>lrsyncd<\/li><\/ul>\n\n\n\n<p>inotify+rsync\u4f7f\u7528\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>inotify \u5bf9\u540c\u6b65\u6570\u636e\u76ee\u5f55\u4fe1\u606f\u7684\u76d1\u63a7<\/li><li>rsync \u5b8c\u6210\u5bf9\u6570\u636e\u7684\u540c\u6b65<\/li><li>\u5229\u7528\u811a\u672c\u8fdb\u884c\u7ed3\u5408<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u73b0 inotify<\/h2>\n\n\n\n<p>\u5185\u6838\u662f\u5426\u652f\u6301inotify<\/p>\n\n\n\n<p>Linux\u652f\u6301inotify\u7684\u5185\u6838\u6700\u5c0f\u7248\u672c\u4e3a 2.6.13\uff0c\u53c2\u7167man 7 inotify\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u5217\u51fa\u4e0b\u9762\u7684\u6587\u4ef6\uff0c\u8bf4\u660e\u670d\u52a1\u5668\u5185\u6838\u652f\u6301inotify\n&#91;root@dmitproxy ~]#ls -l \/proc\/sys\/fs\/inotify\ntotal 0\n-rw-r--r-- 1 root root 0 May 27 01:32 max_queued_events\n-rw-r--r-- 1 root root 0 May 27 01:32 max_user_instances\n-rw-r--r-- 1 root root 0 May 27 01:32 max_user_watches\n\n&#91;root@dmitproxy ~]#cat \/proc\/sys\/fs\/inotify\/max_queued_events \n16384\n\n&#91;root@dmitproxy ~]#cat \/proc\/sys\/fs\/inotify\/max_user_instances \n128\n\n&#91;root@dmitproxy ~]#cat \/proc\/sys\/fs\/inotify\/max_user_watches\n8192<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0ainotify\u5185\u6838\u53c2\u6570\u8bf4\u660e\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>max_queued_events\uff1ainotify \u4e8b\u4ef6\u961f\u5217\u6700\u5927\u957f\u5ea6\uff08\u540c\u65f6\u53d1\u751f\u7684\u4e8b\u4ef6\uff09\uff0c\u5982\u503c\u592a\u5c0f\u4f1a\u51fa\u73b0 Event Queue Overflow \u9519\u8bef\uff0c\u9ed8\u8ba4\u503c\uff1a16384, \u751f\u4ea7\u73af\u5883\u5efa\u8bae\u8c03\u5927,\u6bd4\u5982:327679<\/li><li>max_user_instances\uff1a\u6bcf\u4e2a\u7528\u6237\u521b\u5efainotify\u5b9e\u4f8b\u6700\u5927\u503c\uff0c\u9ed8\u8ba4\u503c\uff1a128<\/li><li>max_user_watches\uff1a\u53ef\u4ee5\u76d1\u89c6\u7684\u6587\u4ef6\u7684\u603b\u6570\u91cf\uff08inotifywait \u5355\u8fdb\u7a0b\uff09\uff0c\u9ed8\u8ba4\u503c\uff1a8192,\u5efa\u8bae\u8c03\u5927<\/li><\/ul>\n\n\n\n<p>\u5982\u4f55\u4fee\u6539inotify\u5185\u6838\u53c2\u6570:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/sysctl.conf\n\n#\u5728\u914d\u7f6e\u6587\u4ef6\u6700\u540e\u9644\u52a0\u4e24\u884c\nfs.inotify.max_queued_events=327679\nfs.inotify.max_user_watches=100000\n\n#\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\nsysctl -p\n\n#\u89c2\u5bdf\u521a\u624d\u7684\u503c\u6709\u6ca1\u6709\u53d8\u5316\n&#91;root@dmitproxy ~]#cat \/proc\/sys\/fs\/inotify\/*\n327679\n128\n100000<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">inotify-tools\u5de5\u5177<\/h2>\n\n\n\n<p>\u5de5\u5177\u57fa\u4e8eepel\u6e90<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#centos\u5b89\u88c5\nyum -y install inotify-tools\n#ubuntu\u5b89\u88c5\napt -y install inotify-tools<\/code><\/pre>\n\n\n\n<p>inotify-tools\u5305\u4e3b\u8981\u5de5\u5177\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>inotifywait\uff1a \u5728\u88ab\u76d1\u63a7\u7684\u6587\u4ef6\u6216\u76ee\u5f55\u4e0a\u7b49\u5f85\u7279\u5b9a\u6587\u4ef6\u7cfb\u7edf\u4e8b\u4ef6\uff08open \uff0cclose\uff0cdelete\u7b49\uff09\u53d1\u751f\uff0c\u5e38\u7528\u4e8e\u5b9e\u65f6\u540c\u6b65\u7684\u76ee\u5f55\u76d1\u63a7\u3002<\/li><li>inotifywatch\uff1a\u6536\u96c6\u88ab\u76d1\u63a7\u7684\u6587\u4ef6\u7cfb\u7edf\u4f7f\u7528\u7684\u7edf\u8ba1\u6570\u636e\uff0c\u6307\u6587\u4ef6\u7cfb\u7edf\u4e8b\u4ef6\u53d1\u751f\u7684\u6b21\u6570\u7edf\u8ba1\u3002<\/li><\/ul>\n\n\n\n<p><em>\u7b80\u800c\u8a00\u4e4b\u5c31\u662fwait\u7edf\u8ba1\u53d8\u5316\uff0cwatch\u7edf\u8ba1\u6570\u5b57\u3002<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">inotifywait \u547d\u4ee4<\/h2>\n\n\n\n<p>\u683c\u5f0f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>inotifywait &#91; options ] file1 &#91; file2 ] &#91; file3 ] &#91; ... ]<\/code><\/pre>\n\n\n\n<p>\u5e38\u7528\u9009\u9879:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-m, --monitor \u59cb\u7ec8\u4fdd\u6301\u4e8b\u4ef6\u76d1\u542c\n-d, --daemon \u4ee5\u5b88\u62a4\u8fdb\u7a0b\u65b9\u5f0f\u6267\u884c\uff0c\u548c-m\u76f8\u4f3c\uff0c\u914d\u5408-o\u4f7f\u7528\n-r, --recursive \u9012\u5f52\u76d1\u63a7\u76ee\u5f55\u6570\u636e\u4fe1\u606f\u53d8\u5316\n-q, --quiet \u8f93\u51fa\u5c11\u91cf\u4e8b\u4ef6\u4fe1\u606f\uff0c\u4e5f\u5c31\u662f\u4e0d\u4f1a\u8f93\u51fa\u5f00\u5934\u90a3\u4e24\u53e5\u8bdd\n--exclude &lt;pattern&gt; \u6307\u5b9a\u6392\u9664\u6587\u4ef6\u6216\u76ee\u5f55\uff0c\u4f7f\u7528\u6269\u5c55\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u7684\u6a21\u5f0f\u5b9e\u73b0\n--excludei &lt;pattern&gt; \u548cexclude\u76f8\u4f3c\uff0c\u4e0d\u533a\u5206\u5927\u5c0f\u5199\n-o, --outfile &lt;file&gt; \u6253\u5370\u4e8b\u4ef6\u5230\u6587\u4ef6\u4e2d\uff0c\u76f8\u5f53\u4e8e\u6807\u51c6\u6b63\u786e\u8f93\u51fa\uff0c\u6ce8\u610f\uff1a\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\n-s, --syslogOutput \u53d1\u9001\u9519\u8bef\u5230syslog\u76f8\u5f53\u4e8e\u6807\u51c6\u9519\u8bef\u8f93\u51fa\n--timefmt &lt;fmt&gt; \u6307\u5b9a\u65f6\u95f4\u8f93\u51fa\u683c\u5f0f\uff0c\u4f9d\u8d56\u4e8e--format\u9009\u9879\n--format &lt;fmt&gt; \u6307\u5b9a\u7684\u8f93\u51fa\u683c\u5f0f\uff1b\u5373\u5b9e\u9645\u76d1\u63a7\u8f93\u51fa\u5185\u5bb9\n-e \u6307\u5b9a\u76d1\u542c\u6307\u5b9a\u7684\u4e8b\u4ef6\uff0c\u5982\u679c\u7701\u7565\uff0c\u8868\u793a\u6240\u6709\u4e8b\u4ef6\u90fd\u8fdb\u884c\u76d1\u542c<\/code><\/pre>\n\n\n\n<p>inotifywait \u7684&#8211;timefmt \u65f6\u95f4\u683c\u5f0f<\/p>\n\n\n\n<p>\u53c2\u8003\uff1aman 3 strftime<\/p>\n\n\n\n<p>\u6b64\u9009\u9879\u5fc5\u987b\u914d\u5408&#8211;format\u4e00\u8d77\u4f7f\u7528<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>%Y #\u5e74\u4efd\u4fe1\u606f\uff0c\u5305\u542b\u4e16\u7eaa\u4fe1\u606f\uff0c\u6bd4\u59822022\n%y #\u5e74\u4efd\u4fe1\u606f\uff0c\u4e0d\u5305\u62ec\u4e16\u7eaa\u4fe1\u606f\uff0c\u6bd4\u598222\n%m #\u663e\u793a\u6708\u4efd\uff0c\u8303\u56f4 01-12\n%d #\u6bcf\u6708\u7684\u7b2c\u51e0\u5929\uff0c\u8303\u56f4\u662f 01-31\n%H #\u5c0f\u65f6\u4fe1\u606f\uff0c\u4f7f\u7528 24\u5c0f\u65f6\u5236\uff0c\u8303\u56f4 00-23\n%M #\u5206\u949f\uff0c\u8303\u56f4 00-59\n%S #\u79d2\uff0c\u8303\u4f8b 0-60<\/code><\/pre>\n\n\n\n<p>inotifywait \u7684 &#8211;format \u683c\u5f0f\u5b9a\u4e49<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>%T #\u8f93\u51fa\u65f6\u95f4\u683c\u5f0f\u4e2d\u5b9a\u4e49\u7684\u65f6\u95f4\u683c\u5f0f\u4fe1\u606f\uff0c\u901a\u8fc7 --timefmt option \u8bed\u6cd5\u683c\u5f0f\u6307\u5b9a\u65f6\u95f4\u4fe1\u606f\n%w #\u4e8b\u4ef6\u51fa\u73b0\u65f6\uff0c\u76d1\u63a7\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u540d\u79f0\u4fe1\u606f\uff0c\u76f8\u5f53\u4e8edirname\n%f #\u4e8b\u4ef6\u51fa\u73b0\u65f6\uff0c\u5c06\u663e\u793a\u76d1\u63a7\u76ee\u5f55\u4e0b\u89e6\u53d1\u4e8b\u4ef6\u7684\u6587\u4ef6\u6216\u76ee\u5f55\u4fe1\u606f\uff0c\u5426\u5219\u4e3a\u7a7a\uff0c\u76f8\u5f53\u4e8ebasename\n%e #\u663e\u793a\u53d1\u751f\u7684\u4e8b\u4ef6\u4fe1\u606f\uff0c\u4e0d\u540c\u7684\u4e8b\u4ef6\u9ed8\u8ba4\u7528\u9017\u53f7\u5206\u9694\n%Xe #\u663e\u793a\u53d1\u751f\u7684\u4e8b\u4ef6\u4fe1\u606f\uff0c\u4e0d\u540c\u7684\u4e8b\u4ef6\u6307\u5b9a\u7528X\u8fdb\u884c\u5206\u9694<\/code><\/pre>\n\n\n\n<p>inotifywait -e \u9009\u9879\u6307\u5b9a\u7684\u4e8b\u4ef6\u7c7b\u578b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>create #\u6587\u4ef6\u6216\u76ee\u5f55\u521b\u5efa\ndelete #\u6587\u4ef6\u6216\u76ee\u5f55\u88ab\u5220\u9664\nmodify #\u6587\u4ef6\u6216\u76ee\u5f55\u5185\u5bb9\u88ab\u5199\u5165\nattrib #\u6587\u4ef6\u6216\u76ee\u5f55\u5c5e\u6027\u6539\u53d8\nclose_write #\u6587\u4ef6\u6216\u76ee\u5f55\u5173\u95ed\uff0c\u5728\u5199\u5165\u6a21\u5f0f\u6253\u5f00\u4e4b\u540e\u5173\u95ed\u7684\nclose_nowrite #\u6587\u4ef6\u6216\u76ee\u5f55\u5173\u95ed\uff0c\u5728\u53ea\u8bfb\u6a21\u5f0f\u6253\u5f00\u4e4b\u540e\u5173\u95ed\u7684\nclose #\u6587\u4ef6\u6216\u76ee\u5f55\u5173\u95ed\uff0c\u4e0d\u7ba1\u8bfb\u6216\u662f\u5199\u6a21\u5f0f\nopen #\u6587\u4ef6\u6216\u76ee\u5f55\u88ab\u6253\u5f00\nlsdir #\u6d4f\u89c8\u76ee\u5f55\u5185\u5bb9\nmoved_to #\u6587\u4ef6\u6216\u76ee\u5f55\u88ab\u79fb\u52a8\u5230\u76d1\u63a7\u7684\u76ee\u5f55\u4e2d\nmoved_from #\u6587\u4ef6\u6216\u76ee\u5f55\u4ece\u76d1\u63a7\u7684\u76ee\u5f55\u4e2d\u88ab\u79fb\u52a8\nmove #\u6587\u4ef6\u6216\u76ee\u5f55\u4e0d\u7ba1\u79fb\u52a8\u5230\u6216\u662f\u79fb\u51fa\u76d1\u63a7\u76ee\u5f55\u90fd\u89e6\u53d1\u4e8b\u4ef6\naccess #\u6587\u4ef6\u6216\u76ee\u5f55\u5185\u5bb9\u88ab\u8bfb\u53d6\ndelete_self #\u6587\u4ef6\u6216\u76ee\u5f55\u88ab\u5220\u9664\uff0c\u76ee\u5f55\u672c\u8eab\u88ab\u5220\u9664\nunmount #\u53d6\u6d88\u6302\u8f7d<\/code><\/pre>\n\n\n\n<p>\u8303\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>inotifywait -mr \/data --format \"%T %w %f %e\" --timefmt \"%y-%m-%d %H-%M-%S\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">rsync<\/h2>\n\n\n\n<p>rsync \u5e38\u7528\u4e8e\u505a\u4e3a linux\u7cfb\u7edf\u4e0b\u7684\u6570\u636e\u955c\u50cf\u5907\u4efd\u5de5\u5177\uff0c\u5b9e\u73b0\u8fdc\u7a0b\u540c\u6b65\uff0c\u652f\u6301\u672c\u5730\u590d\u5236\uff0c\u6216\u8005\u4e0e\u5176\u4ed6SSH\u3001rsync\u4e3b\u673a\u540c\u6b65\u6570\u636e\uff0c\u652f\u6301\u589e\u91cf\u5907\u4efd\uff0c\u914d\u5408\u4efb\u52a1\u8ba1\u5212\uff0crsync\u80fd\u5b9e\u73b0\u5b9a\u65f6\u6216\u95f4\u9694\u540c\u6b65\uff0c\u914d\u5408inotify\u6216sersync\uff0c\u53ef\u4ee5\u5b9e\u73b0\u89e6\u53d1\u5f0f\u7684\u5b9e\u65f6\u6570\u636e\u540c\u6b65\u3002<\/p>\n\n\n\n<p>\u8f6f\u4ef6\u5305\uff1arsync<\/p>\n\n\n\n<p>\u670d\u52a1\u6587\u4ef6\uff1a\/lib\/systemd\/system\/rsync.service<\/p>\n\n\n\n<p>\u914d\u7f6e\u6587\u4ef6\uff1a\/etc\/rsyncd.conf<\/p>\n\n\n\n<p>\u7aef\u53e3\uff1a873\/TCP<\/p>\n\n\n\n<p><strong>rsync\u6709\u4e09\u79cd\u5de5\u4f5c\u65b9\u5f0f\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\u4e0a\u5b9e\u73b0\u540c\u6b65\u3002\u547d\u4ee4\u884c\u8bed\u6cd5\u683c\u5f0f\u4e3a&#8221;Local&#8221;\u6bb5\u7684\u683c\u5f0f\u3002<\/li><li>\u672c\u5730\u4e3b\u673a\u4f7f\u7528\u8fdc\u7a0bshell\u548c\u8fdc\u7a0b\u4e3b\u673a\u901a\u4fe1\u3002\u547d\u4ee4\u884c\u8bed\u6cd5\u683c\u5f0f\u4e3a&#8221;Access via remote shell&#8221;\u6bb5\u7684\u683c\u5f0f\u3002<\/li><li>\u672c\u5730\u4e3b\u673a\u901a\u8fc7\u7f51\u7edc\u5957\u63a5\u5b57\u8fde\u63a5\u8fdc\u7a0b\u4e3b\u673a\u4e0a\u7684rsync daemon\u3002\u547d\u4ee4\u884c\u8bed\u6cd5\u683c\u5f0f\u4e3a&#8221;Access viarsync daemon&#8221;\u6bb5\u7684\u683c\u5f0f\u3002 <em>\u524d\u4e24\u8005\u7684\u672c\u8d28\u662f\u901a\u8fc7\u672c\u5730\u6216\u8fdc\u7a0bshell\uff0c\u800c\u7b2c3\u79cd\u65b9\u5f0f\u5219\u662f\u8ba9\u8fdc\u7a0b\u4e3b\u673a\u4e0a\u8fd0\u884crsyncd\u670d\u52a1\uff0c\u4f7f\u5176\u76d1\u542c\u5728\u4e00\u4e2a\u7aef\u53e3\u4e0a\uff0c\u7b49\u5f85\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u3002<\/em><\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>rsync\u547d\u4ee4<\/strong><\/h2>\n\n\n\n<p>\u547d\u4ee4\u7528\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Local:\nrsync &#91;OPTION...] SRC... &#91;DEST]\n\n#Access via remote shell\n#Pull:\nrsync &#91;OPTION...] &#91;USER@]HOST:SRC... &#91;DEST]\n#Push:\nrsync &#91;OPTION...] SRC... &#91;USER@]HOST:DEST\n\n#Access via rsync daemon:\nPull:\nrsync &#91;OPTION...] &#91;USER@]HOST::SRC... &#91;DEST]\nrsync &#91;OPTION...] rsync:\/\/&#91;USER@]HOST&#91;:PORT]\/SRC... &#91;DEST]\nPush:\nrsync &#91;OPTION...] SRC... &#91;USER@]HOST::DEST\nrsync &#91;OPTION...] SRC... rsync:\/\/&#91;USER@]HOST&#91;:PORT]\/DEST<\/code><\/pre>\n\n\n\n<p>\u5e38\u89c1\u9009\u9879\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-v\uff1a\u663e\u793arsync\u8fc7\u7a0b\u4e2d\u8be6\u7ec6\u4fe1\u606f\u3002\u53ef\u4ee5\u4f7f\u7528\"-vvvv\"\u83b7\u53d6\u66f4\u8be6\u7ec6\u4fe1\u606f\u3002\n-P\uff1a\u663e\u793a\u6587\u4ef6\u4f20\u8f93\u7684\u8fdb\u5ea6\u4fe1\u606f\u3002(\u5b9e\u9645\u4e0a\"-P\"=\"--partial --progress\"\uff0c\u5176\u4e2d\u7684\"--progress\"\u624d\u662f\u663e\n\u793a\u8fdb\u5ea6\u4fe1\u606f\u7684)\u3002\n-n --dry-run \uff1a\u4ec5\u6d4b\u8bd5\u4f20\u8f93\uff0c\u800c\u4e0d\u5b9e\u9645\u4f20\u8f93\u3002\u5e38\u548c\"-vvvv\"\u914d\u5408\u4f7f\u7528\u6765\u67e5\u770brsync\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002\n-a --archive \uff1a\u5f52\u6863\u6a21\u5f0f\uff0c\u8868\u793a\u9012\u5f52\u4f20\u8f93\u5e76\u4fdd\u6301\u6587\u4ef6\u5c5e\u6027\u3002\u7b49\u540c\u4e8e\"-rtopgDl\"\u3002\n-r --recursive\uff1a\u9012\u5f52\u5230\u76ee\u5f55\u4e2d\u53bb\u3002\n-t --times\uff1a\u4fdd\u6301mtime\u5c5e\u6027\u3002\u5f3a\u70c8\u5efa\u8bae\u4efb\u4f55\u65f6\u5019\u90fd\u52a0\u4e0a\"-t\"\uff0c\u5426\u5219\u76ee\u6807\u6587\u4ef6mtime\u4f1a\u8bbe\u7f6e\u4e3a\u7cfb\u7edf\u65f6\u95f4\uff0c\u5bfc\u81f4\u4e0b\u6b21\u66f4\u65b0\u68c0\u67e5\u51famtime\u4e0d\u540c\u4ece\u800c\u5bfc\u81f4\u589e\u91cf\u4f20\u8f93\u65e0\u6548\u3002\n-o --owner\uff1a\u4fdd\u6301owner\u5c5e\u6027(\u5c5e\u4e3b)\u3002\n-g --group\uff1a\u4fdd\u6301group\u5c5e\u6027(\u5c5e\u7ec4)\u3002\n-p --perms\uff1a\u4fdd\u6301perms\u5c5e\u6027(\u6743\u9650\uff0c\u4e0d\u5305\u62ec\u7279\u6b8a\u6743\u9650)\u3002\n-D \uff1a\u662f\"--device --specials\"\u9009\u9879\u7684\u7ec4\u5408\uff0c\u5373\u4e5f\u62f7\u8d1d\u8bbe\u5907\u6587\u4ef6\u548c\u7279\u6b8a\u6587\u4ef6\u3002\n-l --links\uff1a\u5982\u679c\u6587\u4ef6\u662f\u8f6f\u94fe\u63a5\u6587\u4ef6\uff0c\u5219\u62f7\u8d1d\u8f6f\u94fe\u63a5\u672c\u8eab\u800c\u975e\u8f6f\u94fe\u63a5\u6240\u6307\u5411\u7684\u5bf9\u8c61\n-z \uff1a\u4f20\u8f93\u65f6\u8fdb\u884c\u538b\u7f29\u63d0\u9ad8\u6548\u7387\n-R --relative\uff1a\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84\u3002\u610f\u5473\u7740\u5c06\u547d\u4ee4\u884c\u4e2d\u6307\u5b9a\u7684\u5168\u8def\u5f84\u800c\u975e\u8def\u5f84\u6700\u5c3e\u90e8\u7684\u6587\u4ef6\u540d\u53d1\u9001\u7ed9\u670d\u52a1\u7aef\uff0c\u5305\u62ec\u5b83\u4eec\u7684\u5c5e\u6027\u3002\u7528\u6cd5\u89c1\u4e0b\u6587\u793a\u4f8b\u3002\n--size-only \uff1a\u9ed8\u8ba4\u7b97\u6cd5\u662f\u68c0\u67e5\u6587\u4ef6\u5927\u5c0f\u548cmtime\u4e0d\u540c\u7684\u6587\u4ef6\uff0c\u4f7f\u7528\u6b64\u9009\u9879\u5c06\u53ea\u68c0\u67e5\u6587\u4ef6\u5927\u5c0f\u3002\n-u --update \uff1a\u4ec5\u5728\u6e90mtime\u6bd4\u76ee\u6807\u5df2\u5b58\u5728\u6587\u4ef6\u7684mtime\u65b0\u65f6\u624d\u62f7\u8d1d\u3002\u6ce8\u610f\uff0c\u8be5\u9009\u9879\u662f\u63a5\u6536\u7aef\u5224\u65ad\u7684\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5220\u9664\u884c\u4e3a\u3002\n-d --dirs \uff1a\u4ee5\u4e0d\u9012\u5f52\u7684\u65b9\u5f0f\u62f7\u8d1d\u76ee\u5f55\u672c\u8eab\u3002\u9ed8\u8ba4\u9012\u5f52\u65f6\uff0c\u5982\u679c\u6e90\u4e3a\"dir1\/file1\"\uff0c\u5219\u4e0d\u4f1a\u62f7\u8d1ddir1\u76ee\u5f55\uff0c\u4f7f\u7528\u8be5\u9009\u9879\u5c06\u62f7\u8d1ddir1\u4f46\u4e0d\u62f7\u8d1dfile1\u3002\n--max-size \uff1a\u9650\u5236rsync\u4f20\u8f93\u7684\u6700\u5927\u6587\u4ef6\u5927\u5c0f\u3002\u53ef\u4ee5\u4f7f\u7528\u5355\u4f4d\u540e\u7f00\uff0c\u8fd8\u53ef\u4ee5\u662f\u4e00\u4e2a\u5c0f\u6570\u503c(\u4f8b\u5982\uff1a\"--max-size=1.5m\")\n--min-size \uff1a\u9650\u5236rsync\u4f20\u8f93\u7684\u6700\u5c0f\u6587\u4ef6\u5927\u5c0f\u3002\u8fd9\u53ef\u4ee5\u7528\u4e8e\u7981\u6b62\u4f20\u8f93\u5c0f\u6587\u4ef6\u6216\u90a3\u4e9b\u5783\u573e\u6587\u4ef6\u3002\n--exclude \uff1a\u6307\u5b9a\u6392\u9664\u89c4\u5219\u6765\u6392\u9664\u4e0d\u9700\u8981\u4f20\u8f93\u7684\u6587\u4ef6\u3002\n--delete \uff1a\u4ee5SRC\u4e3a\u4e3b\uff0c\u5bf9DEST\u8fdb\u884c\u540c\u6b65\u3002\u591a\u5219\u5220\u4e4b\uff0c\u5c11\u5219\u8865\u4e4b\u3002\u6ce8\u610f\"--delete\"\u662f\u5728\u63a5\u6536\u7aef\u6267\u884c\u7684\uff0c\u6240\u4ee5\u5b83\u662f\u5728exclude\/include\u89c4\u5219\u751f\u6548\u4e4b\u540e\u624d\u6267\u884c\u7684\u3002\n-b --backup \uff1a\u5bf9\u76ee\u6807\u4e0a\u5df2\u5b58\u5728\u7684\u6587\u4ef6\u505a\u4e00\u4e2a\u5907\u4efd\uff0c\u5907\u4efd\u7684\u6587\u4ef6\u540d\u540e\u9ed8\u8ba4\u4f7f\u7528\"~\"\u505a\u540e\u7f00\u3002\n--backup-dir\uff1a\u6307\u5b9a\u5907\u4efd\u6587\u4ef6\u7684\u4fdd\u5b58\u8def\u5f84\u3002\u4e0d\u6307\u5b9a\u65f6\u9ed8\u8ba4\u548c\u5f85\u5907\u4efd\u6587\u4ef6\u4fdd\u5b58\u5728\u540c\u4e00\u76ee\u5f55\u4e0b\u3002\n-e \uff1a\u6307\u5b9a\u6240\u8981\u4f7f\u7528\u7684\u8fdc\u7a0bshell\u7a0b\u5e8f\uff0c\u9ed8\u8ba4\u4e3assh\u3002\n--port \uff1a\u8fde\u63a5daemon\u65f6\u4f7f\u7528\u7684\u7aef\u53e3\u53f7\uff0c\u9ed8\u8ba4\u4e3a873\u7aef\u53e3\u3002\n--password-file\uff1adaemon\u6a21\u5f0f\u65f6\u7684\u5bc6\u7801\u6587\u4ef6\uff0c\u53ef\u4ee5\u4ece\u4e2d\u8bfb\u53d6\u5bc6\u7801\u5b9e\u73b0\u975e\u4ea4\u4e92\u5f0f\u3002\u6ce8\u610f\uff0c\u8fd9\u4e0d\u662f\u8fdc\u7a0bshell\u8ba4\u8bc1\u7684\u5bc6\u7801\uff0c\u800c\u662frsync\u6a21\u5757\u8ba4\u8bc1\u7684\u5bc6\u7801\u3002\n-W --whole-file\uff1arsync\u5c06\u4e0d\u518d\u4f7f\u7528\u589e\u91cf\u4f20\u8f93\uff0c\u800c\u662f\u5168\u91cf\u4f20\u8f93\u3002\u5728\u7f51\u7edc\u5e26\u5bbd\u9ad8\u4e8e\u78c1\u76d8\u5e26\u5bbd\u65f6\uff0c\u8be5\u9009\u9879\u6bd4\u589e\n\u91cf\u4f20\u8f93\u66f4\u9ad8\u6548\u3002\n--existing \uff1a\u8981\u6c42\u53ea\u66f4\u65b0\u76ee\u6807\u7aef\u5df2\u5b58\u5728\u7684\u6587\u4ef6\uff0c\u76ee\u6807\u7aef\u8fd8\u4e0d\u5b58\u5728\u7684\u6587\u4ef6\u4e0d\u4f20\u8f93\u3002\u6ce8\u610f\uff0c\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84\u65f6\u5982\u679c\u4e0a\u5c42\u76ee\u5f55\u4e0d\u5b58\u5728\u4e5f\u4e0d\u4f1a\u4f20\u8f93\u3002\n--ignore-existing\uff1a\u8981\u6c42\u53ea\u66f4\u65b0\u76ee\u6807\u7aef\u4e0d\u5b58\u5728\u7684\u6587\u4ef6\u3002\u548c\"--existing\"\u7ed3\u5408\u4f7f\u7528\u6709\u7279\u6b8a\u529f\u80fd\uff0c\u89c1\u4e0b\u6587\u793a\u4f8b\u3002\n--remove-source-files\uff1a\u8981\u6c42\u5220\u9664\u6e90\u7aef\u5df2\u7ecf\u6210\u529f\u4f20\u8f93\u7684\u6587\u4ef6<\/code><\/pre>\n\n\n\n<p>\u6848\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u5907\u4efd\u7f51\u7ad9\u5230\u672c\u5730\nrsync -a \/var\/www\/html \/backup\/\n\n#\u5907\u4efd\u7f51\u7ad9\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\uff08\u5efa\u8bae\u63d0\u524d\u505a\u514d\u5bc6SSH\u767b\u5f55\uff09\nrsync -a \/var\/www\/html 154.3.32.85:\/backup\/\n\n#\u4f7f\u7528rsync\u670d\u52a1\u7684\u65b9\u5f0f\u5907\u4efd\n#\u9996\u5148\u5728\u5907\u4efd\u670d\u52a1\u5668\u521b\u5efa\u914d\u7f6e\u6587\u4ef6\nvim \/etc\/rsyncd.conf\n#\u914d\u7f6e\u7528\u6237\u5b58\u653e\u5907\u4efd\u7684\u76ee\u5f55\nuid = root\ngid = root\nlog file = \/var\/log\/rsyncd.log\npid file = \/var\/run\/rsyncd.pid\nlock file = \/var\/run\/rsyncd.lock\nreverse lookup = no\nhosts allow = 154.17.6.123  #\u8fd9\u91ccIP\u6362\u6210\u4f60\u7684\u6570\u636e\u670d\u52a1\u5668\u5730\u5740\n&#91;backup]                    #\u6a21\u5757\u540d\npath=\/backup\ncomment = backup dir\nread only = no\n\n#\u4fdd\u5b58\u5e76\u91cd\u542f\u670d\u52a1\nsystemctl restart rsync\n\n#\u5728\u6570\u636e\u670d\u52a1\u5668\u8fdc\u7a0b\u67e5\u770b\u5907\u4efd\u670d\u52a1\u5668\u7684\u76ee\u5f55\nrsync rsync:\/\/154.3.32.85\/backup \n\n#\u5907\u4efd\u7f51\u7ad9\u6570\u636e\uff08\u6211\u8fd9\u91cc\u5df2\u505a\u514d\u5bc6\u9a8c\u8bc1\uff09\nrsync -a \/var\/www\/html rsync:\/\/154.3.32.85\/backup<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">inotify+rsync+shell \u811a\u672c\u5b9e\u73b0\u5b9e\u65f6\u6570\u636e\u540c\u6b65<\/h2>\n\n\n\n<p>\u9996\u5148\u6309\u7167\u4e0a\u9762\u7684\u914d\u7f6e\u6587\u4ef6\u642d\u5efa\u597drsync\u7684\u5907\u4efd\u670d\u52a1\u5668<\/p>\n\n\n\n<p>\u7136\u540e\u5728\u6570\u636e\u670d\u52a1\u5668\u4e0a\u521b\u5efainotify_rsync.sh\u811a\u672c<\/p>\n\n\n\n<p><em>\u6b64\u811a\u672c\u6267\u884c\u524d\u5148\u786e\u4fdd\u4e24\u4e3b\u673a\u521d\u59cb\u6570\u636e\u5904\u4e8e\u540c\u6b65\u72b6\u6001,\u6b64\u811a\u672c\u5b9e\u73b0\u540e\u7eed\u7684\u6570\u636e\u540c\u6b65<\/em><\/p>\n\n\n\n<p>\u811a\u672c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n#****************************************\n#Author: \u5c0f\u9752\u86d9\n#Mail: yizhiputao@gmail.com\n#Date: 2022-05-27\n#FileName\uff1a inotify_rsync.sh\n#URL: https:\/\/vpsfrog.com\n#Description\uff1a The backup script\n#****************************************\n#\u9700\u8981\u5b9e\u65f6\u5907\u4efd\u7684\u7f51\u7ad9\u76ee\u5f55\uff0c\u6ce8\u610f\u540e\u9762\u7684\/\nSRC=\"\/var\/www\/\"\n#\u5907\u4efd\u670d\u52a1\u5668\u7684\u5730\u5740::\u6a21\u5757\u540d\nDEST=\"154.3.32.85::backup\"\ninotifywait -mrq --exclude=\".*\\.swp\" --timefmt=\"%Y-%m-%d %H:%M:%S\" --format \"%T %w %f\" -e create,delete,moved_to,close_write,attrib ${SRC} |while read DATE TIME DIR FILE;do\n  FILEPATH=${DIR}${FILE}\n  rsync -az --delete ${SRC} ${DEST} &amp;&amp; echo \"At ${TIME} on ${DATE},file ${FILEPATH} was backuped via rsync\" &gt;&gt; \/var\/log\/backup.log \ndone<\/code><\/pre>\n\n\n\n<p>\u6ce8\uff1a\u4f7f\u7528\u4ee5\u4e0a\u811a\u672c\u5907\u4efd\u65f6IP\u5730\u5740\u540e\u9762\u53ea\u9700\u8981\u8ddf\u6a21\u5757\u540d\uff0c\u800c\u4e0d\u662f\u8def\u5f84\/\uff0c\u5426\u5219\u4f1a\u770b\u5230\u4ee5\u4e0b\u62a5\u9519<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> ERROR: The remote path must start with a module name not a \/<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u751f\u4ea7\u73af\u5883\uff0c\u6709\u65f6\u4f1a\u9700\u8981\u4e24\u53f0\u4e3b\u673a\u7684\u7279\u5b9a\u76ee\u5f55\u5b9e\u73b0\u5b9e\u65f6\u540c\u6b65\u3002\u6bd4\u5982\uff0c\u5c06NFS\u5171\u4eab\u76ee\u5f55\u7684\u6570\u636e\u6587\u4ef6\uff0c\u81ea\u52a8\u5b9e\u65f6\u540c\u6b65\u5230\u5907\u4efd\u670d\u52a1\u5668\u7279\u5b9a\u76ee\u5f55\u4e2d\u3002 \u5b9e\u65f6\u540c\u6b65\u6280\u672f\u4ecb\u7ecd \u5b9e\u73b0\u5b9e\u65f6\u540c\u6b65\u7684\u65b9\u6cd5 inotify + rsync \u65b9\u5f0f\u5b9e\u73b0\u6570\u636e\u540c\u6b65 sersync \uff1a\u524d\u91d1\u5c71\u516c&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[39,40],"topic":[],"class_list":["post-241","post","type-post","status-publish","format-standard","hentry","category-linux","tag-rsync","tag-40"],"_links":{"self":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=241"}],"version-history":[{"count":3,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/241\/revisions"}],"predecessor-version":[{"id":245,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/241\/revisions\/245"}],"wp:attachment":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=241"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}