1 define profile::postgresql::backup_dump (
2 String $pg_user = "postgres",
3 String $pg_group = "postgres",
4 Optional[Variant[String, Integer]] $pg_port = undef,
7 $pg_path = "$base_path/postgresql"
8 $pg_backup_path = "$base_path/postgresql_backup"
9 $pg_host = split($base_path, "/")[-1]
11 ensure_packages(["python", "python-pip"])
12 ensure_resource("package", "pylog2rotate", {
13 source => "git+https://github.com/avian2/pylog2rotate",
16 require => Package["python-pip"],
19 file { $pg_backup_path:
24 require => File[$base_path],
27 if $pg_port and !empty($pg_port) {
28 $pg_port_arg = " -p $pg_port"
33 cron::job::multiple { "backup_psql_$pg_host":
35 require => [File[$pg_backup_path], File[$pg_path]],
38 command => "/usr/bin/pg_dumpall -h $pg_path$pg_port_arg -f $pg_backup_path/\$(date -Iseconds).sql",
42 description => "Backup the database",
45 command => "/usr/bin/rm -f $(ls -1 $pg_backup_path/*.sql | grep -v 'T22:' | sort -r | sed -e '1,12d')",
49 description => "Cleanup the database backups",
52 command => "cd $pg_backup_path ; /usr/bin/rm -f $(ls -1 *T22*.sql | log2rotate --skip 7 --fuzz 7 --delete --format='%Y-%m-%dT%H:%M:%S+02:00.sql')",
56 description => "Cleanup the database backups exponentially",