Sign inSign up

pranasnet/sqlbak

By pranasnet

•Updated 3 months ago

Backup, monitor and restore SQL Server, MySQL and PostgreSQL from the web

Image
Databases & storage
8

100K+

pranasnet/sqlbak repository overview

⁠What is SqlBak?

SqlBak⁠ is an application that allows you to create database backups and send them to the cloud storage.

⁠What does this image contain?

This Docker image contains the SqlBak application and utilities for interacting with databases, such as mysql, mysqldump, pssql, pg_dump, etc.

⁠How to use this image?

To start working with SqlBak you need to connect the application to sqlbak.com and set up a connection to the database. You can configure the container in two ways – either by running several commands inside the container, or by passing environment variables to the container.

Setting up SqlBak with commands in a container

When starting one instance of SqlBak, it is more convenient to configure the connection by executing interactive commands using the SqlBak utility inside the container.

Run SqlBak container:

docker run --name sqlbak_container -d -v sqlbak_volume:/opt/sqlbak pranasnet/sqlbak

To link your application to sqlbak.com run the following command:

docker exec -i sqlbak_container sqlbak --register --key=[secret key] --name=[name_of_dashboard]

[secret key] – you can find it on download page

[name_of_dashboard] – specify the name you want to see in sqlbak.com/dashboard

After entering this command, the application will ask you for database connection details.

But you can set up the connection later using the following command:

docker exec sqlbak_container sqlbak --add-connection --db-type=[db_type] --host=[host] --user=[db_user] --password=[db_password]

[db_type] – database type mssql\mysql\postgresql

[host] – database network address

[db_user] – database user

[db_password] – password

⁠Setting up using environment variables

Setting up a SqlBak container through environment variables is useful in automation scripts. To get started, you need to link the container to an account on sqlbak.com and to the database that you want to back up. Connection information must be passed in environment variables:

sqlbak_key – located on the <a href=sqlbak.com/download>download page (secret key)*

sqlbak_name – name to be displayed on sqlbak.com/dashboard

db_type – database type (mysql/postgresql/mssql)*

host – database network address*

user – user to be connected to the database

password – password for connecting to the database*

port – a port for a database connection

Variables marked with an asterisk are required. 

Please note, if the container is already connected to sqlbak.com or dbms, then the transferred environment variables will be ignored. If you need to configure an already connected container, this must be done from inside the container using the SqlBak utility.

Thus, to run the container and immediately configure it, you need to use the following command:

sudo docker run -d \ 
    -e sqlbak_key=[secret_key] \  
    -e sqlbak_name=[name-on-dashboard] \ 
    -e host=[host-name] \  
    -e db_type=[type-of-database] \ 
    -e user=[db_user] \  
    -e password=[db_password] \ 
    -v sqlbak_volume:/opt/sqlbak \  
   pranasnet/sqlbak 

⁠Features of physical backups

Microsoft SQL Server backup and incremental backups for MySQL require file transfer between the runtime environment where the database is located and the SqlBak container. 

To use SqlBak for a Microsoft SQL Server backup, you need to create a volume for the /tmp/sqlbak directory. This directory should be shared for the container with SqlBak and the environment in which the Microsoft SQL Server is located. 

For example, if your SQL Server is on the host system, then when running the SqlBak container, specify the --volume /tmp/sqlbak:/tmp/sqlbak parameter. If your SQL Server is located in another container, then when running the container with the SQL Server, specify --volume sqlbak_backup_folder:/tmp/sqlbak and specify precisely the same for the container with SqlBak. The folder for backups will become shared for both containers.

The situation is similar for MySQL incremental backups, but only for the /var/lib/mysql/ directory. You can use --volume /var/lib/mysql:/var/lib/mysql if the MySQL server is on the host system, or create --volume mysql_inc_dir:/var/lib/mysql for both containers.

⁠Use cases

Connecting SqlBak to amazon RDS PostgreSQL

docker run -d \
    -e sqlbak_key=[secret key] \
    -e sqlbak_name=my_rds_postgresql \
    -e db_type=postgresql \
    -e user=postgres \
    -e password=my-secret-password \
    -e host=myinstanse.rds.amazonaws.com \
    -v sqlbak_volume:/opt/sqlbak \
    --restart unless-stopped \
  pranasnet/sqlbak

Connecting SqlBak to MySQL server that is located on the host system. Volume is created to transfer backup files

docker run -d \
    -e sqlbak_key=[secret key] \
    -e sqlbak_name=postgresql \
    -e db_type=mysql \
    -e user=root \
    -e password=my-secret-password \
    -e host=localhost \
    -p 3306:3306 \
    -v /var/lib/mysql:/var/lib/mysql \
    --restart unless-stopped \
  pranasnet/sqlbak

Example of connecting to a MySQL database with the ability to make incremental backups. In this example, binlog files for incremental backups will be transferred through the db_data volume.

version: '3.3'
services:
 db_mysql:
  image: mysql
  restart: always
  environment:
    MYSQL_ROOT_PASSWORD: example
  networks:
   - overlay
  volumes:
   - db_data:/var/lib/mysql
 sqlbak:
  depends_on:
   - db_mysql
  image: pranasnet/sqlbak
  volumes:
   - db_data:/var/lib/mysql
  environment:
   sqlbak_key: [secret key]
   sqlbak_name: name_on_dashboard
   db_type: mysql
   user: root
   password: example
   host: db_mysql
  networks:
   - overlay
volumes:
 db_data:
networks:
 overlay:

SqlBak configuration together with SQL Server in docker compose file, shared volume is created between containers.

version: '3.3'
services:
 sqlbak:
  image: pranasnet/sqlbak
  volumes:
   - sqlbak_local_data:/opt/sqlbak 
   - backup_folder:/tmp/sqlbak
  environment:
   sqlbak_key: [secret key] 
   sqlbak_name: name_on_dashboard 
   db_type: mssql
   user: sa
   password: secretPassword1
   host: db
  networks:
   - overlay
 db: 
  image: mcr.microsoft.com/mssql/server:2017-CU8-ubuntu
  environment: 
   ACCEPT_EULA: Y 
   SA_PASSWORD: secretPassword1 
  volumes: 
   - backup_folder:/tmp/sqlbak 
  networks: 
   - overlay
volumes: 
 sqlbak_local_data: 
 backup_folder: 
networks: 
 overlay:
⁠Connecting to multiple databases

SqlBak container can be connected to several databases at once. To set new connections, specify the numeral with the connection number (2.3,4 or 5) at the end of the environment variables that are responsible for connecting to the database.

Here's an example of connecting a SqlBak container to two databases at once:

version: '3.3'
services:
 sqlbak:
  image: pranasnet/sqlbak
  volumes:
   - sqlbak_local_data:/opt/sqlbak 
   - backup_folder:/tmp/sqlbak
  environment:
   sqlbak_key: [secret key]
   sqlbak_name: name_on_dashboard 
   db_type: mssql
   user: sa
   password: secretPassword1
   host: db_sql_server
   db_type2: mysql
   user2: root
   password2: example
   host2: db_mysql
   db_type3: mongo
   user3: root
   password3: example
   host3: db_mongo
  networks:
   - overlay
 db_sql_server: 
  image: mcr.microsoft.com/mssql/server:2017-CU8-ubuntu
  environment: 
   ACCEPT_EULA: Y 
   SA_PASSWORD: secretPassword1 
  volumes: 
   - backup_folder:/tmp/sqlbak 
  networks: 
   - overlay
 db_mysql:
  image: mysql
  command: --default-authentication-plugin=mysql_native_password
  restart: always
  environment:
    MYSQL_ROOT_PASSWORD: example
  networks:
   - overlay
 db_mongo:
  image: mongo
  restart: always
  environment:
   MONGO_INITDB_ROOT_USERNAME: root
   MONGO_INITDB_ROOT_PASSWORD: example
  networks:
   - overlay
volumes: 
 sqlbak_local_data: 
 backup_folder: 
networks: 
 overlay:
  
⁠Other notes regarding container use

Since SqlBak provides regular backups, it is recommended to run the container with the parameter --restart unless-stopped.

The data necessary for the application to work is stored in the /opt/sqlbak directory, therefore, for all examples above, volume -v sqlbak_volume:/opt/sqlbak is created, the presence of this volume will allow you to update the application in the future without resetting.

In addition to initializing the container through environment variables, you can configure it using the SqlBak utility located in the container. This can be useful if you want to add multiple connections to databases, or for diagnostic purposes if errors occur during initialization through environment variables. To find out the supported commands run 

docker exec [container-id] sqlbak --help

For more details on supported parameters, see SqlBak on Linux Reference Manual ⁠

Tag summary

Content type

Image

Digest

sha256:16cc9c0ec…

Size

422.6 MB

Last updated

3 months ago

docker pull pranasnet/sqlbak