<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Vivek Shukla - Docker</title>
    <subtitle>I am a Software Engineer from India. I am currently building Daestro. I work in Rust, Javascript and Python.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://vshukla.com/tags/docker/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://vshukla.com/tags/docker/"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2025-04-23T00:00:00+00:00</updated>
    <id>https://vshukla.com/tags/docker/atom.xml</id>
    <entry xml:lang="en">
        <title>docker buildx: Multi-platform Builds</title>
        <published>2025-04-23T00:00:00+00:00</published>
        <updated>2025-04-23T00:00:00+00:00</updated>
        <author>
          <name>Vivek Shukla</name>
        </author>
        <link rel="alternate" type="text/html" href="https://vshukla.com/snippets/docker-buildx-multi-platform/"/>
        <id>https://vshukla.com/snippets/docker-buildx-multi-platform/</id>
        <summary type="html">How to build multi-platform images with Docker Buildx</summary>
        <content type="html" xml:base="https://vshukla.com/snippets/docker-buildx-multi-platform/">&lt;p&gt;Tested on: Ubuntu 22.04 LTS&lt;br &#x2F;&gt;
Docker Version: 28.1.1&lt;br &#x2F;&gt;
Docker Buildx Version: v0.23.0&lt;&#x2F;p&gt;
&lt;p&gt;Documentation: &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.docker.com&#x2F;build&#x2F;building&#x2F;multi-platform&#x2F;#qemu&quot;&gt;Multi-platform Builds&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;# check if buildx is installed&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; buildx version&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;# installing and registering QEMU&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --privileged --rm&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; tonistiigi&#x2F;binfmt&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --install&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; all&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;# create new build that runs in docker container&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; buildx create&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --name&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; mybuilder&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --driver&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; docker-container&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;# switching to our builder&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; buildx use mybuilder&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;# build and pushing image directly to image store (make sure you are logged in)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; buildx build&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --platform&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; linux&#x2F;amd64,linux&#x2F;arm64&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -t&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;usernam&lt;&#x2F;span&gt;&lt;span&gt;e&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;image_nam&lt;&#x2F;span&gt;&lt;span&gt;e&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ta&lt;&#x2F;span&gt;&lt;span&gt;g&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; .&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --push&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
    </entry>
    <entry xml:lang="en">
        <title>Docker Image Publishing</title>
        <published>2025-04-23T00:00:00+00:00</published>
        <updated>2025-04-23T00:00:00+00:00</updated>
        <author>
          <name>Vivek Shukla</name>
        </author>
        <link rel="alternate" type="text/html" href="https://vshukla.com/snippets/docker-image-publishing/"/>
        <id>https://vshukla.com/snippets/docker-image-publishing/</id>
        <summary type="html">How to publish a Docker image to a registry</summary>
        <content type="html" xml:base="https://vshukla.com/snippets/docker-image-publishing/">&lt;p&gt;&lt;strong&gt;Login&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; login&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --username&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;usernam&lt;&#x2F;span&gt;&lt;span&gt;e&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --password-stdin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Build&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; build .&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -t&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;image_nam&lt;&#x2F;span&gt;&lt;span&gt;e&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ta&lt;&#x2F;span&gt;&lt;span&gt;g&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Tag&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; tag&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;image_nam&lt;&#x2F;span&gt;&lt;span&gt;e&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ta&lt;&#x2F;span&gt;&lt;span&gt;g&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;usernam&lt;&#x2F;span&gt;&lt;span&gt;e&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;image_nam&lt;&#x2F;span&gt;&lt;span&gt;e&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ta&lt;&#x2F;span&gt;&lt;span&gt;g&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Push&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; push&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;usernam&lt;&#x2F;span&gt;&lt;span&gt;e&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;image_nam&lt;&#x2F;span&gt;&lt;span&gt;e&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ta&lt;&#x2F;span&gt;&lt;span&gt;g&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
    </entry>
    <entry xml:lang="en">
        <title>Plausible Docker Volume Backup</title>
        <published>2025-03-18T00:00:00+00:00</published>
        <updated>2025-03-18T00:00:00+00:00</updated>
        <author>
          <name>Vivek Shukla</name>
        </author>
        <link rel="alternate" type="text/html" href="https://vshukla.com/snippets/plausible-docker-volume-backup/"/>
        <id>https://vshukla.com/snippets/plausible-docker-volume-backup/</id>
        <summary type="html">Backup Plausible data from docker volumes and upload using rclone</summary>
        <content type="html" xml:base="https://vshukla.com/snippets/plausible-docker-volume-backup/">&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;#!&#x2F;bin&#x2F;bash&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;home&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&#x2F;home&#x2F;&amp;lt;update&amp;gt;&#x2F;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;dest&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&amp;lt;update&amp;gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;bucket&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&amp;lt;update&amp;gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;pg_container_id&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&amp;lt;update&amp;gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;ch_container_id&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&amp;lt;update&amp;gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;passphrase&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&amp;lt;update&amp;gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;date&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;$(&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;date&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; +&amp;quot;%Y%m%d%H%M%S&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;pl_repo&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$home&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&#x2F;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$date&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;_plausible.tar.gz&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;pl_repo_gpg&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$pl_repo&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;.gpg&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;pg_data&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$home&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&#x2F;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$date&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;_db-data.tar.gz&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;pg_data_gpg&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$pg_data&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;.gpg&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;ch_data&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$home&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&#x2F;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$date&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;_event-data.tar.gz&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;ch_data_gpg&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$ch_data&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;.gpg&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;# stopping postgres and clickhouse containers before backup&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; container stop&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $pg_container_id $ch_container_id&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;# creating gzip file&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;tar&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --exclude=images --exclude-vcs -czf&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $pl_repo&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -C&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $home&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; plausible&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; tar&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -czf&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $pg_data&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -C&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &#x2F;var&#x2F;lib&#x2F;docker&#x2F;volumes&#x2F; plausible_db-data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; tar&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -czf&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $ch_data&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -C&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &#x2F;var&#x2F;lib&#x2F;docker&#x2F;volumes&#x2F; plausible_event-data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;# starting containers&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; container start&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $pg_container_id $ch_container_id&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;# encrypting&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $passphrase&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; gpg&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --batch --yes --passphrase-fd&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -o&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $pl_repo_gpg&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --symmetric&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $pl_repo&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $passphrase&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; gpg&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --batch --yes --passphrase-fd&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -o&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $pg_data_gpg&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --symmetric&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $pg_data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $passphrase&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; gpg&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --batch --yes --passphrase-fd&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -o&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $ch_data_gpg&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; --symmetric&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $ch_data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;# saving to s3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;rclone&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; copy&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $pl_repo_gpg $dest&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$bucket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;rclone&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; copy&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $pg_data_gpg $dest&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$bucket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;rclone&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; copy&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $ch_data_gpg $dest&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$bucket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;# deleting local copies&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;rm&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -f&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $pl_repo $pg_data $ch_data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;rm&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -f&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $pl_repo_gpg $pg_data_gpg $ch_data_gpg&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
    </entry>
    <entry xml:lang="en">
        <title>Automate Postgres Database Backup and Upload to S3</title>
        <published>2023-10-20T00:00:00+00:00</published>
        <updated>2023-10-20T00:00:00+00:00</updated>
        <author>
          <name>Vivek Shukla</name>
        </author>
        <link rel="alternate" type="text/html" href="https://vshukla.com/tech/automate-postgres-database-backup-and-upload/"/>
        <id>https://vshukla.com/tech/automate-postgres-database-backup-and-upload/</id>
        <summary type="html">In this tutorial we will create a bash script to automate postgres database backup from a docker container and native postgres installation then upload to S3 based storage system.</summary>
        <content type="html" xml:base="https://vshukla.com/tech/automate-postgres-database-backup-and-upload/">&lt;p&gt;Database is a very critical system for an application. To prepare for any disaster we all must take regular backups of our database.&lt;&#x2F;p&gt;
&lt;p&gt;In this tutorial we will create a bash script to automate &lt;a href=&quot;&#x2F;tech&#x2F;postgres-database-backup-from-docker-container&quot;&gt;postgres database backup from a docker container&lt;&#x2F;a&gt; and native postgres installation then upload to S3 based storage system.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-we-will-cover&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-we-will-cover&quot; aria-label=&quot;Anchor link for: what-we-will-cover&quot;&gt;🔗&lt;&#x2F;a&gt;What we will cover&lt;&#x2F;h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Write db backup automation script for docker and non-docker based system&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Upload backup file to AWS S3&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Setup the cron job for daily backup&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;steps&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#steps&quot; aria-label=&quot;Anchor link for: steps&quot;&gt;🔗&lt;&#x2F;a&gt;Steps&lt;&#x2F;h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Move to your project folder, where docker-compose.yml is.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Take the database backup in container&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Copy the backup file from container filesystem to our desired location&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Delete the backup file inside the container&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Upload backup file to S3&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Delete the local backup file&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Code snippet below covers step 1 to 4. But it is not optimal, later we will make modification so that we can easily automate it and make it re-usable.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; project_dir&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; compose exec db_service_name sh&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -c&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &amp;quot;pg_dump -U db_user db_name &amp;gt; filename&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; compose cp db_service_name:filename destination&#x2F;filename&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; compose exec db_service_name rm filename&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;upload-to-s3&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#upload-to-s3&quot; aria-label=&quot;Anchor link for: upload-to-s3&quot;&gt;🔗&lt;&#x2F;a&gt;Upload to S3&lt;&#x2F;h2&gt;
&lt;p&gt;To upload file to S3, we need to have aws cli installed, you can follow &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.aws.amazon.com&#x2F;cli&#x2F;latest&#x2F;userguide&#x2F;getting-started-install.html&quot;&gt;this guide from AWS docs to install awscli&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;After installing awscli, you need to run &lt;code&gt;aws configure&lt;&#x2F;code&gt; and provide your key id and key secret. You can use any S3 based storage system here.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;aws s3 cp filename s3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;your&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;bucket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you are using some other S3 based storage system then you’ll have to provide custom &lt;code&gt;--endpoint-url&lt;&#x2F;code&gt; argument here, make sure you read the respective docs for this.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;full-script&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#full-script&quot; aria-label=&quot;Anchor link for: full-script&quot;&gt;🔗&lt;&#x2F;a&gt;Full Script&lt;&#x2F;h2&gt;
&lt;p&gt;We have laid out all the steps and code to accomplish that, now let’s modify in such a way that we can easily automate it and make it reusable.&lt;&#x2F;p&gt;
&lt;p&gt;The filename is created based on the current datetime of the system, so that we can avoid ambiguity and exactly know how old is the backup file.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;for-docker-compose&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#for-docker-compose&quot; aria-label=&quot;Anchor link for: for-docker-compose&quot;&gt;🔗&lt;&#x2F;a&gt;For docker compose&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;#!&#x2F;bin&#x2F;bash&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;############## ✅ Update These Values ##################&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;directory&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;your-project-dir&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;home&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&#x2F;home&#x2F;&amp;lt;user&amp;gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;db_service_name&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;db&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;db_user&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;db_user&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;db_name&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;db_name&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;#####################################################&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;############ 🔴 CHANGE WITH CAUTION 🔴 #############&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;date&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;$(&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;date&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; +&amp;quot;%Y-%m-%d-%H:%M:%S&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$db_name&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;_&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$date&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;.sql&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $home&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $directory&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; compose exec&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $db_service_name&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; sh&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -c&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &amp;quot;pg_dump -U &lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$db_user $db_name&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &amp;gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$filename&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; compose cp&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $db_service_name&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$filename $home&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&#x2F;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$filename&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; compose exec&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $db_service_name&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; rm&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $filename&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $home&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;#####################################################&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;#####################################################&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;############## ✅ CAN CHANGE BELOW ##################&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;aws&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; s3 cp&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $filename&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; s3:&#x2F;&#x2F;your-bucket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;rm&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $filename&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;At the top, you’ve to update variable values based on your project and directory structure, and the main code will use that to backup the database.&lt;&#x2F;p&gt;
&lt;p&gt;At the end of script, we have aws command to copy the backup file to S3, here you need to update bucket name and if you are using other S3 storage provider (other than AWS), then &lt;code&gt;--endpoint-url&lt;&#x2F;code&gt; argument with appropriate value.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;for-native-postgres-installation&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#for-native-postgres-installation&quot; aria-label=&quot;Anchor link for: for-native-postgres-installation&quot;&gt;🔗&lt;&#x2F;a&gt;For Native Postgres Installation&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;#!&#x2F;bin&#x2F;bash&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;############## ✅ Update These Values ##################&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;home&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&#x2F;home&#x2F;&amp;lt;user&amp;gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;db_user&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;db_user&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;db_name&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;db_name&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;#####################################################&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;############ 🔴 CHANGE WITH CAUTION 🔴 ##############&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;date&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;$(&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;date&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; +&amp;quot;%Y-%m-%d-%H:%M:%S&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$db_name&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;_&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$date&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;.sql&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;ch&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $home&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;pg_dump&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -U&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $db_user $db_name&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $filename&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;#####################################################&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-comment&quot;&gt;############## ✅ CAN CHANGE BELOW ##################&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;aws&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; s3 cp&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $filename&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; s3:&#x2F;&#x2F;urlify-db-backup&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;rm&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $filename&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;When running pg_dump in the native installation, there are two ways postgres will try to authenticate the user.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;auth-peer.html&quot;&gt;Peer based authentication&lt;&#x2F;a&gt;: It will check if the current user (system logged in user) is same as user passed to pg_dump.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;If peer auth fails then postgres looks for &lt;code&gt;.pgpass&lt;&#x2F;code&gt; file in home directory for the password.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;If both fails then it might ask for password.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;So, make sure you use 1st method and run the script on the same user as the one passed to pg_dump.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;setup-cron-job&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#setup-cron-job&quot; aria-label=&quot;Anchor link for: setup-cron-job&quot;&gt;🔗&lt;&#x2F;a&gt;Setup Cron Job&lt;&#x2F;h2&gt;
&lt;p&gt;To automate backup and upload of our database, we will use crontab. It comes built-in with almost all the Linux distros and are very easy to setup.&lt;&#x2F;p&gt;
&lt;p&gt;Give your script executable permission:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;chmod&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; +x db_backup.sh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Open crontab:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;crontab&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -e&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will open up crontab in your prefered choice of editor. Use the below statement to run the backup script everyday at 12 PM.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0 12 * * * &#x2F;home&#x2F;&amp;lt;user&amp;gt;&#x2F;db_backup.sh &amp;gt;&amp;gt; cron.log 2&amp;gt;&amp;amp;1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Create cron.log file&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;touch&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; cron.log&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Use full path if cron.log is not in current user’s home folder.&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>How To Take Postgres Database Backup From Docker Container</title>
        <published>2023-10-18T00:00:00+00:00</published>
        <updated>2023-10-18T00:00:00+00:00</updated>
        <author>
          <name>Vivek Shukla</name>
        </author>
        <link rel="alternate" type="text/html" href="https://vshukla.com/tech/postgres-database-backup-from-docker-container/"/>
        <id>https://vshukla.com/tech/postgres-database-backup-from-docker-container/</id>
        <summary type="html">In this tutorial we are gonna use docker exec and cp command along with pg_dump to take Postgres database backup from docker container.</summary>
        <content type="html" xml:base="https://vshukla.com/tech/postgres-database-backup-from-docker-container/">&lt;p&gt;To take database backup in Postgres we use pg_dump. &lt;code&gt;pg_dump&lt;&#x2F;code&gt; is a utility provided by PostgreSQL to &lt;a href=&quot;&#x2F;tech&#x2F;backup-and-restore-postgresql-database-dump-in-ubuntu&quot;&gt;create the database backup&lt;&#x2F;a&gt;. We are gonna use docker &lt;code&gt;exec&lt;&#x2F;code&gt; and &lt;code&gt;cp&lt;&#x2F;code&gt; command along with pg_dump to take Postgres database backup from docker container.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;pg-dump&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#pg-dump&quot; aria-label=&quot;Anchor link for: pg-dump&quot;&gt;🔗&lt;&#x2F;a&gt;pg_dump&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s take a look at how to take backup with &lt;code&gt;pg_dump&lt;&#x2F;code&gt; command:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;pg_dump&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -U&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; your_db_user&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -d&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; your_db_name&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; db_backup.sql&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is straight forward, pass your db username, database name that you want to take backup of and the backup filename which would be created.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;docker-exec&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#docker-exec&quot; aria-label=&quot;Anchor link for: docker-exec&quot;&gt;🔗&lt;&#x2F;a&gt;docker exec&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s do the same thing on Docker, for that we will use &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.docker.com&#x2F;engine&#x2F;reference&#x2F;commandline&#x2F;exec&#x2F;&quot;&gt;docker exec&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function&quot;&gt; exec&lt;&#x2F;span&gt;&lt;span&gt; container_name_or_id sh&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt;c&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &amp;quot;pg_dump -U your_db_user -d your_db_name &amp;gt; db_backup.sql&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Make sure that the specified container is running, since &lt;code&gt;docker exec&lt;&#x2F;code&gt; command executes on the running container.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;docker-cp&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#docker-cp&quot; aria-label=&quot;Anchor link for: docker-cp&quot;&gt;🔗&lt;&#x2F;a&gt;docker cp&lt;&#x2F;h2&gt;
&lt;p&gt;The docker exec command created the database backup but it’s inside the container file system. So now we need to copy that file from container to our file system.&lt;&#x2F;p&gt;
&lt;p&gt;For that purpose docker gives us &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.docker.com&#x2F;engine&#x2F;reference&#x2F;commandline&#x2F;cp&#x2F;&quot;&gt;docker cp&lt;&#x2F;a&gt;, which we can use to copy to&#x2F;from the container’s filesystem.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; cp container_name_or_id:db_backup.sql your_destination&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now, we have copied our database backup file to our filesystem, it’s time to delete the one from our container. To delete backup file from container do this:&lt;&#x2F;p&gt;
&lt;p&gt;docker exec container_name_or_id rm db_backup.sql&lt;&#x2F;p&gt;
&lt;h2 id=&quot;all-commands-for-docker&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#all-commands-for-docker&quot; aria-label=&quot;Anchor link for: all-commands-for-docker&quot;&gt;🔗&lt;&#x2F;a&gt;All Commands For docker&lt;&#x2F;h2&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; exec container_name_or_id sh&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -c&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &amp;quot;pg_dump -U your_db_user -d your_db_name &amp;gt; db_backup.sql&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; cp container_name_or_id:db_backup.sql your_destination&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; exec container_name_or_id rm db_backup.sql&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;docker-compose&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#docker-compose&quot; aria-label=&quot;Anchor link for: docker-compose&quot;&gt;🔗&lt;&#x2F;a&gt;docker compose&lt;&#x2F;h2&gt;
&lt;p&gt;You can run the same commands just use &lt;code&gt;docker compose&lt;&#x2F;code&gt; instead of just &lt;code&gt;docker&lt;&#x2F;code&gt;, and replace container name&#x2F;id with service name.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; compose exec service_name sh&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other&quot;&gt; -c&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &amp;quot;pg_dump -U your_db_user -d your_db_name &amp;gt; db_backup.sql&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; compose cp service_name:db_backup.sql your_destination&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; compose exec service_name rm db_backup.sql&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
    </entry>
</feed>
