{"id":1167,"date":"2022-10-07T16:02:00","date_gmt":"2022-10-07T09:02:00","guid":{"rendered":"https:\/\/longvan.net\/cong-dong\/?p=1167"},"modified":"2022-11-02T14:59:07","modified_gmt":"2022-11-02T07:59:07","slug":"huong-dan-copy-du%cc%83-lie%cc%a3u-voi-lenh-rsync-thong-qua-ket-noi-ssh","status":"publish","type":"post","link":"https:\/\/longvan.net\/cong-dong\/huong-dan-copy-du%cc%83-lie%cc%a3u-voi-lenh-rsync-thong-qua-ket-noi-ssh\/","title":{"rendered":"H\u01b0\u1edbng d\u1eabn copy d\u01b0\u0303 li\u00ea\u0323u v\u1edbi l\u1ec7nh rsync th\u00f4ng qua k\u1ebft n\u1ed1i SSH"},"content":{"rendered":"<h4><strong>I. Rsync<\/strong><\/h4>\n<p>Rsync (remote sync) l\u00e0 c\u00f4ng c\u1ee5 \u0111\u1ed3ng b\u1ed9 file, th\u01b0 m\u1ee5c c\u1ee7a Linux. N\u00f3 s\u1eed d\u1ee5ng thu\u1eadt to\u00e1n khi copy d\u1eef li\u1ec7u sao cho d\u1eef li\u1ec7u ph\u1ea3i copy l\u00e0 nh\u1ecf nh\u1ea5t (ch\u1ec9 copy nh\u1eefng g\u00ec thay \u0111\u1ed5i gi\u1eefa ngu\u1ed3n v\u00e0 g\u1ed1c), khi \u0111\u1ed3ng b\u1ed9 n\u00f3 gi\u1eef nguy\u00ean m\u1ecdi thu\u1ed9c t\u00ednh c\u1ee7a file, th\u01b0 m\u1ee5c (t\u1eeb ch\u1ee7 s\u1edf h\u1eefu, quy\u1ec1n truy c\u1eadp file &#8230;). M\u0103\u0323c \u0111i\u0323nh, tr\u00ean h\u00e2\u0300u h\u00ea\u0301t ca\u0301c phi\u00ean ba\u0309n h\u00ea\u0323 \u0111i\u00ea\u0300u ha\u0300nh Linux \u0111\u00ea\u0300u cung c\u00e2\u0301p s\u0103\u0309n c\u00f4ng cu\u0323 na\u0300y.<\/p>\n<ul>\n<li><em>Rsync<\/em>\u00a0nhanh h\u01a1n SCP v\u00ec Rsync s\u1eed d\u1ee5ng giao th\u1ee9c remote-update, ch\u1ec9 transfer nh\u1eefng d\u1eef li\u1ec7u thay \u0111\u1ed5i m\u00e0 th\u00f4i.<\/li>\n<li><em>Rsync<\/em>\u00a0ti\u1ebft ki\u1ec7m b\u0103ng th\u00f4ng do s\u1eed d\u1ee5ng ph\u01b0\u01a1ng ph\u00e1p n\u00e9n v\u00e0 gi\u1ea3i n\u00e9n khi transfer.<\/li>\n<\/ul>\n<h4>II. Ca\u0300i \u0111\u0103\u0323t va\u0300 s\u01b0\u0309 du\u0323ng Rsync<\/h4>\n<ol>\n<li>\n<h5>Ca\u0300i \u0111\u0103\u0323t Rsync:<\/h5>\nSSH va\u0300o server linux va\u0300 ti\u00ea\u0301n ha\u0300nh ca\u0300i \u0111\u0103\u0323t b\u0103\u0300ng l\u00ea\u0323nh sau.\n<ul>\n<li>Tr\u00ean RedHat\/CentOS<br \/>\n<pre># yum install rsync -y<br \/># systemctl start rsyncd<br \/># systemctl enable rsyncd<\/pre>\n<\/li>\n<li>Tr\u00ean Debian\/Ubuntu\n<pre>#apt-get install rsync -y<\/pre>\n<strong data-wp-editing=\"1\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1272\" src=\"https:\/\/longvan.net\/cong-dong\/wp-content\/uploads\/2022\/10\/image-1-1.png\" alt=\"\" width=\"650\" height=\"240\" srcset=\"https:\/\/longvan.net\/cong-dong\/wp-content\/uploads\/2022\/10\/image-1-1.png 698w, https:\/\/longvan.net\/cong-dong\/wp-content\/uploads\/2022\/10\/image-1-1-300x111.png 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><br \/><\/strong><\/li>\n<\/ul>\n<\/li>\n<li>\n<h5>S\u01b0\u0309 du\u0323ng RSYNC \u0111\u00ea\u0309 copy d\u01b0\u0303 li\u00ea\u0323u th\u00f4ng qua k\u00ea\u0301t n\u00f4\u0301i SSH<\/h5>\n<ul>\n<li>M\u00f4 hi\u0300nh:<br \/>\n<ul>\n<li>Source Host: Ma\u0301y chu\u0309 g\u01b0\u0309i d\u1eef li\u1ec7u<\/li>\n<li>Destination Host: M\u00e1y chu\u0309 nh\u1eadn d\u1eef li\u1ec7u<\/li>\n<\/ul>\n<\/li>\n<li>Cu\u0301 pha\u0301p chung:<br \/>\n<pre>rsync -option source_file username@destination_host:\/destination_folder<\/pre>\n<\/li>\n<li>Chu\u0301 thi\u0301ch:\n<ul>\n<li><em><span style=\"color: #000000;\">rsync<\/span><\/em>: L\u1ec7nh rsync th\u1ef1c hi\u1ec7n<\/li>\n<li><em><span style=\"color: #000000;\">-option<\/span><\/em>: C\u00e1c t\u00f9y ch\u1ecdn ph\u1ee5<\/li>\n<li><em><span style=\"color: #000000;\">source_file<\/span><\/em>: File\/Th\u01b0 m\u1ee5c c\u1ea7n copy<\/li>\n<li><em>username@destination_host<\/em>: t\u00ean user v\u00e0 IP\/hostname (V\u00ed d\u1ee5 root@45.252.252.252)<\/li>\n<li><em>\/destination_folder:<\/em> Th\u01b0 m\u1ee5c \u0111\u00edch c\u1ea7n copy \u0111\u1ebfn.<\/li>\n<\/ul>\n<\/li>\n<li>M\u00f4\u0323t s\u00f4\u0301 tu\u0300y cho\u0323n quan tro\u0323ng trong rsync:\n<ul>\n<li>-v: hi\u1ec3n th\u1ecb tr\u1ea1ng th\u00e1i k\u1ebft qu\u1ea3<\/li>\n<li>-r: copy toa\u0300n b\u00f4\u0323 d\u01b0\u0303 li\u00ea\u0323u, nh\u01b0ng kh\u00f4ng gi\u01b0\u0303 th\u00f4ng tin quy\u00ea\u0300n, s\u01a1\u0309 h\u01b0\u0303u c\u1ee7a file v\u00e0 th\u01b0 m\u1ee5c.<\/li>\n<li>-a: copy toa\u0300n b\u00f4\u0323 d\u01b0\u0303 li\u00ea\u0323u, \u0111\u1ed3ng th\u1eddi gi\u1eef nguy\u00ean \u0111\u01b0\u1ee3c t\u1ea5t c\u1ea3 c\u00e1c th\u00f4ng tin v\u00ea\u0300 quy\u00ea\u0300n, s\u01a1\u0309 h\u01b0\u0303u, li\u00ean k\u00ea\u0301t,.. c\u1ee7a th\u01b0 m\u1ee5c v\u00e0 file.<\/li>\n<li>-z: n\u00e9n d\u1eef li\u1ec7u khi transfer, ti\u1ebft ki\u1ec7m b\u0103ng th\u00f4ng tuy nhi\u00ean t\u1ed1n th\u00eam m\u1ed9t ch\u00fat th\u1eddi gian<\/li>\n<li>-h: hi\u00ea\u0309n thi\u0323 k\u00ea\u0301t qua\u0309 \u0111\u00f4\u0300ng b\u00f4\u0323 d\u01b0\u0303 li\u00ea\u0323u m\u00f4\u0323t ca\u0301ch d\u1ec5 \u0111\u1ecdc<\/li>\n<li>-e \u2018ssh -p PORT\u2019: T\u00f9y ch\u1ecdn khi s\u1eed d\u1ee5ng port ssh ri\u00eang (V\u00ed d\u1ee5 m\u00e1y \u0110\u00edch port SSH l\u00e0 22 b\u1ea1n s\u1ebd s\u1eed d\u1ee5ng l\u00e0 -e \u2018ssh -p 2222\u2019)<\/li>\n<li>\u2013delete: x\u00f3a d\u1eef li\u1ec7u \u1edf destination n\u1ebfu source kh\u00f4ng t\u1ed3n t\u1ea1i d\u1eef li\u1ec7u \u0111\u00f3.<\/li>\n<li>\u2013exclude: lo\u1ea1i tr\u1eeb ra nh\u1eefng d\u1eef li\u1ec7u kh\u00f4ng mu\u1ed1n truy\u1ec1n \u0111i, n\u1ebfu b\u1ea1n c\u1ea7n lo\u1ea1i ra nhi\u1ec1u file ho\u1eb7c folder \u1edf nhi\u1ec1u \u0111\u01b0\u1eddng d\u1eabn kh\u00e1c nhau th\u00ec m\u1ed7i c\u00e1i b\u1ea1n ph\u1ea3i th\u00eam \u2013exclude t\u01b0\u01a1ng \u1ee9ng.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Vi\u0301 du\u0323 th\u01b0\u0323c t\u00ea\u0301<\/strong>:\n<p>\u01a0\u0309 vi\u0301 du\u0323 na\u0300y, chu\u0301ng ta se\u0303 ti\u00ea\u0301n ha\u0300nh che\u0301p d\u01b0\u0303 li\u00ea\u0323u wordpress t\u01b0\u0300 th\u01b0 mu\u0323c <code>\/home\/doamins\/vannhieu.com<\/code> \u01a1\u0309 server 103.27.238.62\u00a0 \u0111\u00ea\u0301n th\u01b0 mu\u0323c <code>\/home\/domains\/vannhieu123.com<\/code> tr\u00ean server 103.27.238.61, ca\u0301c b\u01b0\u01a1\u0301c th\u01b0\u0323c hi\u00ea\u0323n nh\u01b0 sau:<\/p>\n<ul>\n<li>\u0110a\u0309m ba\u0309o rsync \u0111a\u0303 \u0111\u01b0\u01a1\u0323c ca\u0300i \u0111\u0103\u0323t tr\u00ean ca\u0309 2 server.<\/li>\n<li>SSh va\u0300o server 103.27.238.62 va\u0300 th\u01b0\u0323c hi\u00ean l\u00ea\u0323nh:\n<pre>rsync -P -avz \/home\/domains\/vannhieu.com\/* \u00a0103.27.238.61:\/home\/domains\/vannhieu123.com\/<\/pre>\nTrong \u0111o\u0301:\n<ul>\n<li><em>sync<\/em>: l\u1ec7nh \u0111\u1ed3ng b\u1ed9<\/li>\n<li><em>-avzh<\/em>: C\u00e1c option \u0111i k\u00e8m (B\u1ea1n c\u00f3 th\u1ec3 xem ch\u00fa th\u00edch c\u00e1c option \u1edf tr\u00ean)<\/li>\n<li><em>\/home\/domains\/vannhieu.com\/*<\/em> : Th\u01b0 m\u1ee5c Ngu\u1ed3n, \u0111\u1ed3ng b\u1ed9 to\u00e0n b\u1ed9 c\u00e1c file v\u00e0 th\u01b0 m\u1ee5c trong th\u01b0 m\u1ee5c vannhieu.com (D\u1ea5u * c\u00f3 ngh\u0129a l\u00e0 t\u1ea5t c\u1ea3)<\/li>\n<li><em>103.27.238.61<\/em>: M\u00e1y \u0110\u00edch, m\u00e1y m\u00e0 \u0111\u1ed3ng b\u1ed9 file \u0111\u1ebfn<\/li>\n<li><em>\/home\/domains\/vannhieu123.com\/:<\/em> Th\u01b0 m\u1ee5c m\u00e1y \u0111\u00edch, c\u00e1c file s\u1ebd \u0111\u01b0\u1ee3c l\u01b0u t\u1ea1i \u0111\u00e2y.<\/li>\n<\/ul>\n<\/li>\n<li>Nh\u00e2\u0323p th\u00f4ng tin password cu\u0309a server \u0111\u00ea\u0309 b\u0103\u0301t \u0111\u00e2\u0300u copy d\u01b0\u0303 li\u00ea\u0323u<br \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1264\" src=\"https:\/\/longvan.net\/cong-dong\/wp-content\/uploads\/2022\/10\/image-2-e1665130552528.png\" alt=\"\" width=\"900\" height=\"431\" srcset=\"https:\/\/longvan.net\/cong-dong\/wp-content\/uploads\/2022\/10\/image-2-e1665130552528.png 1319w, https:\/\/longvan.net\/cong-dong\/wp-content\/uploads\/2022\/10\/image-2-e1665130552528-300x144.png 300w, https:\/\/longvan.net\/cong-dong\/wp-content\/uploads\/2022\/10\/image-2-e1665130552528-1024x490.png 1024w, https:\/\/longvan.net\/cong-dong\/wp-content\/uploads\/2022\/10\/image-2-e1665130552528-768x367.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/li>\n<li data-wp-editing=\"1\">Sau khi copy d\u01b0\u0303 li\u00ea\u0323u xong<br \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1266\" src=\"https:\/\/longvan.net\/cong-dong\/wp-content\/uploads\/2022\/10\/image-4-e1665130697135.png\" alt=\"\" width=\"900\" height=\"404\" srcset=\"https:\/\/longvan.net\/cong-dong\/wp-content\/uploads\/2022\/10\/image-4-e1665130697135.png 1258w, https:\/\/longvan.net\/cong-dong\/wp-content\/uploads\/2022\/10\/image-4-e1665130697135-300x135.png 300w, https:\/\/longvan.net\/cong-dong\/wp-content\/uploads\/2022\/10\/image-4-e1665130697135-1024x460.png 1024w, https:\/\/longvan.net\/cong-dong\/wp-content\/uploads\/2022\/10\/image-4-e1665130697135-768x345.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>Nh\u01b0 v\u00e2\u0323y, Long V\u00e2n \u0111a\u0303 hoa\u0300n tha\u0300nh h\u01b0\u01a1\u0301ng d\u00e2\u0303n Quy\u0301 kha\u0301ch ca\u0301ch copy d\u01b0\u0303 li\u00ea\u0323u v\u01a1\u0301i l\u00ea\u0323nh RSYNC th\u00f4ng qua k\u00ea\u0301t n\u00f4\u0301i SSH. Chu\u0301c Quy\u0301 kha\u0301ch tha\u0300nh c\u00f4ng!<\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I. Rsync Rsync (remote sync) l\u00e0 c\u00f4ng c\u1ee5 \u0111\u1ed3ng b\u1ed9 file, th\u01b0 m\u1ee5c c\u1ee7a Linux. N\u00f3 s\u1eed d\u1ee5ng thu\u1eadt to\u00e1n khi copy d\u1eef li\u1ec7u sao cho d\u1eef li\u1ec7u ph\u1ea3i copy l\u00e0 nh\u1ecf nh\u1ea5t (ch\u1ec9 copy nh\u1eefng g\u00ec thay \u0111\u1ed5i gi\u1eefa ngu\u1ed3n v\u00e0 g\u1ed1c), khi \u0111\u1ed3ng b\u1ed9 n\u00f3 gi\u1eef nguy\u00ean m\u1ecdi thu\u1ed9c t\u00ednh c\u1ee7a file, th\u01b0 [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_oasis_is_in_workflow":0,"_oasis_original":0,"footnotes":""},"categories":[4],"tags":[144,5,143],"class_list":["post-1167","post","type-post","status-publish","format-standard","hentry","category-linux","tag-copy","tag-linux","tag-rsync"],"_links":{"self":[{"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/posts\/1167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/comments?post=1167"}],"version-history":[{"count":11,"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/posts\/1167\/revisions"}],"predecessor-version":[{"id":3278,"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/posts\/1167\/revisions\/3278"}],"wp:attachment":[{"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/media?parent=1167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/categories?post=1167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/tags?post=1167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}