I am building a Windows 7 installer with NSIS for internal company use. One step in the install is to backup a Postgres DB using pg_dump.exe, then restore a file packaged in the installed usign pg_restore.exe. These two executables are normal helper tools include with any Postgres installation, so they can be expected to exist on the user's machine. I want to execute this operation like so:
ExecWait 'C:\path\to\file\pg_dump.exe --host localhost --port 5432 --username "postgres" --no-password --format custom --blobs --verbose --file $OUTDIR/myDB.backup myDB' $0
DetailPrint 'Backup DB process return $0'
But the problem I'm having is that the path of executables differs from machine to machine. So I am trying to run a search operation to find the files. Such as this
${Locate} "C:\" "/L=F /M=pg_dump.exe" "locateBackup"
Or this (using locate plugin)
${locate::Open} "C:\" `/F=1 /D=0 /X=exe /-PN="Oracle" /-PF="$WINDIR\System|$WINDIR\System32|$WINDIR\Help" /N=pg_dump.exe /B=1` $0
${locate::Find} $0 $1 $2 $3 $4 $5 $6
Both of those methods fail on Windows 7. The installer crashes when the search traverses certain directories; I'm not sure why.
Next thing I'd like to try is to look up the executables location in the Windows registry, with the NSIS command ReadRegStr
, maybe something like this
ReadRegStr $0 HKLM Software\pg_dump ""
DetailPrint "Its installed at: $0"
But I can't find the right registry key for looking up pg_dump (or pg_restore).
Is there a way to identify the path of installed executables on Windows 7 using native NSIS functions? Or is there a better way to backup and restore Postgres databases with NSIS installers?
You can find the installation directory (if it was installed through the one-click installer) in
HKLM\PostgreSQL\Installation\postgresql-9.1\Base Directory
apparently this key is version dependent. And there can be more than one entry (if more than one version is installed). So you will need to enumerate the entries and pick whatever version fits you.
Then append \bin
to the value obtained from "Base Directory" and pg_dump/pg_restore should be there.