<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Vivek Shukla - Backup</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/backup/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://vshukla.com/tags/backup/"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2025-03-18T00:00:00+00:00</updated>
    <id>https://vshukla.com/tags/backup/atom.xml</id>
    <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>
</feed>
