{"id":1236,"date":"2020-11-01T03:07:08","date_gmt":"2020-11-01T03:07:08","guid":{"rendered":"http:\/\/10.0.0.14\/?p=1236"},"modified":"2021-09-07T23:31:30","modified_gmt":"2021-09-07T23:31:30","slug":"tdd-with-django-graphene-docker-part-7-backup-db-makefile","status":"publish","type":"post","link":"https:\/\/tutorials.leesonresearch.com\/tutorials\/2020\/11\/01\/tdd-with-django-graphene-docker-part-7-backup-db-makefile\/","title":{"rendered":"TDD with Gatsby, Django &#038; Docker Part 1, Chapter 07 &#8212; Backup DB &#038; Makefile"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Backing Up Our Database<\/h1>\n\n\n\n<p>One of the final tasks we need to address is how to back up a postgres database running inside a docker container.<\/p>\n\n\n\n<p>Not that difficult:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: Double click to copy; notranslate\" title=\"Double click to copy\">\ndocker exec postgres pg_dump -U user_todo db_todo &gt; db_backups\/backup.sql\n<\/pre><\/div>\n\n\n<p>After running the command above if you check the contents of your server\/db_backups directory you should see a backup.sql file containing all your data. <\/p>\n\n\n\n<p>Our Makefile that we created in Part 1 of this tutorial we will now populate with common Docker shortcut commands that come in handy.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># server\/Makefile\n\nbuild:\n  docker-compose build\n\nreboot:\n  docker-compose down &amp;&amp; docker-compose up -d\n\nprod:\n  docker-compose up -d\n\ndev:\n  docker-compose -f docker-compose.yml -f docker-compose-dev.yml up -d\n\nup-non-daemon:\n  docker-compose up\n\nstart:\n  docker-compose start\n\nstop:\n  docker-compose stop\n\ndown:\n  docker-compose down\n\nrestart:\n  docker-compose stop &amp;&amp; docker-compose start\n\nrestart-dev:\n  docker-compose down &amp;&amp; docker-compose -f docker-compose.yml -f docker-compose-dev.yml up -d\n\nrestart-frontend:\n  docker-compose stop frontend &amp;&amp; docker-compose start frontend\n\nrestart-server:\n  docker-compose stop server &amp;&amp; docker-compose start server\n\nshell-server:\n  docker exec -ti server bash\n\nshell-frontend:\n  docker exec -ti frontend bash\n\nshell-db:\n  docker exec -ti postgres bash\n\nlog-server:\n  docker-compose logs server\n\nlog-frontend:\n  docker-compose logs frontend\n\nlog-db:\n  docker-compose logs postgres\n\ncollectstatic:\n  docker exec server \/bin\/sh -c \"python manage.py collectstatic --noinput\"\n\nmigrations:\n  docker exec server \/bin\/sh -c \"python manage.py makemigrations; python manage.py migrate\"\n<\/pre>\n\n\n\n<p>So now, when we want to reboot instead of having to run:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: Double click to copy; notranslate\" title=\"Double click to copy\">\ndocker-compose down\ndocker-compose up -d\n<\/pre><\/div>\n\n\n<p>&#8230; we can simply run:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: Double click to copy; notranslate\" title=\"Double click to copy\">\nmake reboot\n<\/pre><\/div>\n\n\n<p>&#8230; or running migrations:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: Double click to copy; notranslate\" title=\"Double click to copy\">\nmake migrations\n<\/pre><\/div>\n\n\n<p>&#8230; instead of what we have been doing throughout this tutorial:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: Double click to copy; notranslate\" title=\"Double click to copy\">\ndocker-compose run server .\/manage.py makemigrations\ndocker-compose run server .\/manage.py migrate\n<\/pre><\/div>\n\n\n<p>You will have to have Make installed on your development computer. I&#8217;m using a Mac so for me I only to run:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: Double click to copy; notranslate\" title=\"Double click to copy\">\nbrew install make\n<\/pre><\/div>\n\n\n<p>Windows is something else, I&#8217;ll leave that to you reader to figure that out.<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link\" href=\"todo-app-with-gatsby-django-graphene-docker-pt-6\">&lt; Previous:  Chapter 6<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link\" href=\"tdd-with-gatsby-docker-part-1-setup-dev-env\">Next: Chapter 8 &gt;<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Backing Up Our Database One of the final tasks we need to address is how to back up a postgres database running inside a docker container. Not that difficult: After running the command above if you check the contents of&#8230; <a class=\"more-link\" href=\"https:\/\/tutorials.leesonresearch.com\/tutorials\/2020\/11\/01\/tdd-with-django-graphene-docker-part-7-backup-db-makefile\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":312,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,20,41],"tags":[15,21,42],"class_list":["post-1236","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-django","category-featured-tutorial","category-postgresql","tag-django","tag-docker-compose","tag-postgresql"],"_links":{"self":[{"href":"https:\/\/tutorials.leesonresearch.com\/tutorials\/wp-json\/wp\/v2\/posts\/1236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorials.leesonresearch.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorials.leesonresearch.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorials.leesonresearch.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorials.leesonresearch.com\/tutorials\/wp-json\/wp\/v2\/comments?post=1236"}],"version-history":[{"count":13,"href":"https:\/\/tutorials.leesonresearch.com\/tutorials\/wp-json\/wp\/v2\/posts\/1236\/revisions"}],"predecessor-version":[{"id":2505,"href":"https:\/\/tutorials.leesonresearch.com\/tutorials\/wp-json\/wp\/v2\/posts\/1236\/revisions\/2505"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tutorials.leesonresearch.com\/tutorials\/wp-json\/wp\/v2\/media\/312"}],"wp:attachment":[{"href":"https:\/\/tutorials.leesonresearch.com\/tutorials\/wp-json\/wp\/v2\/media?parent=1236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorials.leesonresearch.com\/tutorials\/wp-json\/wp\/v2\/categories?post=1236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorials.leesonresearch.com\/tutorials\/wp-json\/wp\/v2\/tags?post=1236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}