{"id":34986,"date":"2021-09-15T17:07:01","date_gmt":"2021-09-15T10:07:01","guid":{"rendered":"https:\/\/wiki.tino.org\/staging\/?p=34986"},"modified":"2025-06-11T16:29:24","modified_gmt":"2025-06-11T09:29:24","slug":"full-backup-va-restore-voi-mariabackup","status":"publish","type":"post","link":"https:\/\/tino.vn\/blog\/full-backup-va-restore-voi-mariabackup\/","title":{"rendered":"H\u01b0\u1edbng d\u1eabn th\u1ef1c hi\u1ec7n Full Backup v\u00e0 Restore v\u1edbi Mariabackup"},"content":{"rendered":"\n<p><strong>Trong b\u00e0i vi\u1ebft n\u00e0y, Tino Group s\u1ebd h\u01b0\u1edbng d\u1eabn b\u1ea1n c\u00e1ch th\u1ef1c hi\u1ec7n Full Backup v\u00e0 Resore v\u1edbi Mariabackup nh\u00e9!<\/strong><\/p>\n\n\n\n<h2 id=\"Sao_l\u01b0u_d\u1eef_li\u1ec7u_c\u00f9ng_Mariabackup\"><strong>Sao l\u01b0u d\u1eef li\u1ec7u c\u00f9ng Mariabackup<\/strong><\/h2>\n\n\n\n<p>Khi s\u1eed d\u1ee5ng Mariabackup, b\u1ea1n c\u00f3 t\u00f9y ch\u1ecdn th\u1ef1c hi\u1ec7n sao l\u01b0u full ho\u1eb7c incremental backup (sao l\u01b0u gia t\u0103ng).\u00a0C\u00e1c b\u1ea3n sao l\u01b0u full t\u1ea1o ra m\u1ed9t b\u1ea3n sao l\u01b0u ho\u00e0n ch\u1ec9nh c\u1ee7a m\u00e1y ch\u1ee7 c\u01a1 s\u1edf d\u1eef li\u1ec7u trong m\u1ed9t th\u01b0 m\u1ee5c tr\u1ed1ng m\u00e0 ch\u00fang ta ch\u1ec9 \u0111\u1ecbnh, trong khi c\u00e1c b\u1ea3n sao l\u01b0u incremental c\u1eadp nh\u1eadt b\u1ea3n sao l\u01b0u tr\u01b0\u1edbc \u0111\u00f3 v\u1edbi b\u1ea5t k\u1ef3 thay \u0111\u1ed5i n\u00e0o \u0111\u1ed1i v\u1edbi d\u1eef li\u1ec7u \u0111\u00e3 x\u1ea3y ra k\u1ec3 t\u1eeb khi sao l\u01b0u.\u00a0<\/p>\n\n\n\n<h2 id=\"H\u01b0\u1edbng_d\u1eabn_t\u1ea1o_Backup_tr\u00ean_database_server\"><strong>H\u01b0\u1edbng d\u1eabn t\u1ea1o Backup tr\u00ean database server<\/strong><\/h2>\n\n\n\n<p>\u0110\u1ec3 sao l\u01b0u c\u01a1 s\u1edf d\u1eef li\u1ec7u, b\u1ea1n c\u1ea7n ch\u1ea1y Mariabackup v\u1edbi&nbsp;<code><a href=\"https:\/\/mariadb.com\/kb\/en\/mariabackup-options\/#-backup\" rel=\"nofollow noopener\" target=\"_blank\">--backup<\/a><\/code>t\u00f9y ch\u1ecdn y\u00eau c\u1ea7u n\u00f3 th\u1ef1c hi\u1ec7n sao l\u01b0u v\u00e0 v\u1edbi&nbsp;<code><a href=\"https:\/\/mariadb.com\/kb\/en\/mariabackup-options\/#-target-dir\" rel=\"nofollow noopener\" target=\"_blank\">--target-dir<\/a><\/code>t\u00f9y ch\u1ecdn cho bi\u1ebft v\u1ecb tr\u00ed \u0111\u1eb7t c\u00e1c t\u1ec7p sao l\u01b0u.&nbsp;Khi th\u1ef1c hi\u1ec7n m\u1ed9t b\u1ea3n sao l\u01b0u \u0111\u1ea7y \u0111\u1ee7, th\u01b0 m\u1ee5c \u0111\u00edch ph\u1ea3i tr\u1ed1ng ho\u1eb7c n\u00f3 kh\u00f4ng \u0111\u01b0\u1ee3c t\u1ed3n t\u1ea1i.<\/p>\n\n\n\n<p>\u0110\u1ec3 sao l\u01b0u, h\u00e3y ch\u1ea1y l\u1ec7nh sau:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ mariabackup --backup \\\n   --target-dir=\/var\/mariadb\/backup\/ \\\n   --user=mariabackup --password=mypassword<\/code><\/pre>\n\n\n\n<p>Th\u1eddi gian sao l\u01b0u ph\u1ee5 thu\u1ed9c v\u00e0o k\u00edch th\u01b0\u1edbc c\u1ee7a c\u01a1 s\u1edf d\u1eef li\u1ec7u ho\u1eb7c b\u1ea3ng m\u00e0 b\u1ea1n \u0111ang sao l\u01b0u.&nbsp;B\u1ea1n c\u00f3 th\u1ec3 h\u1ee7y sao l\u01b0u n\u1ebfu c\u1ea7n, v\u00ec qu\u00e1 tr\u00ecnh sao l\u01b0u kh\u00f4ng s\u1eeda \u0111\u1ed5i c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/p>\n\n\n\n<p>Mariabackup ghi c\u00e1c t\u1ec7p sao l\u01b0u v\u00e0o th\u01b0 m\u1ee5c \u0111\u00edch.&nbsp;N\u1ebfu th\u01b0 m\u1ee5c \u0111\u00edch kh\u00f4ng t\u1ed3n t\u1ea1i, th\u00ec n\u00f3 s\u1ebd t\u1ea1o ra n\u00f3.&nbsp;N\u1ebfu th\u01b0 m\u1ee5c \u0111\u00edch t\u1ed3n t\u1ea1i v\u00e0 ch\u1ee9a c\u00e1c t\u1ec7p, th\u00ec n\u00f3 s\u1ebd g\u00e2y ra l\u1ed7i v\u00e0 h\u1ee7y b\u1ecf.<\/p>\n\n\n\n<p>\u0110\u00e2y l\u00e0 m\u1ed9t th\u01b0 m\u1ee5c sao l\u01b0u v\u00ed d\u1ee5:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ls \/var\/mariadb\/backup\/\n\naria_log.0000001  mysql                   xtrabackup_checkpoints\naria_log_control  performance_schema      xtrabackup_info\nbackup-my.cnf     test                    xtrabackup_logfile\nibdata1           xtrabackup_binlog_info<\/code><\/pre>\n\n\n\n<h3 id=\"Chu\u1ea9n_b\u1ecb_file_backup_\u0111\u1ec3_c\u00f3_th\u1ec3_restore\"><strong>Chu\u1ea9n b\u1ecb file backup \u0111\u1ec3 c\u00f3 th\u1ec3 restore<\/strong><\/h3>\n\n\n\n<p>C\u00e1c t\u1ec7p d\u1eef li\u1ec7u m\u00e0 Mariabackup t\u1ea1o trong th\u01b0 m\u1ee5c \u0111\u00edch kh\u00f4ng nh\u1ea5t qu\u00e1n theo th\u1eddi \u0111i\u1ec3m, v\u00ec c\u00e1c t\u1ec7p d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c sao ch\u00e9p v\u00e0o c\u00e1c th\u1eddi \u0111i\u1ec3m kh\u00e1c nhau trong qu\u00e1 tr\u00ecnh sao l\u01b0u.&nbsp;N\u1ebfu b\u1ea1n c\u1ed1 g\u1eafng kh\u00f4i ph\u1ee5c t\u1eeb c\u00e1c t\u1ec7p n\u00e0y, InnoDB s\u1ebd nh\u1eadn th\u1ea5y s\u1ef1 m\u00e2u thu\u1eabn v\u00e0 s\u1ef1 c\u1ed1 \u0111\u1ec3 b\u1ea3o v\u1ec7 b\u1ea1n kh\u1ecfi b\u1ecb h\u1ecfng<\/p>\n\n\n\n<p>Tr\u01b0\u1edbc khi c\u00f3 th\u1ec3 kh\u00f4i ph\u1ee5c t\u1eeb b\u1ea3n sao l\u01b0u, tr\u01b0\u1edbc ti\u00ean b\u1ea1n c\u1ea7n&nbsp;<strong>chu\u1ea9n b\u1ecb<\/strong>&nbsp;n\u00f3 \u0111\u1ec3 l\u00e0m cho c\u00e1c t\u1ec7p d\u1eef li\u1ec7u nh\u1ea5t qu\u00e1n.&nbsp;B\u1ea1n c\u00f3 th\u1ec3 l\u00e0m nh\u01b0 v\u1eady v\u1edbi&nbsp;<code><a href=\"https:\/\/mariadb.com\/kb\/en\/mariabackup-options\/#-prepare\" rel=\"nofollow noopener\" target=\"_blank\">--prepare<\/a><\/code>t\u00f9y ch\u1ecdn.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ mariabackup --prepare \\\n   --target-dir=\/var\/mariadb\/backup\/<\/code><\/pre>\n\n\n\n<h3 id=\"Restore_file_backup_\u0111\u00e3_chu\u1ea9n_b\u1ecb_tr\u01b0\u1edbc_\u0111\u00f3\"><strong>Restore file backup \u0111\u00e3 chu\u1ea9n b\u1ecb tr\u01b0\u1edbc \u0111\u00f3<\/strong><\/h3>\n\n\n\n<p>Khi qu\u00e1 tr\u00ecnh sao l\u01b0u ho\u00e0n t\u1ea5t v\u00e0 b\u1ea1n \u0111\u00e3 chu\u1ea9n b\u1ecb sao l\u01b0u \u0111\u1ec3 kh\u00f4i ph\u1ee5c (b\u01b0\u1edbc tr\u01b0\u1edbc), b\u1ea1n c\u00f3 th\u1ec3 kh\u00f4i ph\u1ee5c b\u1ea3n sao l\u01b0u b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng&nbsp;<code><a href=\"https:\/\/mariadb.com\/kb\/en\/mariabackup-options\/#-copy-back\" rel=\"nofollow noopener\" target=\"_blank\">--copy-back<\/a><\/code>ho\u1eb7c c\u00e1c&nbsp;<code><a href=\"https:\/\/mariadb.com\/kb\/en\/mariabackup-options\/#-move-back\" rel=\"nofollow noopener\" target=\"_blank\">--move-back<\/a><\/code>t\u00f9y ch\u1ecdn.&nbsp;C\u00e1c&nbsp;<code><a href=\"https:\/\/mariadb.com\/kb\/en\/mariabackup-options\/#-copy-back\" rel=\"nofollow noopener\" target=\"_blank\">--copy-back<\/a><\/code>t\u00f9y ch\u1ecdn cho ph\u00e9p b\u1ea1n gi\u1eef c\u00e1c t\u1eadp tin sao l\u01b0u g\u1ed1c.&nbsp;C\u00e1c&nbsp;<code><a href=\"https:\/\/mariadb.com\/kb\/en\/mariabackup-options\/#-move-back\" rel=\"nofollow noopener\" target=\"_blank\">--move-back<\/a><\/code>t\u00f9y ch\u1ecdn th\u1ef1c s\u1ef1 di chuy\u1ec3n c\u00e1c t\u1eadp tin sao l\u01b0u v\u00e0o&nbsp;<code><a href=\"https:\/\/mariadb.com\/kb\/en\/server-system-variables\/#datadir\" rel=\"nofollow noopener\" target=\"_blank\">datadir<\/a><\/code>, v\u00ec v\u1eady c\u00e1c t\u1eadp tin sao l\u01b0u g\u1ed1c b\u1ecb m\u1ea5t.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u0110\u1ea7u ti\u00ean,&nbsp;<a href=\"https:\/\/mariadb.com\/kb\/en\/starting-and-stopping-mariadb\/\" rel=\"nofollow noopener\" target=\"_blank\">d\u1eebng ti\u1ebfn tr\u00ecnh M\u00e1y ch\u1ee7 MariaDB<\/a>&nbsp;.<\/li><li>Sau \u0111\u00f3, \u0111\u1ea3m b\u1ea3o r\u1eb1ng&nbsp;<code><a href=\"https:\/\/mariadb.com\/kb\/en\/server-system-variables\/#datadir\" rel=\"nofollow noopener\" target=\"_blank\">datadir<\/a><\/code>tr\u1ed1ng.<\/li><li>Sau \u0111\u00f3, ch\u1ea1y Mariabackup v\u1edbi m\u1ed9t trong c\u00e1c t\u00f9y ch\u1ecdn \u0111\u01b0\u1ee3c \u0111\u1ec1 c\u1eadp \u1edf tr\u00ean:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>$ mariabackup --copy-back \\\n   --target-dir=\/var\/mariadb\/backup\/<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Sau \u0111\u00f3, b\u1ea1n c\u00f3 th\u1ec3 c\u1ea7n ph\u1ea3i s\u1eeda c\u00e1c quy\u1ec1n \u0111\u1ed1i v\u1edbi t\u1ec7p.<\/li><\/ul>\n\n\n\n<p>Khi Mariabackup kh\u00f4i ph\u1ee5c c\u01a1 s\u1edf d\u1eef li\u1ec7u, n\u00f3 s\u1ebd b\u1ea3o to\u00e0n c\u00e1c \u0111\u1eb7c quy\u1ec1n v\u1ec1 t\u1ec7p v\u00e0 th\u01b0 m\u1ee5c c\u1ee7a b\u1ea3n sao l\u01b0u.&nbsp;Tuy nhi\u00ean, n\u00f3 ghi c\u00e1c t\u1ec7p v\u00e0o \u0111\u0129a v\u1edbi t\u01b0 c\u00e1ch l\u00e0 ng\u01b0\u1eddi d\u00f9ng v\u00e0 nh\u00f3m kh\u00f4i ph\u1ee5c c\u01a1 s\u1edf d\u1eef li\u1ec7u.&nbsp;Do \u0111\u00f3, sau khi kh\u00f4i ph\u1ee5c b\u1ea3n sao l\u01b0u, b\u1ea1n c\u00f3 th\u1ec3 c\u1ea7n \u0111i\u1ec1u ch\u1ec9nh ch\u1ee7 s\u1edf h\u1eefu c\u1ee7a th\u01b0 m\u1ee5c d\u1eef li\u1ec7u \u0111\u1ec3 ph\u00f9 h\u1ee3p v\u1edbi ng\u01b0\u1eddi d\u00f9ng v\u00e0 nh\u00f3m cho M\u00e1y ch\u1ee7 MariaDB, th\u01b0\u1eddng l\u00e0&nbsp;<code>mysql<\/code>cho c\u1ea3 hai.&nbsp;V\u00ed d\u1ee5: \u0111\u1ec3 thay \u0111\u1ed5i \u0111\u1ec7 quy quy\u1ec1n s\u1edf h\u1eefu t\u1ec7p cho&nbsp;<code>mysql<\/code>ng\u01b0\u1eddi d\u00f9ng v\u00e0 nh\u00f3m, b\u1ea1n c\u00f3 th\u1ec3 th\u1ef1c thi:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ chown -R mysql:mysql \/var\/lib\/mysql\/<\/code><\/pre>\n\n\n\n<p>Sau khi ho\u00e0n t\u1ea5t, ch\u00fang ta c\u00f3 th\u1ec3 start l\u1ea1i mariadb \u0111\u1ec3 ho\u1ea1t \u0111\u1ed9ng.<\/p>\n\n\n\n<h3 id=\"Restore_b\u1eb1ng_c\u00e1c_c\u00f4ng_c\u1ee5_kh\u00e1c\"><strong>Restore b\u1eb1ng c\u00e1c c\u00f4ng c\u1ee5 kh\u00e1c<\/strong><\/h3>\n\n\n\n<p>Sau khi m\u1ed9t b\u1ea3n sao l\u01b0u \u0111\u1ea7y \u0111\u1ee7 \u0111\u01b0\u1ee3c chu\u1ea9n b\u1ecb, n\u00f3 l\u00e0 m\u1ed9t th\u01b0 m\u1ee5c d\u1eef li\u1ec7u MariaDB \u0111\u1ea7y \u0111\u1ee7 ch\u1ee9c n\u0103ng.&nbsp;Do \u0111\u00f3, mi\u1ec5n l\u00e0 qu\u00e1 tr\u00ecnh M\u00e1y ch\u1ee7 MariaDB b\u1ecb d\u1eebng tr\u00ean m\u00e1y ch\u1ee7 \u0111\u00edch, v\u1ec1 m\u1eb7t k\u1ef9 thu\u1eadt, b\u1ea1n c\u00f3 th\u1ec3 kh\u00f4i ph\u1ee5c b\u1ea3n sao l\u01b0u b\u1eb1ng b\u1ea5t k\u1ef3 c\u00f4ng c\u1ee5 sao ch\u00e9p t\u1ec7p n\u00e0o, ch\u1eb3ng h\u1ea1n nh\u01b0&nbsp;<code>cp<\/code>ho\u1eb7c&nbsp;<code>rysnc<\/code>.&nbsp;V\u00ed d\u1ee5: b\u1ea1n c\u0169ng c\u00f3 th\u1ec3 th\u1ef1c hi\u1ec7n c\u00e1c thao t\u00e1c sau \u0111\u1ec3 kh\u00f4i ph\u1ee5c b\u1ea3n sao l\u01b0u:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ rsync -avrP \/var\/mariadb\/backup \/var\/lib\/mysql\/\n$ chown -R mysql:mysql \/var\/lib\/mysql\/\n$ rm \/var\/lib\/mysql\/ib_logfile*<\/code><\/pre>\n\n\n\n<p>Ch\u00fac b\u1ea1n thao t\u00e1c th\u00e0nh c\u00f4ng!<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>Trong b\u00e0i vi\u1ebft n\u00e0y, Tino Group s\u1ebd h\u01b0\u1edbng d\u1eabn b\u1ea1n c\u00e1ch th\u1ef1c hi\u1ec7n Full Backup v\u00e0 Resore v\u1edbi Mariabackup nh\u00e9! Sao l\u01b0u d\u1eef li\u1ec7u c\u00f9ng Mariabackup Khi s\u1eed d\u1ee5ng Mariabackup, b\u1ea1n c\u00f3 t\u00f9y ch\u1ecdn th\u1ef1c hi\u1ec7n sao l\u01b0u full ho\u1eb7c incremental backup (sao l\u01b0u gia t\u0103ng).\u00a0C\u00e1c b\u1ea3n sao l\u01b0u full t\u1ea1o ra m\u1ed9t b\u1ea3n sao [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":34989,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5404],"tags":[6187],"class_list":["post-34986","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-webmasters","tag-ho-tro-developer"],"_links":{"self":[{"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/posts\/34986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/comments?post=34986"}],"version-history":[{"count":1,"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/posts\/34986\/revisions"}],"predecessor-version":[{"id":114767,"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/posts\/34986\/revisions\/114767"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/media\/34989"}],"wp:attachment":[{"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/media?parent=34986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/categories?post=34986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/tags?post=34986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}