diff --git a/manifests/db_type.pp b/manifests/db_type.pp index a819c28..6448878 100644 --- a/manifests/db_type.pp +++ b/manifests/db_type.pp @@ -74,6 +74,11 @@ define sunetdrive::db_type( content => template($mycnf_path), mode => '0744', } + file { '/usr/local/bin/purge-binlogs': + ensure => present, + content => template('sunetdrive/mariadb/purge-binlogs.erb.sh'), + mode => '0744', + } file { "${mariadb_dir}/scripts/run_manual_backup_dump.sh": ensure => present, content => template('sunetdrive/mariadb/run_manual_backup_dump.erb.sh'), @@ -84,6 +89,13 @@ define sunetdrive::db_type( content => template('sunetdrive/mariadb/rename-docker.sh'), mode => '0744', } + sunet::scriptherder::cronjob { 'purge_binlogs': + cmd => "/usr/local/bin/purge-binlogs", + hour => '6', + minute => '0', + ok_criteria => ['exit_status=0','max_age=2d'], + warn_criteria => ['exit_status=1','max_age=3d'], + } if $is_multinode { $docker_compose = $override_compose } else { diff --git a/templates/mariadb/purge-binlogs.erb.sh b/templates/mariadb/purge-binlogs.erb.sh new file mode 100644 index 0000000..9216db9 --- /dev/null +++ b/templates/mariadb/purge-binlogs.erb.sh @@ -0,0 +1,3 @@ +#!/bin/bash +six_hours_ago=$(date -d "6 hours ago" "+%Y-%m-%d %H:%M:%S") +docker exec mariadb_db_1 mysql -u root -p'<%= @mysql_root_password %>' -N -B -e "PURGE BINARY LOGS BEFORE '${six_hours_ago}'"