Quantcast
Channel: Severalnines - MariaDB
Viewing all articles
Browse latest Browse all 327

ClusterControl Tips & Tricks: Customizing your Database Backups

$
0
0

ClusterControl provides centralized backup management and it supports the standard mysqldump and Percona Xtrabackup backup methods. We believe the chosen command line arguments for the respective methods are optimal for most database workloads, and comply to the MySQL backup best practices. We are influenced by all the feedback we have received over the years, when working with DBAs and sysadmins. However, you might still want to customize your backup. In this post, we will show you how to do this.

By default, ClusterControl will append the following MySQL backup-related lines inside the my.cnf if they aren’t already in there:

[mysqldump]
max_allowed_packet = 512M
# default_character_set = utf8
user=backupuser
password=[random password]

[xtrabackup]
user=backupuser
password=[random password]

The above might not be enough in some circumstances. Let’s see how we customize this for our environment, using the respective backup method.

mysqldump

By default, ClusterControl creates 4 mysqldump files with the following suffix:

  • _triggerseventroutines - Triggers, event and routines
  • _data - Database data
  • _schema - Database schema
  • _mysql - MySQL system database

Let’s say we have 5 databases and we chose to backup all of them. Here is what ClusterControl will execute when performing the backup using mysqldump method (commands are trimmed with backslash for readability):

  • Triggers, event and routines dump file:

    $ /usr/bin/mysqldump \
    --defaults-file=/etc/mysql/my.cnf \
    --flush-privileges \
    --hex-blob \
    --opt \
    --no-create-info \
    --no-data \
    --set-gtid-purged=OFF \
    --triggers \
    -R --events \
    --single-transaction \
    --skip-comments \
    --skip-lock-tables  \
    --skip-add-locks \
    --databases accounting mydb s9s_cmon sakila sbtest
  • Data dump file:

    $ /usr/bin/mysqldump \
    --defaults-file=/etc/my.cnf \
    --flush-privileges \
    --hex-blob \
    --opt \
    --no-create-info \
    --master-data=2 \
    --set-gtid-purged=OFF \
    --skip-triggers \
    --single-transaction \
    --skip-comments \
    --skip-lock-tables \
    --skip-add-locks \
    --databases accounting mydb s9s_cmon sakila sbtest

    *master-data=2 is included only if the MySQL node is generating binary log.

  • Schema dump file:

    $ /usr/bin/mysqldump \
    --defaults-file=/etc/my.cnf \
    --flush-privileges \
    --hex-blob \
    --opt  \
    --no-data \
    --set-gtid-purged=OFF  \
    --add-drop-table \
    --skip-triggers \
    --single-transaction \
    --skip-comments  \
    --skip-lock-tables \
    --databases accounting mydb s9s_cmon sakila sbtest
  • Mysql database dump file:

    $ /usr/bin/mysqldump \
    --defaults-file=/etc/mysql/my.cnf \
    --flush-privileges \
    --hex-blob \
    --opt \
    --set-gtid-purged=OFF \
    --single-transaction \
    --skip-comments \
    --skip-lock-tables \
    --skip-add-locks \
    --databases mysql

From the above command lines, we can see that on each mysqldump command, ClusterControl includes the MySQL configuration file into its --defaults-file argument. By having this, the mysqldump process is able to read the content of the mysqldump directive. By default ClusterControl configures the backup user credentials together with max_allowed_packet, similar to the following:

[mysqldump]
max_allowed_packet = 512M
# default_character_set = utf8
user=backupuser
password=[random password]

The advantage of this is that we can include some extra options for mysqldump. Unfortunately, the --defaults-file argument can only be specified as the foremost argument. Pay attention that the latter command line arguments take precedence on what have been configured inside my.cnf under [mysqldump] directive based on the order they appear. For example, if we add skip-comments=0 inside my.cnf, while at the end of the mysqldump command, there is a --skip-comments (or --skip-comments=1), the former will be ignored and the latter will be used.

Nevertheless, we can still use it as part of our backup customization by using other mysqldump backup options. For example, we can exclude tables that we don’t want to backup by using ignore-table parameter (with “database.table” formatting). Add the following lines into the MySQL configuration file:

[mysqldump]
max_allowed_packet = 512M
# default_character_set = utf8
user=backupuser
password=[random password]
ignore-table=sbtest.sbtest9
ignore-table=sbtest.sbtest10
ignore-table=sbtest.sbtest1

Once configured, we can just trigger a new mysqldump job from ClusterControl and we will have those tables skipped by mysqldump. No MySQL restart is required.

Percona Xtrabackup

ClusterControl executes the Xtrabackup depending on the options you chose. Consider the following:

Based on the above options, the complete Xtrabackup command would be:

$ ulimit -n 256000 && LC_ALL=C /usr/bin/innobackupex --defaults-file=/etc/mysql/my.cnf  --galera-info --parallel 1 --stream=xbstream --no-timestamp .

The first command “ulimit  -n 256000” is to ensure that Percona Xtrabackup has sufficient privileges to access a huge number of file descriptors (in case the databases contain many tables). Take note of the --defaults-file=/etc/mysql/my.cnf, which is similar to mysqldump, where innobackupex reads the content of MySQL configuration on the following directives and variables:

[mysqld]
datadir=[physical path to MySQL data directory]
tmpdir=[path to temporary directory]

[xtrabackup]
user=backupuser
password=[random password]

If you would like to customize the backup options for Percona Xtrabackup, you can add them directly under [xtrabackup] directive. For example, let’s say we want Xtrabackup to print the binary log position when the backup is taken, we can add something like this:

[xtrabackup]
user=backupuser
password=[random password]
slave-info=1

Triggering the xtrabackup job will then include a file called xtrabackup_slave_info file. No MySQL restart is required.

We hope this helps you better manage your MySQL backups!


Viewing all articles
Browse latest Browse all 327

Trending Articles