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

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

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 setup 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.

Source

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

sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(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"

services:
  database_glacierizer:
    image: devforth/docker-database-glacierizer
    environment:
      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>"

      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 https://portal.aws.amazon.com/billing/signup#/start and create an account

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

Image for a hint

3. Type 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. Last thing, create a Glacier Vault. Go here and create a new one with Create Vault button. Remember vault name which you will enter to use it in docker-compose.yml. Also, we recommend creating a vault in US East (N. Virginia) regionšŸŒŽ.

Image for a hint

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

Best related