Search code examples
mysqlansiblemysqlbinlog

Use Ansible playbook to enable mysql bin logging for incremental backups


I have been doing this manually by uncommenting the last lines in the /etc/mysql/mysql.conf.d/mysqld.cnf

# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
# server-id     = 1
# log_bin           = /var/log/mysql/mysql-bin.log
# binlog_expire_logs_seconds    = 2592000
max_binlog_size   = 100M
# binlog_do_db      = include_database_name
# binlog_ignore_db  = include_database_name

However i would like to automate this with Ansible which am using to set up the database which i have already achieved.

Whats the best way to do this?


Solution

  • A common approach and usual way is to use the template module – Template a file out to a target host

    cat templates/mysqld.cnf.j2
    
    # Ansible managed MySQL deamon config
    
    max_binlog_size   = {{ binlog_size }}M
    binlog_do_db      = {{ database_name }}
    binlog_ignore_db  = {{ database_name }}
    

    and a task like

    - name: Make sure MySQL deamon 
      template:
        src: templates/mysqld.cnf.j2
        dest: /etc/mysql/mysql.conf.d/mysqld.cnf
    

    Further Documenation