Skip to content

Script: backup_database

Bruno Galindro da Costa edited this page Sep 6, 2016 · 2 revisions

backup_database

Use this script to execute database backups.

Currently databases supported

MySQL

MongoDB

How to use

This script will execute a database backup based on a configuration file. It is capable to make backup syncronization as it is finish each database dump. After each backup has done, it could send data to zabbix server for monitoring the backup state. The template is located in a separated project.

To execute backups it uses database backup tools, like mysqldump for MySQL and mongodump for MongoDB.

Config file

Sections

  • Default

    • zabbix_server: IP or FQDN of Zabbix Server
    • zabbix_host: Registered Zabbix host that will receive data
    • zabbix_conf: Location of Zabbix Agent conf
    • zabbix_sender_opts: Options to use in zabbix sender. The defaults are: -vv -z zabbix_server -s zabbix_host -k zabbix_key[zabbix_key_param,server]
    • parallel_process: How many database backup tool must be executed in parallel. For example: if you select all databases from a MySQL instance that have 30 databases and set this parameter to 15, the script will execute 15 mysqldump processes for each database in parallel. So, as the dumps are completed, it will get the next database to backup and put into the execution array, trying to keep as maximum executions as possible, but never exceeding the defined limit.
    • mysqldump_bin: Absolute path of mysqldump binary
    • mongodump_bin: Absolute path of mongodump binary
    • aws_cmd: Absolute path of aws binary. It is used for S3 sync
  • Jobs *

{

  "Default" : {
    "zabbix_server" : "zabbix.domain.com",
    "zabbix_host" : "Backup_Server",
    "zabbix_conf" : "/etc/zabbix/zabbix_agentd.conf",
    "zabbix_sender_opts" : "",
    "parallel_process" : "10",
    "mysqldump_bin" : "/usr/bin/mysqldump",
    "aws_cmd" : "/usr/local/bin/aws"
  },

  "Jobs" : [
    {
      "job_name" : "mysql",
      "server" : "10.0.0.1",
      "user" : "root",
      "password" : "secret",
      "databases_regexp" : "*",
      "destination" : "/backup/",
      "zabbix_key" : "backup",
      "zabbix_key_param" : "mysql_amazon_local",
      "backup_window_hours" : 2,
      "compression" : {
        "algorithm" : "gzip",
        "level" : "9"
      },
      "replication" : {
        "azure" : {
          "account_name" : "account",
          "account_key" : "secret",
          "container" : "backup",
          "zabbix_key" : "backup",
          "zabbix_key_param" : "mysql_blobstorage_azure"
        },
        "rsync" : {
          "user" : "backup",
          "host_dest" : "server",
          "ssh_key" : "~/.ssh/id_rsa",
          "zabbix_key" : "backup",
          "zabbix_key_param" : "mysql_rsync_azure"
        },
        "s3" : {
          "aws_s3_bucket_name" : "my_bucket",
          "aws_region" : "sa-east-1",
          "aws_s3_bucket_path" : "/backup/",
          "zabbix_key" : "backup",
          "zabbix_key_param" : "mysql_s3_my_bucket"
        }
      },
      "post_tasks" : {
        "move" : {
          "to" : "/backup/"
        }
      }
    },
    {
      "job_name" : "mongodb",
      "server" : "10.0.0.3",
      "bkp_type" : "mongodb",
      "databases_regexp" : "(^db(?!-demo))",
      "destination" : "/backup_mongodb/",
      "zabbix_key" : "backup",
      "zabbix_key_param" : "mongodb_amazon_local",
      "backup_window_hours" : 2,
      "compression" : {
        "algorithm" : "bzip2",
        "compresslevel" : "9"
      },
      "replication" : {
        "s3" : {
          "aws_s3_bucket_name" : "my_bucket",
          "aws_s3_bucket_path" : "/backup_mongodb/",
          "aws_region" : "us-east-1",
          "zabbix_key" : "backup",
          "zabbix_key_param" : "mongodb_s3_my_bucket"
        }
      }
    }
  ]

}

Clone this wiki locally