I have written PostgreSQL backups scripts that backup all the databases to file. pgAgent.exe (a scheduling daemon) starts the BAT scripts under the local postgres user.

The normal setup is to backup to a local drive and get the backup program to pick up the files but we have a client that would like to backup to a network drive.

I tried running pgAgent and by extension the scripts under the administration user and still did not have any luck. (same user that had the drive mappings)

When i login to the postgres user by running runas.exe /user:postgres cmd.exe and type cd /D Z: I get the error The system cannot find the drive specified.

Now from what i understand, network drives are mapped on a per user session basis. is there a special trick to accessing the network drives from a command prompt?

  • If the network share is shared to "everyone" the you can use net use Z: \\SERVERNAME\SHARE – trozz Apr 15 '11 at 7:00
  • I made an login for the postgres user and added at the start of the script "net use Z: \\server\share /user:domain\user password" thanks Trozz for pointing me in the right direction :) – Silverfire Apr 15 '11 at 7:26
  • no problem mind just adding a vote to the answer i just attached :) – trozz Apr 15 '11 at 12:56
REM Mount Z:\ as the user with permissions; you may need to add the password
net use z: \\server\share /user:domain\user

REM copy things here
REM ...

REM unmount the drive letter
net use z: /d
  • yea, I suppose that language-specific comments might be helpful... – gWaldo Apr 19 '11 at 0:16

If the network share is shared to "everyone" the you can use net use Z: \\SERVERNAME\SHARE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.