Purge binlogs regularly

This commit is contained in:
Micke Nordin 2023-03-24 16:26:56 +01:00
parent 8386df91de
commit 6dfe1496a4
Signed by untrusted user: Micke
GPG key ID: 0DA0A7A5708FE257
2 changed files with 15 additions and 0 deletions

View file

@ -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 {

View file

@ -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}'"