{"id":6110,"date":"2021-02-06T18:30:09","date_gmt":"2021-02-06T13:00:09","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=6110"},"modified":"2021-02-06T18:30:14","modified_gmt":"2021-02-06T13:00:14","slug":"how-to-backup-our-mongodb-and-push-the-file-into-aws-s3-in-ubuntu","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/how-to-backup-our-mongodb-and-push-the-file-into-aws-s3-in-ubuntu\/","title":{"rendered":"How to backup our MongoDB and push the file into AWS S3 in Ubuntu"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Please follow the below steps to backup the MongoDB.<br>1) Install AWS CLI with the below command.<br><span class=\"has-inline-color has-vivid-cyan-blue-color\">pip install awscli &#8211;upgrade &#8211;user<\/span><br>2) Configure AWS client with the below command.<br><span class=\"has-inline-color has-vivid-cyan-blue-color\">aws configure<\/span><br>3) After running the above command it will ask for the below details which are related to IAM user. If you have not created IAM user, create and give the details.<br><span class=\"has-inline-color has-vivid-cyan-blue-color\">AWS Access Key ID [None]: <strong><em>KEY <\/em><\/strong><br>AWS Secret Access Key [None]: <strong><em>SECRET <\/em><\/strong><br>Default region name [None]: <strong><em>region <\/em><\/strong><br>Default output format [None]: <strong><em>json<\/em><\/strong><\/span><br>4) Create a directory scripts wherever you wish and paste the below script in a file( ex:- dbbackup.sh) under that directory. Before that make a directory db_backups and give that path in the script.<br><span class=\"has-inline-color has-vivid-cyan-blue-color\">backup_name=~\/db_backups-`date +%Y-%m-%d-%H%M` <br>mongodump &#8211;out $backup_name <br>tar czf $backup_name.tar.gz $backup_name <br>aws s3 cp $backup_name.tar.gz s3:\/\/my_bucket\/db_backups\/ <br>rm -rf $backup_name <br>rm $backup_name.tar.gz<\/span><br>5) The last step is to configure cron to run the script every day, we should first open cron file:<br><span class=\"has-inline-color has-vivid-cyan-blue-color\">crontab -e<\/span><br>6) Add something like below<br><span class=\"has-inline-color has-vivid-cyan-blue-color\">0 0 * * * \/bin\/bash ~\/bin\/db-backups.sh &gt;&gt; ~\/logs\/db_backups.log 2&gt;&amp;1<\/span><br>7) The above line asks cron to run the script every day at midnight.<br>8) To test it, run the below command<br><span class=\"has-inline-color has-vivid-cyan-blue-color\">\/bin\/bash ~\/bin\/db-backups.sh<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also we can wait to the next day and verify in our Amazon Web Services account that the file was created.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Please follow the below steps to backup the MongoDB.1) Install AWS CLI with the below command.pip install awscli &#8211;upgrade &#8211;user2) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1019],"tags":[804,182,817,816],"class_list":["post-6110","post","type-post","status-publish","format-standard","hentry","category-cloud-aws","tag-aws-s3","tag-backup","tag-backup-mongodb-and-push-file-into-aws-s3","tag-mongodb","psol-cat-cloud-aws"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1Ay","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/6110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=6110"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/6110\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=6110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=6110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=6110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}