{"id":53809,"date":"2023-06-15T22:19:14","date_gmt":"2023-06-15T14:19:14","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=53809"},"modified":"2023-06-15T22:19:14","modified_gmt":"2023-06-15T14:19:14","slug":"linux-rsync-backup","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-rsync-backup.html","title":{"rendered":"Linux\u4e0b\u5b9e\u73b0\u6587\u4ef6\u5907\u4efd\u7684\u65b9\u6cd5"},"content":{"rendered":"

\u8fd9\u7bc7\u6765\u8bf4\u8bf4\u5982\u4f55\u5b89\u5168\u7684\u5907\u4efd\uff0c\u8fd9\u91cc\u8981\u8bb2\u7684\u662f\u4e3b\u670d\u52a1\u5668\u5982\u4f55\u63a8\u9001\u6570\u636e\u5b9e\u73b0\u5907\u4efd\u3002<\/strong><\/p>\n

\u4e00\u3001\u5907\u4efd\u670d\u52a1\u5668\u914d\u7f6ersync\u6587\u4ef6 vi \/etc\/rsyncd.conf<\/strong><\/div>\n
#\u5de5\u4f5c\u4e2d\u6307\u5b9a\u7528\u6237(\u53ef\u4ee5\u4e0d\u6307\u5b9a\u4e3a0)\r\nuid = 0\r\ngid = 0\r\n#\u76f8\u5f53\u4e8e\u9ed1\u6d1e.\u51fa\u9519\u5b9a\u4f4d\r\nuse chroot = no\r\n#\u6709\u591a\u5c11\u4e2a\u5ba2\u6237\u7aef\u540c\u65f6\u4f20\u6587\u4ef6\r\nmax connections = 200\r\n#\u8d85\u65f6\u65f6\u95f4\r\ntimeout = 300\r\n#\u8fdb\u7a0b\u53f7\u6587\u4ef6\r\npid file = \/var\/run\/rsyncd.pid\r\n#\u65e5\u5fd7\u6587\u4ef6\r\nlock file = \/var\/run\/rsync.lock\r\n#\u65e5\u5fd7\u6587\u4ef6\r\nlog file = \/var\/log\/rsyncd.log\r\n#\u6a21\u5757\u5f00\u59cb\r\n#\u6a21\u5757\u540d\u79f0\u968f\u4fbf\u8d77\uff08\u53ef\u4ee5\u662f\u591a\u4e2a\uff09\r\n[backup]\r\n#\u9700\u8981\u5907\u4efd\u7684\u76ee\u5f55\r\npath = \/backup\r\n#\u8868\u793a\u51fa\u73b0\u9519\u8bef\u5ffd\u7565\u9519\u8bef\r\nignore errors\r\n#\u8868\u793a\u7f51\u7edc\u6743\u9650\u53ef\u5199(\u672c\u5730\u63a7\u5236\u771f\u6b63\u53ef\u5199)\r\nread only = false\r\n#\u8fd9\u91cc\u8bbe\u7f6eIP\u6216\u8ba9\u4e0d\u8ba9\u540c\u6b65\r\nlist = false\r\n#\u6307\u5b9a\u5141\u8bb8\u7684\u7f51\u6bb5\r\nhosts allow = 192.168.1.0\/24\r\n#\u62d2\u7edd\u94fe\u63a5\u7684\u5730\u5740\uff0c\u4e00\u4e0b\u8868\u793a\u6ca1\u6709\u62d2\u7edd\u7684\u94fe\u63a5\u3002\r\nhosts deny = 0.0.0.0\/32\r\n#\u4e0d\u8981\u52a8\u7684\u4e1c\u897f(\u9ed8\u8ba4\u60c5\u51b5)\r\n#\u865a\u62df\u7528\u6237\r\nauth users = rsync_backup\r\n#\u865a\u62df\u7528\u6237\u7684\u5bc6\u7801\u6587\u4ef6\r\nsecrets file = \/etc\/rsync.password<\/pre>\n
\u4e8c\u3001\u5907\u4efd\u670d\u52a1\u5668\u914d\u7f6e\u865a\u62df\u7528\u6237\u7684\u5bc6\u7801\u6587\u4ef6<\/strong><\/div>\n
[root@slave \/]# echo \"rsync_backup:123456\" >\/etc\/rsync.password\r\n[root@slave \/]# cat \/etc\/rsync.password\r\nrsync_backup:123456 #\u6ce8\uff1arsync_backup\u4e3a\u865a\u62df\u7528\u6237\uff0c123456\u4e3a\u8fd9\u4e2a\u865a\u62df\u7528\u6237\u7684\u5bc6\u7801\r\n[root@inotify-slave \/]# chmod 600 \/etc\/rsync.password #\u4e3a\u5bc6\u7801\u6587\u4ef6\u63d0\u6743\uff0c\u589e\u52a0\u5b89\u5168\u6027<\/pre>\n
\u4e09\u3001\u4e3b\u670d\u52a1\u5668\u914d\u7f6e\u865a\u62df\u7528\u6237\u5bc6\u7801 \u5e76\u6d4b\u8bd5<\/strong><\/div>\n
[root@master ~]# echo \"123456\" >\/etc\/rsync.password\r\n[root@master ~]# cat \/etc\/rsync.password\r\n123456 #\u6ce8\u610f\uff1a\u8fd9\u91cc\u53ea\u8981\u5199\u5bc6\u7801\u5373\u53ef\uff0c\u5207\u8bb0\u3002\r\n[root@master ~]# chmod 600 \/etc\/rsync.password\r\n[root@ ~]# ll \/etc\/rsync.password\r\n-rw------- 1 root root 7 4\u6708 22 14:32 \/etc\/rsync.password\r\n[root@master ~]# echo \"hello itstyle\">test.txt\r\n[root@master ~]# cat test.txt\r\nhello itstyle\r\n[root@inotify ~]# rsync -avz test.txt rsync_backup@192.168.1.130::backup --password-file=\/etc\/rsync.password\r\nsending incremental file list\r\ntest.txt\r\nsent 82 bytes received 27 bytes 72.67 bytes\/sec\r\ntotal size is 13 speedup is 0.12<\/pre>\n
\u56db\u3001\u7f16\u5199\u811a\u672c<\/strong><\/div>\n

vi rsync_push.sh<\/p>\n

#!\/bin\/bash\r\nrsync -az \/home\/tomcat8 rsync_backup@192.168.1.130::backup --password-file=\/etc\/rsync.password<\/pre>\n
\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/bbs.aliyun.com\/read\/308794.html?utm_campaign=wenzhang&utm_medium=article&utm_source=QQ-qun&utm_content=m_12495<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/linux-rsync-backup.html<\/a>\u7f16\u8f91\uff1a\u9ad8\u519b\uff0c\u5ba1\u6838\u5458\uff1a\u5f20\u5e9a<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u8fd9\u7bc7\u6765\u8bf4\u8bf4\u5982\u4f55\u5b89\u5168\u7684\u5907\u4efd\uff0c\u8fd9\u91cc\u8981\u8bb2\u7684\u662f\u4e3b\u670d\u52a1\u5668\u5982\u4f55\u63a8\u9001\u6570\u636e\u5b9e\u73b0\u5907\u4efd\u3002 \u4e00\u3001\u5907\u4efd\u670d\u52a1\u5668\u914d\u7f6ersync\u6587\u4ef6 vi […]<\/p>\n","protected":false},"author":63,"featured_media":54630,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-53809","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/53809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=53809"}],"version-history":[{"count":14,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/53809\/revisions"}],"predecessor-version":[{"id":275044,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/53809\/revisions\/275044"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/54630"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=53809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=53809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=53809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}