diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-06-28 12:17:40 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-06-28 12:17:40 +0200 |
commit | 0a145a25c0a8cbcd50d515d2a828bd6665836ddb (patch) | |
tree | c6e3832098d19917b0ba0bcbe119103c632c7d29 /modules/profile/manifests/postgresql/backup_dump.pp | |
parent | f1d583bfdaf881116e5f9ca9e050307e7acdc28e (diff) | |
parent | 3925777d9715d271c0643faef9f520e7816dba89 (diff) | |
download | Puppet-0a145a25c0a8cbcd50d515d2a828bd6665836ddb.tar.gz Puppet-0a145a25c0a8cbcd50d515d2a828bd6665836ddb.tar.zst Puppet-0a145a25c0a8cbcd50d515d2a828bd6665836ddb.zip |
Merge branch 'refactoring' into dev
Diffstat (limited to 'modules/profile/manifests/postgresql/backup_dump.pp')
-rw-r--r-- | modules/profile/manifests/postgresql/backup_dump.pp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/modules/profile/manifests/postgresql/backup_dump.pp b/modules/profile/manifests/postgresql/backup_dump.pp new file mode 100644 index 0000000..10e349a --- /dev/null +++ b/modules/profile/manifests/postgresql/backup_dump.pp | |||
@@ -0,0 +1,53 @@ | |||
1 | define profile::postgresql::backup_dump ( | ||
2 | String $pg_user = "postgres", | ||
3 | String $pg_group = "postgres", | ||
4 | ) { | ||
5 | $base_path = $title | ||
6 | $pg_path = "$base_path/postgresql" | ||
7 | $pg_backup_path = "$base_path/postgresql_backup" | ||
8 | $pg_host = split($base_path, "/")[-1] | ||
9 | |||
10 | ensure_packages(["python", "python-pip"]) | ||
11 | ensure_resource("package", "pylog2rotate", { | ||
12 | source => "git+https://github.com/avian2/pylog2rotate", | ||
13 | ensure => present, | ||
14 | provider => "pip3", | ||
15 | require => Package["python-pip"], | ||
16 | }) | ||
17 | |||
18 | file { $pg_backup_path: | ||
19 | ensure => directory, | ||
20 | owner => $pg_user, | ||
21 | group => $pg_group, | ||
22 | mode => "0700", | ||
23 | require => File[$base_path], | ||
24 | } | ||
25 | |||
26 | cron::job::multiple { "backup_psql_$pg_host": | ||
27 | ensure => "present", | ||
28 | require => [File[$pg_backup_path], File[$pg_path]], | ||
29 | jobs => [ | ||
30 | { | ||
31 | command => "/usr/bin/pg_dumpall -h $pg_path -f $pg_backup_path/\$(date -Iseconds).sql", | ||
32 | user => $pg_user, | ||
33 | hour => "22,4,10,16", | ||
34 | minute => 0, | ||
35 | description => "Backup the database", | ||
36 | }, | ||
37 | { | ||
38 | command => "/usr/bin/rm -f $(ls -1 $pg_backup_path/*.sql | grep -v 'T22:' | sort -r | sed -e '1,12d')", | ||
39 | user => $pg_user, | ||
40 | hour => 3, | ||
41 | minute => 0, | ||
42 | description => "Cleanup the database backups", | ||
43 | }, | ||
44 | { | ||
45 | 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')", | ||
46 | user => $pg_user, | ||
47 | hour => 3, | ||
48 | minute => 1, | ||
49 | description => "Cleanup the database backups exponentially", | ||
50 | }, | ||
51 | ] | ||
52 | } | ||
53 | } | ||