Skip to content
Snippets Groups Projects
Commit a5652699 authored by Jan Mach's avatar Jan Mach
Browse files

Fix: Forced mentat-backup.py module to use database configuration from file.

parent ce1a2f59
No related branches found
No related tags found
No related merge requests found
......@@ -20,4 +20,4 @@ open-source project.
__author__ = "Jan Mach <jan.mach@cesnet.cz>"
__credits__ = "Pavel Kácha <pavel.kacha@cesnet.cz>, Andrea Kropáčová <andrea.kropacova@cesnet.cz>"
__version__ = "2.7.7"
__version__ = "2.7.8"
......@@ -405,7 +405,10 @@ class MentatBackupScript(mentat.script.base.MentatBaseScript):
try:
dbname = self.config[mentat.const.CKEY_CORE_DATABASE][mentat.const.CKEY_CORE_DATABASE_SQLSTORAGE]['url']
self.logger.info("Performing backup of system database '%s'", dbname)
cmd = r"pg_dump --clean --create --if-exists --format=d --jobs=3 --dbname={} --username=mentat --no-password --file={}".format(dbname, os.path.join(dir_tmp, 'main'))
cmd = r"pg_dump --clean --create --if-exists --format=d --jobs=3 --dbname={} --username=mentat --no-password --file={}".format(
dbname,
os.path.join(dir_tmp, 'main')
)
result['dump_commands'].append(cmd)
self.execute_command(cmd)
cmd = r"chmod 755 {}".format(os.path.join(dir_tmp, 'main'))
......@@ -417,8 +420,15 @@ class MentatBackupScript(mentat.script.base.MentatBaseScript):
# Backup the 'event' in incremental manner (by day).
try:
dbname = self.config[mentat.const.CKEY_CORE_DATABASE][mentat.const.CKEY_CORE_DATABASE_EVENTSTORAGE]['dbname']
cmd = 'psql -d {} -c "copy (select * from events where detecttime >= \'{}\'::timestamptz and detecttime <= \'{}\'::timestamptz limit 50) to stdout" > {}'.format(dbname, time_l.strftime('%Y-%m-%dT%H:%M:%S+00:00'), time_h.strftime('%Y-%m-%dT%H:%M:%S+00:00'), os.path.join(dir_tmp, 'events.dat'))
dbname = self._make_connection_string(
self.config[mentat.const.CKEY_CORE_DATABASE][mentat.const.CKEY_CORE_DATABASE_EVENTSTORAGE]
)
cmd = 'psql {} -c "copy (select * from events where detecttime >= \'{}\'::timestamptz and detecttime <= \'{}\'::timestamptz limit 50) to stdout" > {}'.format(
dbname,
time_l.strftime('%Y-%m-%dT%H:%M:%S+00:00'),
time_h.strftime('%Y-%m-%dT%H:%M:%S+00:00'),
os.path.join(dir_tmp, 'events.dat')
)
result['dump_commands'].append(cmd)
self.execute_command(cmd)
result['dumped_databases'].append(dbname)
......@@ -542,3 +552,11 @@ class MentatBackupScript(mentat.script.base.MentatBaseScript):
self.execute_command(cmd)
else:
self.logger.info("Remote storage already unmounted from path '%s'", mount_point)
def _make_connection_string(self, parameters):
"""
Create PostgreSQL connection string out of connection parameter dictionary.
"""
return "postgresql://{user}:{password}@{host}:{port}/{dbname}".format(
**parameters
)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment