{"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 vi rsync_push.sh<\/p>\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#\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
[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
[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
#!\/bin\/bash\r\nrsync -az \/home\/tomcat8 rsync_backup@192.168.1.130::backup --password-file=\/etc\/rsync.password<\/pre>\n
\n