How to backup SQL Database [Simple ready to use script]

Today, 27th January 2023, Ukraine is still bravely fighting for democratic values, human rights and peace in whole world. Russians ruthlessly kill all civilians in Ukraine including childs and destroy their cities. We are uniting against Putin’s invasion and violence, in support of the people in Ukraine. You can help by donating to Ukrainian's army.

These are ready to use, simplest steps to start doing backups of SQL Database Server right now in the extra-cheap magnetic cloud storage📼. Just set it up and test that backups are there.

Scheduler already inside, you don't need to set up CRON jobs.

For best compatibility, we made our backup inside of the docker container (source is hosted on github), so this guide also covers simple steps to setup docker if you don't have it yet.

To store backups we will use AWS S3 Glacier:

According to Glacier pricing it costs only $0.004 per GB / Month in US regions. If your gzipped database takes 100Mb you can create a backup every week, and after a year you will collect ~5.2Gb of data so it will cost you only $0.02 per month after a year.

With this price you will never want to delete backups - it is cheaper just leave them there forever. Glacier provides 99.999999999% durability of data which means you can always be calm - your data will be there. Glacier uses extra-cheap storages like magnetic tapes/compact disks, which are served by some robots and stored in special storerooms, that's why data retrieval time may take up to several hours.


sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl  gnupg-agent software-properties-common
curl -fsSL | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli
sudo systemctl enable docker
sudo systemctl start docker

sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
version: "3.0"

    image: devforth/docker-database-glacierizer
    network_mode: host # we recommend bind ignoring Docker DNS to access manual
                   # management port easily form host
      PROJECT_NAME: "YourApp"
      CRON: "0 4 * * 0"  # at 04:00 every Sunday

      DATABASE_TYPE: "MySQL"  # possible values [PostgreSQL, MySQL]
      DATABASE_HOST: "<host>"
      DATABASE_NAME: "<database_name>"
      DATABASE_USER: "<username>"
      DATABASE_PASSWORD: "<password>"
      MANUAL_MANAGEMENT_PORT: 33399 # optional

             # optional - to be notified about each backup result

      GLACIER_VAULT_NAME: "<vault_name>"
      AWS_S3_REGION_NAME: "us-east-1" # for US East (N. Virginia)
      AWS_ACCESS_KEY_ID: "<access_key>"
      AWS_SECRET_ACCESS_KEY: "<secret_key>"

To get GLACIER_VAULT_NAME and AWS params see below.

Setup an AWS account and a Glacier bucket

1. Go to and create an account

2. Go to IAM Users and add a new user:

Image for a hint

3. Type the username and set API access:

Image for a hint

4. Add GlacierFullAccess:

Image for a hint

5. Next, Next, Create User

6. Show API Key ID and Secret and use them in docker-compose.yml file

Image for a hint

7. The last thing, create a Glacier Vault. Go here and create a new one with Create Vault button. Remember the vault name which you will enter to use in docker-compose.yml. Also, we recommend creating a vault in US East (N. Virginia) region🌎.

Trigger backup manually

In your project create a script :



set -e

ssh -tt -L $MANAGEMENT_PORT:$MANAGEMENT_PORT [email protected]$DAEMON_HOST > /dev/null &

sleep 1
kill $PID

Add execution permission:

chmod +x

Now you can run this script to immediately trigger backup.


#dockercompose #mysql #postgresql #aws #backups #docker #amazons3glacier
Vladislav Protasenia profile picture
Nov 11, 2020
by Vladislav Protasenia
Did it help you?
Yes !

Best related