Skip to content

Commit

Permalink
Profile Backup: Get the DB backup file name from application
Browse files Browse the repository at this point in the history
Backup script (batch file) now gets the fully formatted DB backup
file name from the application. Previously the file name was been
constructed inside the script and the behavior was not consistent
in different versions of Windows.
  • Loading branch information
pgathogo committed May 14, 2023
1 parent 2aa349c commit 17cdba4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
1 change: 0 additions & 1 deletion stdm/composer/composer_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ def _configure_data_controls(self, composer_data_source):
# Use composer item id since the uuid is stripped off
composerItem = self.composition().itemById(composerId)


if composerItem is not None:
compFieldSelector = ComposerFieldSelector(self, composerItem, self.mainWindow())
compFieldSelector.selectFieldName(composer_data_source.dataFieldName(composerId))
Expand Down
7 changes: 4 additions & 3 deletions stdm/scripts/dbbackup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@
set PGPASSWORD=%5
set BACKUP_FOLDER=%6
set PG_BASE_FOLDER=%7
set BACKUP_FILENAME=%8

REM set log_file=%BACKUP_FOLDER%\backit.log

set BACKUP_FILE="%BACKUP_FOLDER%\%DATABASE_NAME%_%datestr%.backup"
echo backup file name is %BACKUP_FILE%
REM set BACKUP_FILE="%BACKUP_FOLDER%\%DATABASE_NAME%_%datestr%.backup"
echo backup file name is %BACKUP_FILENAME%
echo on

REM PAUSE

%PG_BASE_FOLDER% -h %PG_SERVER% -p %PG_PORT% -U %PG_USER% -F c -b -v -f %BACKUP_FILE% %DATABASE_NAME%
%PG_BASE_FOLDER% -h %PG_SERVER% -p %PG_PORT% -U %PG_USER% -F c -b -v -f %BACKUP_FILENAME% %DATABASE_NAME%

timeout /t 3

15 changes: 10 additions & 5 deletions stdm/ui/db_profile_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
from qgis.PyQt.QtCore import (
Qt,
QDir,
QDateTime
QDateTime,
QCoreApplication
)

from qgis.gui import QgsGui
Expand Down Expand Up @@ -108,6 +109,7 @@ def __init__(self, iface):
self.db_conn = self.db_config.read() # DatabaseConnection
self.txtDBName.setText(self.db_conn.Database)
self.txtAdmin.setText('postgres')
self.lblStatus.setText('')

self.config_templates = []

Expand Down Expand Up @@ -170,8 +172,6 @@ def _profile_templates(self, profile: Profile) ->list[QTreeWidgetItem]:
self.config_templates.append(filepath)
return template_items

# ---------------------------------------------------------------------------

def backup_folder_clicked(self):
self._set_selected_directory(self.edtBackupFolder,
self.tr('Configuration file and DB backup folder')
Expand Down Expand Up @@ -217,6 +217,9 @@ def do_backup(self):
db_name = self.db_conn.Database
db_backup_filename = self._make_backup_filename(db_name)

self.lblStatus.setText('Backup started, please wait...')
QCoreApplication.processEvents()

path_sep = "/"
backup_folder = f"{self.edtBackupFolder.text()}"
db_backup_filepath =f"{backup_folder}{path_sep}{db_backup_filename}"
Expand Down Expand Up @@ -261,6 +264,8 @@ def do_backup(self):
if self.compress_backup(db_name, backup_folder, compressed_files):
self._remove_compressed_files(compressed_files)

self.lblStatus.setText('Backup completed.')

msg_box = QMessageBox()
msg_box.setIcon(QMessageBox.Information)
msg_box.setText(self.tr('Backup completed successfully.'))
Expand Down Expand Up @@ -307,15 +312,15 @@ def backup_database(self, db_conn: DatabaseConnection, user: str,
if backup_util == "":
return False


script_file = "/scripts/dbbackup.bat"
script_filepath = f"{PLUGIN_DIR}{script_file}"
backup_folder = f"{self.edtBackupFolder.text()}"

startup_info = subprocess.STARTUPINFO()
startup_info.dwFlags |=subprocess.STARTF_USESHOWWINDOW
process = subprocess.Popen([script_filepath, db_conn.Database,
db_conn.Host, str(db_conn.Port), user, password, backup_folder, backup_util], startupinfo=startup_info)
db_conn.Host, str(db_conn.Port), user, password, backup_folder, backup_util,
backup_filepath], startupinfo=startup_info)

stdout, stderr = process.communicate()
process.wait()
Expand Down
13 changes: 13 additions & 0 deletions stdm/ui/ui_db_profile_backup.ui
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="lblStatus">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down

0 comments on commit 17cdba4

Please sign in to comment.