79 lines
1.7 KiB
Python
Executable File
79 lines
1.7 KiB
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import os
|
|
import argparse
|
|
from subprocess import run
|
|
from datetime import datetime
|
|
|
|
auth_tables = [
|
|
'admission',
|
|
'admissions_roles',
|
|
'emailToken',
|
|
'invite',
|
|
'invites_roles',
|
|
'passwordToken',
|
|
'role',
|
|
'user',
|
|
'users_roles',
|
|
]
|
|
|
|
accounting_tables = [
|
|
'account',
|
|
'accountBalance',
|
|
'aliasesToSupplier',
|
|
'dimension',
|
|
'entry',
|
|
'file',
|
|
'filesToInvoice',
|
|
'financialYear',
|
|
'invoice',
|
|
'journal',
|
|
'object',
|
|
'supplier',
|
|
'supplierType',
|
|
'transaction',
|
|
'transactionsToObjects',
|
|
]
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('-D', '--dir', help='The local location', default='./docker/postgres')
|
|
parser.add_argument('-s', '--schema', help='Dump schema')
|
|
parser.add_argument('-d', '--data', help='Dump')
|
|
parser.add_argument('--auth', action='store_true')
|
|
parser.add_argument('--accounting', action='store_true')
|
|
parser.add_argument('tables', type=str, nargs='*', help='The tables to dump')
|
|
args = parser.parse_args()
|
|
|
|
command = ['docker-compose', 'exec', '-T', 'postgres', 'pg_dump', '-U', 'brf', '-d', 'brf', '-O']
|
|
|
|
for enabled, tables in [
|
|
(args.tables, args.tables),
|
|
(args.auth, auth_tables),
|
|
(args.accounting, accounting_tables),
|
|
]:
|
|
if enabled:
|
|
for table in tables:
|
|
command.extend(['-t', f'"{table}"'])
|
|
|
|
if args.schema:
|
|
print('dumping schema...')
|
|
|
|
with open(os.path.join(args.dir, args.schema), 'w') as f:
|
|
run(
|
|
[ *command, '-s'],
|
|
stdout=f,
|
|
stderr=None
|
|
)
|
|
print(' done!')
|
|
|
|
if args.data:
|
|
print('dumping data...')
|
|
with open(os.path.join(args.dir, args.data), 'w') as f:
|
|
run(
|
|
[ *command, '-a'],
|
|
stdout=f,
|
|
stderr=None
|
|
)
|
|
print(' done!')
|