Power Studio Automated Database Backup

It is a good idea to regulary backup your Power Studio database. This page contains a script and instructions to automatically take a backup and write this backup to a unique file.

Backup script

Create specific folder for your backup script e.g. PS_Backup, and create a new batch file databasebackup.bat. In this file paste the following script:

   @echo off
   for /f "tokens=1-4 delims=- " %%i in ("%date%") do (
     set dow=%%i
     set month=%%j
     set day=%%k
     set year=%%l
   )
   set datestr=%year%%month%%day%
   echo datestr is %datestr%
    
   set folder=<Destination folder>
   echo folder is %folder%
	
   set BACKUP_FILE=%folder%\%datestr%_PowerStudio.backup
   echo backup file name is %BACKUP_FILE%
   
   SET PGPASSWORD=<Password>
   echo on
   pg_dump -h <Hostname> -p 5432 -U <Username> -F c -b -v -f %BACKUP_FILE% <Databasename>
  • Change <Destination folder> to the location, the database backups will be stored, e.g. d:\Power_Studio_Backups
  • Change the <Password> setting above to the correct password for the backup users. (make sure there is no spaces after the word PGPASSWORD any spaces will cause this setting not to work.
  • Change <Hostname> either to ip address or dns name of the server hosting Postgresql.
  • Change <Username> to backup user make sure this users has access to database for backup purposes
  • Change <Databasename> to the database name being backed up.
  • Save the file.

Getting the files to run this script

Getting the pg_dump, pg_dumpall binaries by copying them from your PostgreSQL Server install. (e.g. C:\Program Files\PostgreSQL\11\bin) There is no package available to get just these files.

Get the following files:

libeay32.dll
libiconv-2.dll
libintl-8.dll
libintl-9.dll
libpg.dll
libwinpthread-1.dll
msvr120.dll
pg_dump.exe
pg_dumpall.exe
ssleay32.dll
zlib1.dll

Depending on what version PostgreSQL Server you are running, libintl-8.dll or libintl-9.dll may not be available.

You should download and install the Windows C/C++ runtime libraries from Microsoft for the version Postgresql being used, version 11.0 uses VS-2013.

Schedule the script

Create a Task for the MS Task Scheduler.

Once you have chosen the security context the Task in going to run in, it is advised to change the directory security where the backup is run and the files are stored, as a high level user name and password are stored in plain text.