1
0
mirror of https://github.com/Mailu/Mailu.git synced 2025-11-23 22:04:47 +02:00

Automatic pg_basebackup and wal_archive cleaning

This commit is contained in:
Tim Möhlmann
2018-11-28 18:41:31 +02:00
parent e89d354834
commit e8d05c657f
5 changed files with 42 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import psycopg2
import jinja2
import glob
import os
import subprocess
def setup():
conn = psycopg2.connect(user = 'postgres')
@@ -32,7 +33,6 @@ if not os.path.exists('/data/pg_wal'):
os.system("su - postgres -c 'initdb -D /data'")
# Create backup directory structure, if it does not yet exist
os.system("mkdir -p /backup/dump")
os.system("mkdir -p /backup/wal_archive")
os.system("chown -R postgres:postgres /backup")
@@ -46,5 +46,9 @@ os.system("su - postgres -c 'pg_ctl start -D /data -o \"-h localhost\"'")
setup()
os.system("su - postgres -c 'pg_ctl stop -m smart -w -D /data'")
out=open("/proc/1/fd/1", "w")
err=open("/proc/1/fd/2", "w")
# Run the cron deamon
subprocess.Popen(["crond", "-f", "-d7"], stdout=out, stderr=err)
# Run postgresql service
os.system("su - postgres -c 'postgres -D /data -h \*'")