Migrate PostgreSQL to Podman
This commit is contained in:
parent
1fbe3ceb24
commit
eac272da72
4 changed files with 32 additions and 3 deletions
11
manage.py
11
manage.py
|
@ -13,7 +13,9 @@ def backupProj(project):
|
|||
database = None
|
||||
paths = []
|
||||
|
||||
if project in secrets['postgres'].keys():
|
||||
if project == 'postgres':
|
||||
database = 'all'
|
||||
elif project in secrets['postgres'].keys():
|
||||
database = project
|
||||
|
||||
if project in env['backup'].keys():
|
||||
|
@ -53,8 +55,11 @@ def borgCreate(name, path=None, database=None):
|
|||
if database is not None:
|
||||
print(f"Dumping database {database}.")
|
||||
|
||||
dockerEnv = {"DOCKER_HOST": 'unix:///run/user/1000/docker.sock'}
|
||||
dumpProc = subprocess.run(["docker", "exec", "postgres", "pg_dump", "-c", database], capture_output=True, text=True, env=dockerEnv)
|
||||
if database == 'all':
|
||||
dumpProc = subprocess.run(["podman", "exec", "postgres", "pg_dumpall"], capture_output=True, text=True)
|
||||
else:
|
||||
dumpProc = subprocess.run(["podman", "exec", "postgres", "pg_dump", "-c", database], capture_output=True, text=True)
|
||||
|
||||
if dumpProc.returncode != 0:
|
||||
print(f"Failed to dump database {database}.", file=sys.stderr)
|
||||
return 1
|
||||
|
|
9
projects/postgres/.env.mako
Normal file
9
projects/postgres/.env.mako
Normal file
|
@ -0,0 +1,9 @@
|
|||
<%!
|
||||
import random, string
|
||||
password = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(64))
|
||||
%>
|
||||
POSTGRES_PASSWORD='${password}'
|
||||
# Required for Synapse
|
||||
LANG=C
|
||||
POSTGRES_INITDB_ARGS="--locale=C --encoding=UTF8"
|
||||
|
12
projects/postgres/compose.yaml.mako
Normal file
12
projects/postgres/compose.yaml.mako
Normal file
|
@ -0,0 +1,12 @@
|
|||
services:
|
||||
postgres:
|
||||
container_name: postgres
|
||||
image: docker.io/library/postgres:16-alpine
|
||||
network_mode: pasta:-a,${env['pasta']['postgres']['ipv4']},-a,${env['pasta']['postgres']['ipv6']}
|
||||
restart: always
|
||||
user: ${env['users']['postgres']}:${env['users']['postgres']}
|
||||
env_file: .env.rendered
|
||||
ports:
|
||||
- ${env['ports']['postgres']}:5432
|
||||
volumes:
|
||||
- ${env['volumes']['postgres']['datadir']}:/var/lib/postgresql/data
|
|
@ -63,6 +63,9 @@ pasta:
|
|||
mailserver:
|
||||
ipv4: 10.86.13.1
|
||||
ipv6: fc86::13
|
||||
postgres:
|
||||
ipv4: 10.86.16.1
|
||||
ipv6: fc86::16
|
||||
synapse:
|
||||
ipv4: 10.86.19.1
|
||||
ipv6: fc86::19
|
||||
|
|
Loading…
Reference in a new issue