{"id":386950,"date":"2024-06-29T07:01:31","date_gmt":"2024-06-29T07:01:31","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=386950"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=386950","title":{"rendered":"<span>MongoDB \u2014 \u0417\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043c\u0438\u0440. \u0421\u0435\u043c\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/326\/996\/b98\/326996b98ced2e00f7744ba30fca0e69.jpeg\" width=\"1040\" height=\"560\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/326\/996\/b98\/326996b98ced2e00f7744ba30fca0e69.jpeg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440, \u0438 \u043f\u0440\u0438\u0432\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f\u043c. \u041d\u0435 \u043e\u0447\u0435\u043d\u044c \u0434\u043e\u043b\u0433\u043e \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0436\u0434\u0430\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u0430 \u043c\u043e\u0435\u0439 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c, \u043a\u0442\u043e \u0434\u0430\u043b feedback <a href=\"https:\/\/habr.com\/ru\/post\/569282\/\" rel=\"noopener noreferrer nofollow\">\u043f\u043e \u043c\u043e\u0435\u0439 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<p>\u0411\u044b\u043b\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0438\u044f\u0442\u043d\u043e \u043f\u043e\u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u0441 \u0435\u0434\u0438\u043d\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430\u043c\u0438. \u041e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0441\u043f\u0435\u043a\u0442, \u0442\u0435\u043c \u043a\u0442\u043e \u0434\u0430\u043b \u0441\u043e\u0432\u0435\u0442 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e.<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u043e\u0431 \u043e\u0434\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0430\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0445\u0435\u043c\u044b \u0442\u0430\u0431\u043b\u0438\u0446, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e &#8212; \u044d\u0442\u043e MongoDB \u0421\u0423\u0411\u0414 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 NoSQL-\u0441\u0438\u0441\u0442\u0435\u043c. \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 \u043f\u0430\u0440 \u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0435\u0434\u0438\u043d\u0438\u0446\u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 MongoDB.  \u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043d\u0430\u0431\u043e\u0440\u044b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. MongoDB \u2014 \u044d\u0442\u043e \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0430\u044f\u0441\u044f \u0432 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 2000-\u0445 \u0433\u043e\u0434\u043e\u0432. \u041f\u0440\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u043d\u0435 \u0431\u0443\u0434\u0443 \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0438 \u0442\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0438\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0433\u0430\u0439\u0434\u0430  \u0412\u0441\u0435\u043c \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c.  <br \/><a href=\"https:\/\/docs.mongodb.com\/v5.0\/administration\/install-community\/\" rel=\"noopener noreferrer nofollow\">https:\/\/docs.mongodb.com\/v5.0\/administration\/install-community\/<\/a><\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0443 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e \u0442\u043e\u043c, <strong>\u043a\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043f\u043e\u0442\u043e\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c<\/strong>. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a \u0432\u0441\u0435 \u0441\u043b\u043e\u0436\u043d\u043e, \u0438 \u0434\u0430\u0436\u0435 \u0441\u043a\u0430\u0436\u0443 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e:) \u041d\u0435 \u0431\u0443\u0434\u0443 \u0437\u0430\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0432\u0441\u0435\u0445 \u0441\u0432\u043e\u0435\u0439 \u043f\u0438\u0441\u0430\u043d\u0438\u043d\u043e\u0439 \u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0434\u0435\u043b\u0443. \u041c\u0430\u043d\u0443\u0430\u043b \u0437\u0430\u0442\u043e\u0447\u0435\u043d \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 \u0421\u0423\u0411\u0414 \u0438\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0433\u0430\u0439\u0434\u0430. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u044f \u0431\u0443\u0434\u0443 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u043a\u0435 \u0441 \u041b\u0438\u043d\u0443\u043a\u0441\u043e\u043c, \u041e\u0421 Ubuntu 20.04.2 LTS<\/p>\n<h4>\u0424\u043e\u0440\u043c\u0430\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 MongoDB <\/h4>\n<p>\u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u0432 \u043e\u0431\u043c\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438 \u0438\u0445 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/www.mongodb.com\/json-and-bson\" rel=\"noopener noreferrer nofollow\"><strong>JSON<\/strong><\/a> (JavaScript Object Notation). JSON \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043f\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.  \u0421\u043f\u043e\u0441\u043e\u0431 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 MongoDB \u0432 \u044d\u0442\u043e\u043c \u043f\u043b\u0430\u043d\u0435 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 JSON, \u0445\u043e\u0442\u044f \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e JSON \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f.  \u0414\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432 MongoDB \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u043e\u0440\u043c\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f BSON (\u0411\u0438\u0421\u043e\u043d) \u0438\u043b\u0438 \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043e\u0442 binary JSON.<\/p>\n<p><a href=\"https:\/\/www.mongodb.com\/json-and-bson\" rel=\"noopener noreferrer nofollow\"><strong>BSON<\/strong><\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u044b\u0441\u0442\u0440\u0435\u0435: \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0438\u0441\u043a \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430.  \u0425\u043e\u0442\u044f \u043d\u0430\u0434\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e BSON \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a:  \u0432 \u0446\u0435\u043b\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 JSON-\u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u043c\u0435\u0441\u0442\u0430, \u0447\u0435\u043c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 BSON, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0441 \u043b\u0438\u0445\u0432\u043e\u0439 \u043e\u043a\u0443\u043f\u0430\u0435\u0442\u0441\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e.<\/p>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u0439 \u0421\u0423\u0411\u0414, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u043b\u044f \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0439 \u043a\u043e\u043f\u0438\u0438 \u0442\u0440\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c HABR1, HABR2, HABR3. \u0414\u043b\u044f \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0431\u0434 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0430\u0440\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439.  <\/p>\n<p><em>root@backup-server:~# mongo<\/em><\/p>\n<pre><code class=\"pgsql\">> use HABR db.createCollection(\"posts\") db.createCollection(\"address\") db.createCollection(\"phone\")  > use HABR2 db.createCollection(\"posts2\") db.createCollection(\"address2\") db.createCollection(\"phone2\")  > use HABR3 db.createCollection(\"posts3\") db.createCollection(\"address3\") db.createCollection(\"phone3\") db.createCollection(\"phonehabr\") <\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u043b\u0438 \u0431\u0434, \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0432\u0441\u0435 \u043b\u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0441 \u043d\u0438\u043c\u0438 \ud83d\ude42 <br \/>> <strong>show dbs<\/strong><\/p>\n<pre><code class=\"sql\">switched to db admin admin> show dbs HABR         57.3 kB HABR2        24.6 kB HABR3        24.6 kB admin         184 kB config       73.7 kB local        81.9 kB <\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043d\u0430\u0448\u0438 \u0431\u0434 \u0441\u043e\u0437\u0434\u0430\u043b\u0438\u0441\u044c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0435\u0441\u0442\u044c \u043b\u0438 \u0432 \u043d\u0438\u0445 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435. <\/p>\n<pre><code class=\"pgsql\">admin> use HABR switched to db HABR HABR> show collections addreshabr address3 addresshabr phone5 phonehabr posts postshabr HABR> use HABR2 switched to db HABR2 HABR2> show collections addres phone posts HABR2> use HABR3 switched to db HABR3 HABR3> show collections addres3 phone3 posts3<\/code><\/pre>\n<p>\u0412\u0441\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043d\u0430 \u043c\u0435\u0441\u0442\u0435. \u041c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443 \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0439 \u043a\u043e\u043f\u0438\u0438.  <br \/>\u0420\u0435\u0437\u0435\u0440\u0432\u043d\u0443\u044e \u043a\u043e\u043f\u0438\u044e \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0437 \u043f\u043e\u0434 \u0440\u0443\u0442\u0430.  <\/p>\n<p>\u0414\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0435 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:  <\/p>\n<p><em>mongodump &#8212;host=localhost  &#8212;gzip -d HABR &#8212;archive=\/tmp\/backup-db-habr.gz<\/em><strong><em> <br \/><\/em><\/strong><\/p>\n<pre><code class=\"bash\">root@backup-server:\/tmp\/test# ls -la total 20 drwxr-xr-x  2 root root 4096 Aug  3 18:33 . drwxrwxrwt 13 root root 4096 Aug  3 18:32 .. -rw-r--r--  1 root root  638 Aug  3 18:32 backup-db-habr.gz -rw-r--r--  1 root root  416 Aug  3 18:33 backup-db-habr2.gz -rw-r--r--  1 root root  423 Aug  3 18:33 backup-db-habr3.gz <\/code><\/pre>\n<p><strong>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u0430\u044f \u041a\u043e\u043f\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043b\u0430\u0441\u044c \u0443\u0441\u043f\u0435\u0448\u043d\u043e.<\/strong><\/p>\n<p>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u044d\u043a\u0430\u043f\u0430. <br \/><em><br \/>mongorestore &#8212;gzip &#8212;archive=backup-db-habr.gz<\/em><\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u0443\u044e \u043a\u043e\u043f\u0438\u044e \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439, \u0438 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0432 \u0430\u0440\u0445\u0438\u0432, \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432,  \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432.<\/p>\n<p><strong>\u0421\u043f\u043e\u0441\u043e\u0431 2<\/strong> &#8212; <strong>\u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u0431\u0435\u0437 \u0441\u0436\u0430\u0442\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u044d\u043a\u0430\u043f\u0430 <br \/><strong><em>mkdir -p \/tmp\/backup\/<\/em><br \/><\/strong>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435:<br \/><strong><em>mongodump &#8212;out \/tmp\/backup\/<\/em><\/strong><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0441 \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u043e\u0439 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e \u0442\u0430\u043c \u043b\u0435\u0436\u0438\u0442.  \u0412\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438  \u0411\u0415\u0417 \u0421\u0416\u0410\u0422\u0418\u042f \u0432 <a href=\"https:\/\/www.mongodb.com\/json-and-bson\" rel=\"noopener noreferrer nofollow\">BSON<\/a> \u0438 <a href=\"https:\/\/www.mongodb.com\/json-and-bson\" rel=\"noopener noreferrer nofollow\">JSON<\/a> \u0444\u043e\u0440\u043c\u0430\u0442\u0435. <\/p>\n<pre><code class=\"bash\">root@backup-server:\/tmp\/backup\/HABR# ls -la total 36 drwxr-xr-x 2 root root 4096 Aug  3 21:08 . drwxr-xr-x 5 root root 4096 Aug  3 21:09 .. -rw-r--r-- 1 root root    0 Aug  3 21:08 addreshabr.bson -rw-r--r-- 1 root root  177 Aug  3 21:08 addreshabr.metadata.json -rw-r--r-- 1 root root    0 Aug  3 21:08 address3.bson -rw-r--r-- 1 root root  175 Aug  3 21:08 address3.metadata.json -rw-r--r-- 1 root root    0 Aug  3 21:08 addresshabr.bson -rw-r--r-- 1 root root  178 Aug  3 21:08 addresshabr.metadata.json -rw-r--r-- 1 root root    0 Aug  3 21:08 phone5.bson -rw-r--r-- 1 root root  173 Aug  3 21:08 phone5.metadata.json -rw-r--r-- 1 root root    0 Aug  3 21:08 phonehabr.bson -rw-r--r-- 1 root root  176 Aug  3 21:08 phonehabr.metadata.json -rw-r--r-- 1 root root    0 Aug  3 21:08 posts.bson -rw-r--r-- 1 root root  172 Aug  3 21:08 posts.metadata.json -rw-r--r-- 1 root root    0 Aug  3 21:08 postshabr.bson -rw-r--r-- 1 root root  176 Aug  3 21:08 postshabr.metadata.json<\/code><\/pre>\n<p>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u044d\u043a\u0430\u043f\u0430:<br \/><strong><em>mongorestore &#8212;drop &#8212;dir \/tmp\/backup<\/em><\/strong><\/p>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <strong>&#8212;drop<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0434 \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u043c(\u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442),\u0432\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 duplicate key errors \u042d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <strong>&#8212;drop<\/strong> \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0441 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<p>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 postshabr \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 HABR) \u0441 \u0431\u0435\u043a\u0430\u043f\u0430 \u0432\u0441\u0435\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<p><em>mongorestore &#8212;drop -v &#8212;dir \/root\/backup &#8212;nsInclude &#8216;habr.postshabr&#8217;<\/em><\/p>\n<p>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u0441\u0435\u0445 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438(\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 postshabr \u0432 \u0431\u0430\u0437\u0435 habrdb)<\/p>\n<p><em>mongorestore &#8212;drop -v &#8212;dir \/root\/backup &#8212;nsExclude &#8216;habr.postshabr&#8217;<\/em><\/p>\n<p><strong>\u0421\u043f\u043e\u0441\u043e\u0431 3 &#8212; \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0436\u0430\u0442\u0438\u0435\u043c.<\/p>\n<p><\/strong><em>mongodump &#8212;gzip &#8212;out \/tmp\/backup<\/em><\/p>\n<pre><code class=\"bash\">root@backup-server:\/tmp\/backup\/HABR# ls -la total 44 drwxr-xr-x  2 root root 4096 Aug  3 21:51 . drwxr-xr-x 13 root root 4096 Aug  3 21:51 .. -rw-r--r--  1 root root    0 Aug  3 21:08 addres.bson -rw-r--r--  1 root root   23 Aug  3 21:51 addres.bson.gz -rw-r--r--  1 root root  173 Aug  3 21:08 addres.metadata.json -rw-r--r--  1 root root  152 Aug  3 21:51 addres.metadata.json.gz -rw-r--r--  1 root root    0 Aug  3 21:08 phone.bson -rw-r--r--  1 root root   23 Aug  3 21:51 phone.bson.gz -rw-r--r--  1 root root  172 Aug  3 21:08 phone.metadata.json -rw-r--r--  1 root root  151 Aug  3 21:51 phone.metadata.json.gz -rw-r--r--  1 root root    0 Aug  3 21:08 posts.bson -rw-r--r--  1 root root   23 Aug  3 21:51 posts.bson.gz -rw-r--r--  1 root root  172 Aug  3 21:08 posts.metadata.json -rw-r--r--  1 root root  153 Aug  3 21:51 posts.metadata.json.gz<\/code><\/pre>\n<p>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u0435\u043a\u0430\u043f\u0430.<\/p>\n<p><strong><em>mongorestore &#8212;gzip &#8212;drop &#8212;dir \/mnt\/backup<\/em><\/strong><\/p>\n<p><strong>\u0421\u043f\u043e\u0441\u043e\u0431 4 &#8212; \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0436\u0430\u0442\u0438\u0435\u043c \u0432 \u043e\u0434\u0438\u043d \u0430\u0440\u0445\u0438\u0432(.gz)<\/p>\n<p><\/strong><em>mongodump &#8212;gzip &#8212;archive=\/tmp\/backup\/mybackup.gz<\/em><\/p>\n<p><u>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u0435\u043a\u0430\u043f\u0430:<\/u><\/p>\n<p><em>mongorestore &#8212;gzip &#8212;drop &#8212;archive=\/tmp\/backup\/mybackup.gz<\/em><\/p>\n<p><strong>\u0421\u043f\u043e\u0441\u043e\u0431 5 &#8212; \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p><\/strong><em>mongodump &#8212;gzip -d HABR2<\/em><\/p>\n<pre><code class=\"bash\">root@backup-server:\/tmp\/backup\/dump\/HABR2# mongodump --gzip -d HABR2 2021-08-04T00:17:24.033+0300writing HABR2.posts to dump\/HABR2\/posts.bson.gz 2021-08-04T00:17:24.033+0300writing HABR2.phone to dump\/HABR2\/phone.bson.gz 2021-08-04T00:17:24.035+0300writing HABR2.addres to dump\/HABR2\/addres.bson.gz 2021-08-04T00:17:24.036+0300done dumping HABR2.posts (0 documents) 2021-08-04T00:17:24.036+0300done dumping HABR2.phone (0 documents) 2021-08-04T00:17:24.037+0300done dumping HABR2.addres (0 documents)<\/code><\/pre>\n<p><u>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u0435\u043a\u0430\u043f\u0430:<\/u><strong><\/p>\n<p><\/strong><em>mongorestore &#8212;gzip  &#8212;dir \/tmp\/backup\/<\/em><\/p>\n<p><strong>\u0421\u043f\u043e\u0441\u043e\u0431 6 &#8212; \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 address \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 HABR2.<\/strong> <\/p>\n<p><em>mongodump &#8212;gzip -d HABR2 -c address<\/em><\/p>\n<pre><code class=\"bash\">root@backup-server:\/tmp\/backup\/dump\/HABR2# ls -la total 16 drwxr-xr-x 2 root root 4096 Aug  3 22:05 . drwxr-xr-x 3 root root 4096 Aug  3 22:05 .. -rw-r--r-- 1 root root   23 Aug  3 22:05 addres.bson.gz -rw-r--r-- 1 root root  152 Aug  3 22:05 addres.metadata.json.gz <\/code><\/pre>\n<p><strong>\u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e bson-\u0444\u0430\u0439\u043b\u0430:<br \/><\/strong><br \/><em>zcat posts.bson.gz | bsondump &#8212;pretty<\/em><\/p>\n<pre><code class=\"bash\">root@backup-server:\/# zcat posts.bson.gz | bsondump --pretty 2021-08-03T22:23:57.113+03000 objects found <\/code><\/pre>\n<p><strong>\u0421\u043f\u043e\u0441\u043e\u0431 7 &#8212; \u0411\u0435\u043a\u0430\u043f \u0432\u0441\u0435\u0439 \u0431\u0430\u0437\u044b HABR2 \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 address<\/p>\n<p><\/strong><em>mongodump &#8212;gzip -d HABR2 &#8212;excludeCollection=address<\/em><\/p>\n<pre><code class=\"bash\">root@backup-server:\/tmp\/backup\/dump\/HABR2# mongodump --gzip -d HABR2 --excludeCollection=addres 2021-08-04T00:16:41.482+0300writing HABR2.phone to dump\/HABR2\/phone.bson.gz 2021-08-04T00:16:41.483+0300writing HABR2.posts to dump\/HABR2\/posts.bson.gz 2021-08-04T00:16:41.484+0300done dumping HABR2.phone (0 documents) 2021-08-04T00:16:41.485+0300done dumping HABR2.posts (0 documents) <\/code><\/pre>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u043b\u044e\u0431\u043e\u043c\u0443 \u043a\u0442\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0435\u0442\u0441\u044f \u0441 \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439, \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0432 \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u044d\u0442\u043e\u0439 \u0421\u0423\u0411\u0414. \u0412\u0441\u0435\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/571138\/\"> https:\/\/habr.com\/ru\/articles\/571138\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440, \u0438 \u043f\u0440\u0438\u0432\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f\u043c. \u041d\u0435 \u043e\u0447\u0435\u043d\u044c \u0434\u043e\u043b\u0433\u043e \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0436\u0434\u0430\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u0430 \u043c\u043e\u0435\u0439 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c, \u043a\u0442\u043e \u0434\u0430\u043b feedback <a href=\"https:\/\/habr.com\/ru\/post\/569282\/\" rel=\"noopener noreferrer nofollow\">\u043f\u043e \u043c\u043e\u0435\u0439 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<p>\u0411\u044b\u043b\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0438\u044f\u0442\u043d\u043e \u043f\u043e\u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u0441 \u0435\u0434\u0438\u043d\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430\u043c\u0438. \u041e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0441\u043f\u0435\u043a\u0442, \u0442\u0435\u043c \u043a\u0442\u043e \u0434\u0430\u043b \u0441\u043e\u0432\u0435\u0442 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e.<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u043e\u0431 \u043e\u0434\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0430\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0445\u0435\u043c\u044b \u0442\u0430\u0431\u043b\u0438\u0446, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e &#8212; \u044d\u0442\u043e MongoDB \u0421\u0423\u0411\u0414 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 NoSQL-\u0441\u0438\u0441\u0442\u0435\u043c. \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 \u043f\u0430\u0440 \u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0435\u0434\u0438\u043d\u0438\u0446\u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 MongoDB.  \u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043d\u0430\u0431\u043e\u0440\u044b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. MongoDB \u2014 \u044d\u0442\u043e \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0430\u044f\u0441\u044f \u0432 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 2000-\u0445 \u0433\u043e\u0434\u043e\u0432. \u041f\u0440\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u043d\u0435 \u0431\u0443\u0434\u0443 \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0438 \u0442\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0438\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0433\u0430\u0439\u0434\u0430  \u0412\u0441\u0435\u043c \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c.  <br \/><a href=\"https:\/\/docs.mongodb.com\/v5.0\/administration\/install-community\/\" rel=\"noopener noreferrer nofollow\">https:\/\/docs.mongodb.com\/v5.0\/administration\/install-community\/<\/a><\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0443 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e \u0442\u043e\u043c, <strong>\u043a\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043f\u043e\u0442\u043e\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c<\/strong>. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a \u0432\u0441\u0435 \u0441\u043b\u043e\u0436\u043d\u043e, \u0438 \u0434\u0430\u0436\u0435 \u0441\u043a\u0430\u0436\u0443 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e:) \u041d\u0435 \u0431\u0443\u0434\u0443 \u0437\u0430\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0432\u0441\u0435\u0445 \u0441\u0432\u043e\u0435\u0439 \u043f\u0438\u0441\u0430\u043d\u0438\u043d\u043e\u0439 \u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0434\u0435\u043b\u0443. \u041c\u0430\u043d\u0443\u0430\u043b \u0437\u0430\u0442\u043e\u0447\u0435\u043d \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 \u0421\u0423\u0411\u0414 \u0438\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0433\u0430\u0439\u0434\u0430. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u044f \u0431\u0443\u0434\u0443 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u043a\u0435 \u0441 \u041b\u0438\u043d\u0443\u043a\u0441\u043e\u043c, \u041e\u0421 Ubuntu 20.04.2 LTS<\/p>\n<h4>\u0424\u043e\u0440\u043c\u0430\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 MongoDB <\/h4>\n<p>\u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u0432 \u043e\u0431\u043c\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438 \u0438\u0445 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/www.mongodb.com\/json-and-bson\" rel=\"noopener noreferrer nofollow\"><strong>JSON<\/strong><\/a> (JavaScript Object Notation). JSON \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043f\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.  \u0421\u043f\u043e\u0441\u043e\u0431 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 MongoDB \u0432 \u044d\u0442\u043e\u043c \u043f\u043b\u0430\u043d\u0435 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 JSON, \u0445\u043e\u0442\u044f \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e JSON \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f.  \u0414\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432 MongoDB \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u043e\u0440\u043c\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f BSON (\u0411\u0438\u0421\u043e\u043d) \u0438\u043b\u0438 \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043e\u0442 binary JSON.<\/p>\n<p><a href=\"https:\/\/www.mongodb.com\/json-and-bson\" rel=\"noopener noreferrer nofollow\"><strong>BSON<\/strong><\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u044b\u0441\u0442\u0440\u0435\u0435: \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0438\u0441\u043a \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430.  \u0425\u043e\u0442\u044f \u043d\u0430\u0434\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e BSON \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a:  \u0432 \u0446\u0435\u043b\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 JSON-\u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u043c\u0435\u0441\u0442\u0430, \u0447\u0435\u043c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 BSON, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0441 \u043b\u0438\u0445\u0432\u043e\u0439 \u043e\u043a\u0443\u043f\u0430\u0435\u0442\u0441\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e.<\/p>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u0439 \u0421\u0423\u0411\u0414, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u043b\u044f \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0439 \u043a\u043e\u043f\u0438\u0438 \u0442\u0440\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c HABR1, HABR2, HABR3. \u0414\u043b\u044f \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0431\u0434 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0430\u0440\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439.  <\/p>\n<p><em>root@backup-server:~# mongo<\/em><\/p>\n<pre><code class=\"pgsql\">> use HABR db.createCollection(\"posts\") db.createCollection(\"address\") db.createCollection(\"phone\")  > use HABR2 db.createCollection(\"posts2\") db.createCollection(\"address2\") db.createCollection(\"phone2\")  > use HABR3 db.createCollection(\"posts3\") db.createCollection(\"address3\") db.createCollection(\"phone3\") db.createCollection(\"phonehabr\") <\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u043b\u0438 \u0431\u0434, \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0432\u0441\u0435 \u043b\u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0441 \u043d\u0438\u043c\u0438 \ud83d\ude42 <br \/>> <strong>show dbs<\/strong><\/p>\n<pre><code class=\"sql\">switched to db admin admin> show dbs HABR         57.3 kB HABR2        24.6 kB HABR3        24.6 kB admin         184 kB config       73.7 kB local        81.9 kB <\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043d\u0430\u0448\u0438 \u0431\u0434 \u0441\u043e\u0437\u0434\u0430\u043b\u0438\u0441\u044c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0435\u0441\u0442\u044c \u043b\u0438 \u0432 \u043d\u0438\u0445 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435. <\/p>\n<pre><code class=\"pgsql\">admin> use HABR switched to db HABR HABR> show collections addreshabr address3 addresshabr phone5 phonehabr posts postshabr HABR> use HABR2 switched to db HABR2 HABR2> show collections addres phone posts HABR2> use HABR3 switched to db HABR3 HABR3> show collections addres3 phone3 posts3<\/code><\/pre>\n<p>\u0412\u0441\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043d\u0430 \u043c\u0435\u0441\u0442\u0435. \u041c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443 \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0439 \u043a\u043e\u043f\u0438\u0438.  <br \/>\u0420\u0435\u0437\u0435\u0440\u0432\u043d\u0443\u044e \u043a\u043e\u043f\u0438\u044e \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0437 \u043f\u043e\u0434 \u0440\u0443\u0442\u0430.  <\/p>\n<p>\u0414\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0435 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:  <\/p>\n<p><em>mongodump &#8212;host=localhost  &#8212;gzip -d HABR &#8212;archive=\/tmp\/backup-db-habr.gz<\/em><strong><em> <br \/><\/em><\/strong><\/p>\n<pre><code class=\"bash\">root@backup-server:\/tmp\/test# ls -la total 20 drwxr-xr-x  2 root root 4096 Aug  3 18:33 . drwxrwxrwt 13 root root 4096 Aug  3 18:32 .. -rw-r--r--  1 root root  638 Aug  3 18:32 backup-db-habr.gz -rw-r--r--  1 root root  416 Aug  3 18:33 backup-db-habr2.gz -rw-r--r--  1 root root  423 Aug  3 18:33 backup-db-habr3.gz <\/code><\/pre>\n<p><strong>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u0430\u044f \u041a\u043e\u043f\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043b\u0430\u0441\u044c \u0443\u0441\u043f\u0435\u0448\u043d\u043e.<\/strong><\/p>\n<p>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u044d\u043a\u0430\u043f\u0430. <br \/><em><br \/>mongorestore &#8212;gzip &#8212;archive=backup-db-habr.gz<\/em><\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u0443\u044e \u043a\u043e\u043f\u0438\u044e \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439, \u0438 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0432 \u0430\u0440\u0445\u0438\u0432, \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432,  \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432.<\/p>\n<p><strong>\u0421\u043f\u043e\u0441\u043e\u0431 2<\/strong> &#8212; <strong>\u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u0431\u0435\u0437 \u0441\u0436\u0430\u0442\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u044d\u043a\u0430\u043f\u0430 <br \/><strong><em>mkdir -p \/tmp\/backup\/<\/em><br \/><\/strong>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435:<br \/><strong><em>mongodump &#8212;out \/tmp\/backup\/<\/em><\/strong><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0441 \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u043e\u0439 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e \u0442\u0430\u043c \u043b\u0435\u0436\u0438\u0442.  \u0412\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438  \u0411\u0415\u0417 \u0421\u0416\u0410\u0422\u0418\u042f \u0432 <a href=\"https:\/\/www.mongodb.com\/json-and-bson\" rel=\"noopener noreferrer nofollow\">BSON<\/a> \u0438 <a href=\"https:\/\/www.mongodb.com\/json-and-bson\" rel=\"noopener noreferrer nofollow\">JSON<\/a> \u0444\u043e\u0440\u043c\u0430\u0442\u0435. <\/p>\n<pre><code class=\"bash\">root@backup-server:\/tmp\/backup\/HABR# ls -la total 36 drwxr-xr-x 2 root root 4096 Aug  3 21:08 . drwxr-xr-x 5 root root 4096 Aug  3 21:09 .. -rw-r--r-- 1 root root    0 Aug  3 21:08 addreshabr.bson -rw-r--r-- 1 root root  177 Aug  3 21:08 addreshabr.metadata.json -rw-r--r-- 1 root root    0 Aug  3 21:08 address3.bson -rw-r--r-- 1 root root  175 Aug  3 21:08 address3.metadata.json -rw-r--r-- 1 root root    0 Aug  3 21:08 addresshabr.bson -rw-r--r-- 1 root root  178 Aug  3 21:08 addresshabr.metadata.json -rw-r--r-- 1 root root    0 Aug  3 21:08 phone5.bson -rw-r--r-- 1 root root  173 Aug  3 21:08 phone5.metadata.json -rw-r--r-- 1 root root    0 Aug  3 21:08 phonehabr.bson -rw-r--r-- 1 root root  176 Aug  3 21:08 phonehabr.metadata.json -rw-r--r-- 1 root root    0 Aug  3 21:08 posts.bson -rw-r--r-- 1 root root  172 Aug  3 21:08 posts.metadata.json -rw-r--r-- 1 root root    0 Aug  3 21:08 postshabr.bson -rw-r--r-- 1 root root  176 Aug  3 21:08 postshabr.metadata.json<\/code><\/pre>\n<p>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u044d\u043a\u0430\u043f\u0430:<br \/><strong><em>mongorestore &#8212;drop &#8212;dir \/tmp\/backup<\/em><\/strong><\/p>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <strong>&#8212;drop<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0434 \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u043c(\u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442),\u0432\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 duplicate key errors \u042d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <strong>&#8212;drop<\/strong> \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0441 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<p>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 postshabr \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 HABR) \u0441 \u0431\u0435\u043a\u0430\u043f\u0430 \u0432\u0441\u0435\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<p><em>mongorestore &#8212;drop -v &#8212;dir \/root\/backup &#8212;nsInclude &#8216;habr.postshabr&#8217;<\/em><\/p>\n<p>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u0441\u0435\u0445 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438(\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 postshabr \u0432 \u0431\u0430\u0437\u0435 habrdb)<\/p>\n<p><em>mongorestore &#8212;drop -v &#8212;dir \/root\/backup &#8212;nsExclude &#8216;habr.postshabr&#8217;<\/em><\/p>\n<p><strong>\u0421\u043f\u043e\u0441\u043e\u0431 3 &#8212; \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0436\u0430\u0442\u0438\u0435\u043c.<\/p>\n<p><\/strong><em>mongodump &#8212;gzip &#8212;out \/tmp\/backup<\/em><\/p>\n<pre><code class=\"bash\">root@backup-server:\/tmp\/backup\/HABR# ls -la total 44 drwxr-xr-x  2 root root 4096 Aug  3 21:51 . drwxr-xr-x 13 root root 4096 Aug  3 21:51 .. -rw-r--r--  1 root root    0 Aug  3 21:08 addres.bson -rw-r--r--  1 root root   23 Aug  3 21:51 addres.bson.gz -rw-r--r--  1 root root  173 Aug  3 21:08 addres.metadata.json -rw-r--r--  1 root root  152 Aug  3 21:51 addres.metadata.json.gz -rw-r--r--  1 root root    0 Aug  3 21:08 phone.bson -rw-r--r--  1 root root   23 Aug  3 21:51 phone.bson.gz -rw-r--r--  1 root root  172 Aug  3 21:08 phone.metadata.json -rw-r--r--  1 root root  151 Aug  3 21:51 phone.metadata.json.gz -rw-r--r--  1 root root    0 Aug  3 21:08 posts.bson -rw-r--r--  1 root root   23 Aug  3 21:51 posts.bson.gz -rw-r--r--  1 root root  172 Aug  3 21:08 posts.metadata.json -rw-r--r--  1 root root  153 Aug  3 21:51 posts.metadata.json.gz<\/code><\/pre>\n<p>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u0435\u043a\u0430\u043f\u0430.<\/p>\n<p><strong><em>mongorestore &#8212;gzip &#8212;drop &#8212;dir \/mnt\/backup<\/em><\/strong><\/p>\n<p><strong>\u0421\u043f\u043e\u0441\u043e\u0431 4 &#8212; \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0436\u0430\u0442\u0438\u0435\u043c \u0432 \u043e\u0434\u0438\u043d \u0430\u0440\u0445\u0438\u0432(.gz)<\/p>\n<p><\/strong><em>mongodump &#8212;gzip &#8212;archive=\/tmp\/backup\/mybackup.gz<\/em><\/p>\n<p><u>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u0435\u043a\u0430\u043f\u0430:<\/u><\/p>\n<p><em>mongorestore &#8212;gzip &#8212;drop &#8212;archive=\/tmp\/backup\/mybackup.gz<\/em><\/p>\n<p><strong>\u0421\u043f\u043e\u0441\u043e\u0431 5 &#8212; \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p><\/strong><em>mongodump &#8212;gzip -d HABR2<\/em><\/p>\n<pre><code class=\"bash\">root@backup-server:\/tmp\/backup\/dump\/HABR2# mongodump --gzip -d HABR2 2021-08-04T00:17:24.033+0300writing HABR2.posts to dump\/HABR2\/posts.bson.gz 2021-08-04T00:17:24.033+0300writing HABR2.phone to dump\/HABR2\/phone.bson.gz 2021-08-04T00:17:24.035+0300writing HABR2.addres to dump\/HABR2\/addres.bson.gz 2021-08-04T00:17:24.036+0300done dumping HABR2.posts (0 documents) 2021-08-04T00:17:24.036+0300done dumping HABR2.phone (0 documents) 2021-08-04T00:17:24.037+0300done dumping HABR2.addres (0 documents)<\/code><\/pre>\n<p><u>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u0435\u043a\u0430\u043f\u0430:<\/u><strong><\/p>\n<p><\/strong><em>mongorestore &#8212;gzip  &#8212;dir \/tmp\/backup\/<\/em><\/p>\n<p><strong>\u0421\u043f\u043e\u0441\u043e\u0431 6 &#8212; \u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 address \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 HABR2.<\/strong> <\/p>\n<p><em>mongodump &#8212;gzip -d HABR2 -c address<\/em><\/p>\n<pre><code class=\"bash\">root@backup-server:\/tmp\/backup\/dump\/HABR2# ls -la total 16 drwxr-xr-x 2 root root 4096 Aug  3 22:05 . drwxr-xr-x 3 root root 4096 Aug  3 22:05 .. -rw-r--r-- 1 root root   23 Aug  3 22:05 addres.bson.gz -rw-r--r-- 1 root root  152 Aug  3 22:05 addres.metadata.json.gz <\/code><\/pre>\n<p><strong>\u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e bson-\u0444\u0430\u0439\u043b\u0430:<br \/><\/strong><br \/><em>zcat posts.bson.gz | bsondump &#8212;pretty<\/em><\/p>\n<pre><code class=\"bash\">root@backup-server:\/# zcat posts.bson.gz | bsondump --pretty 2021-08-03T22:23:57.113+03000 objects found <\/code><\/pre>\n<p><strong>\u0421\u043f\u043e\u0441\u043e\u0431 7 &#8212; \u0411\u0435\u043a\u0430\u043f \u0432\u0441\u0435\u0439 \u0431\u0430\u0437\u044b HABR2 \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 address<\/p>\n<p><\/strong><em>mongodump &#8212;gzip -d HABR2 &#8212;excludeCollection=address<\/em><\/p>\n<pre><code class=\"bash\">root@backup-server:\/tmp\/backup\/dump\/HABR2# mongodump --gzip -d HABR2 --excludeCollection=addres 2021-08-04T00:16:41.482+0300writing HABR2.phone to dump\/HABR2\/phone.bson.gz 2021-08-04T00:16:41.483+0300writing HABR2.posts to dump\/HABR2\/posts.bson.gz 2021-08-04T00:16:41.484+0300done dumping HABR2.phone (0 documents) 2021-08-04T00:16:41.485+0300done dumping HABR2.posts (0 documents) <\/code><\/pre>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u043b\u044e\u0431\u043e\u043c\u0443 \u043a\u0442\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0435\u0442\u0441\u044f \u0441 \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439, \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0432 \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u044d\u0442\u043e\u0439 \u0421\u0423\u0411\u0414. \u0412\u0441\u0435\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/571138\/\"> https:\/\/habr.com\/ru\/articles\/571138\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-386950","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/386950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=386950"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/386950\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=386950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=386950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=386950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}