postgres backup script and popen2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • flupke

    #1

    postgres backup script and popen2

    Hi,

    i made a backup script to backup my postgres database.
    Problem is that it prompts for a password. It thought i
    could solve this by using popen2.
    I tested popen2 with dir (i'm on windows 2000, python 2.4.3)
    and it works.
    However when i try popen2 and my pg_dump command, it prompts
    for a password and I was under the impression that i was
    going to be able to dynamically communicate with the process.

    sin, sout = popen2(backup_c ommand)
    sin.readline() # the password prompt
    sout.write("pas sword")
    sin.readlines()

    How can i catch the password prompt and feed the password
    from my code?

    Thanks,
    Benedict
  • =?ISO-8859-1?Q?Ma=EBl_Benjamin_Mettler?=

    #2
    Re: postgres backup script and popen2

    Use pexpect: http://pexpect.sourceforge.net/

    flupke schrieb:
    Hi,
    >
    i made a backup script to backup my postgres database.
    Problem is that it prompts for a password. It thought i
    could solve this by using popen2.
    I tested popen2 with dir (i'm on windows 2000, python 2.4.3)
    and it works.
    However when i try popen2 and my pg_dump command, it prompts
    for a password and I was under the impression that i was
    going to be able to dynamically communicate with the process.
    >
    sin, sout = popen2(backup_c ommand)
    sin.readline() # the password prompt
    sout.write("pas sword")
    sin.readlines()
    >
    How can i catch the password prompt and feed the password
    from my code?
    >
    Thanks,
    Benedict

    Comment

    • Gabriel Genellina

      #3
      Re: postgres backup script and popen2

      On 8 feb, 10:27, Maël Benjamin Mettler <m...@mediamong er.chwrote:
      flupke schrieb:
      i made a backup script to backup my postgres database.
      Problem is that it prompts for a password. It thought i
      could solve this by using popen2.
      >
      Use pexpect:http://pexpect.sourceforge.net/
      pexpect could work. But a better way would be to supply the password
      on the command line. I don't know how postgres does that things, but I
      hope there is some way to automate the backup process...

      --
      Gabriel Genellina

      Comment

      • Gabriel Genellina

        #4
        Re: postgres backup script and popen2

        On 8 feb, 13:29, Jean-Paul Calderone <exar...@divmod .comwrote:
        On 8 Feb 2007 08:23:49 -0800, Gabriel Genellina <gagsl...@yahoo .com.arwrote:
        On 8 feb, 10:27, Maël Benjamin Mettler <m...@mediamong er.chwrote:
        flupke schrieb:
        i made a backup script to backup my postgres database.
        Problem is that it prompts for a password. It thought i
        could solve this by using popen2.
        >>
        pexpect could work. But a better way would be to supply the password
        on the command line.
        >
        So that it shows up in `ps' output to anyone on the system? :)
        Any solution has pros and cons... having the password in the source
        code is not so good anyway...

        --
        Gabriel Genellina

        Comment

        • Nikita the Spider

          #5
          Re: postgres backup script and popen2

          In article <1170951829.472 924.65040@q2g20 00cwa.googlegro ups.com>,
          "Gabriel Genellina" <gagsl-py@yahoo.com.ar wrote:
          On 8 feb, 10:27, Maël Benjamin Mettler <m...@mediamong er.chwrote:
          >
          flupke schrieb:
          i made a backup script to backup my postgres database.
          Problem is that it prompts for a password. It thought i
          could solve this by using popen2.
          Use pexpect:http://pexpect.sourceforge.net/
          >
          pexpect could work. But a better way would be to supply the password
          on the command line. I don't know how postgres does that things, but I
          hope there is some way to automate the backup process...
          See the Postgres documentation for the .pgpass file.

          --
          Philip

          Whole-site HTML validation, link checking and more

          Comment

          • flupke

            #6
            Re: postgres backup script and popen2

            flupke schreef:
            <snip>

            Thanks for all the info.
            I'm sure i will get it right this time :)

            Benedict

            Comment

            Working...