Professional Web Applications Themes

pg_dump shell script with ~/.pgpass - PostgreSQL / PGSQL

I need to create a shell script for cron.daily to run that will do pg_dump for my database. I am using Redhat 9 and Postgresql v7.3.4. Currently when I run the dump manually the command I use is #pg_dump -u -C -D -f /tmp/owl.sql owl What should the command look like using ~/.pgpass ? My other question... Is cron.daily is being run by root? If so would I need to put the .pgpass file in root's home directory? I only have two postgresql users right now, myself and postgres. On the redhat server I have only two users, myself and ...

  1. #1

    Default pg_dump shell script with ~/.pgpass

    I need to create a shell script for cron.daily to run that will do pg_dump
    for my database. I am using Redhat 9 and Postgresql v7.3.4. Currently when
    I run the dump manually the command I use is

    #pg_dump -u -C -D -f /tmp/owl.sql owl

    What should the command look like using ~/.pgpass ?

    My other question... Is cron.daily is being run by root? If so would I need
    to put the .pgpass file in root's home directory?

    I only have two postgresql users right now, myself and postgres. On the
    redhat server I have only two users, myself and root, there is no user
    postgres.

    TIA.
    *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    ***
    Margaret Gillon, IS Dept., Chromalloy Los Angeles, ext. 297


    ---------------------------(end of broadcast)---------------------------
    TIP 8: explain yze is your friend

    MargaretGillon@chromalloy.com Guest

  2. #2

    Default Re: pg_dump shell script with ~/.pgpass

    I posted the message below on 1/15/05 and haven't received a reply yet.
    Should I be asking this question on a different list?
    Thank you.
    *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    ***
    Margaret Gillon, IS Dept., Chromalloy Los Angeles, ext. 297

    ----- Forwarded by Margaret Gillon/CLA/Chromalloy on 01/27/2005 08:38 AM
    -----

    Margaret
    Gillon/CLA/Chroma
    lloy To
    [email]pgsql-generalpostgresql.org[/email]
    01/15/2005 12:14 cc
    PM
    Subject
    pg_dump shell script with ~/.pgpass









    I need to create a shell script for cron.daily to run that will do pg_dump
    for my database. I am using Redhat 9 and Postgresql v7.3.4. Currently when
    I run the dump manually the command I use is

    #pg_dump -u -C -D -f /tmp/owl.sql owl

    What should the command look like using ~/.pgpass ?

    My other question... Is cron.daily is being run by root? If so would I need
    to put the .pgpass file in root's home directory?

    I only have two postgresql users right now, myself and postgres. On the
    redhat server I have only two users, myself and root, there is no user
    postgres.

    TIA.
    *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    ***
    Margaret Gillon, IS Dept., Chromalloy Los Angeles, ext. 297


    ---------------------------(end of broadcast)---------------------------
    TIP 3: if posting/reading through Usenet, please send an appropriate
    subscribe-nomail command to [email]majordomopostgresql.org[/email] so that your
    message can get through to the mailing list cleanly

    MargaretGillon@chromalloy.com Guest

  3. #3

    Default Re: pg_dump shell script with ~/.pgpass


    On Thursday 27 January 2005 11:47 am, [email]MargaretGillonchromalloy.com[/email] saith:
    >
    > My other question... Is cron.daily is being run by root? If so would I need
    > to put the .pgpass file in root's home directory?
    >
    --

    I don't know about .pgpass, so I can't help you with that. Root does run
    cron.daily. You can setup your own personal crontab entries by issuing the
    following command:
    crontab -e

    Do this with your personal account, not root. You will get a vi session when
    you execute this command and then you can setup you backup to occur as you
    desire.

    Here is what mine looks like:
    # min hour dom mon doy command
    # --- ---- ---- ---- ----- ---------------
    30 7,12,22 * * * /esc/source.bkp
    0 22 * * * cd /esc/pgrnd/prog;
    ../dbDump.sh rnd

    Word wrap has ed up the alignment, but you get the idea.

    ---------------------------(end of broadcast)---------------------------
    TIP 6: Have you searched our list archives?

    [url]http://archives.postgresql.org[/url]

    Terry Lee Tucker Guest

  4. #4

    Default Re: pg_dump shell script with ~/.pgpass

    On Thu, Jan 27, 2005 at 08:47:40AM -0800, [email]MargaretGillonchromalloy.com[/email] wrote:
    > I need to create a shell script for cron.daily to run that will do pg_dump
    > for my database. I am using Redhat 9 and Postgresql v7.3.4. Currently when
    > I run the dump manually the command I use is
    >
    > #pg_dump -u -C -D -f /tmp/owl.sql owl
    >
    > What should the command look like using ~/.pgpass ?
    The same. The file is automatically used if found and has the right
    permissions.
    > My other question... Is cron.daily is being run by root? If so would I need
    > to put the .pgpass file in root's home directory?
    Don't use root to do the backup, use postgres. crontab -e -u postgres

    --
    Alvaro Herrera (<alvherre[]dcc.uchile.cl>)
    "El día que dejes de cambiar dejarás de vivir"

    ---------------------------(end of broadcast)---------------------------
    TIP 8: explain yze is your friend

    Alvaro Herrera Guest

  5. #5

    Default Re: pg_dump shell script with ~/.pgpass

    [email]MargaretGillonchromalloy.com[/email] wrote:
    > I posted the message below on 1/15/05 and haven't received a reply yet.
    > Should I be asking this question on a different list?
    This is probably the right list - your message may have been missed
    though, there can be a lot of traffic.
    >
    > I need to create a shell script for cron.daily to run that will do pg_dump
    > for my database. I am using Redhat 9 and Postgresql v7.3.4. Currently when
    > I run the dump manually the command I use is
    >
    > #pg_dump -u -C -D -f /tmp/owl.sql owl
    >
    > What should the command look like using ~/.pgpass ?
    Well, from cron, I'd add an explicit username "-U username" and then in
    your .pgpass add the host/port/db/user/password as described in the
    manuals (client interfaces/libc/files).
    > My other question... Is cron.daily is being run by root? If so would I need
    > to put the .pgpass file in root's home directory?
    Yes and yes. Also, make sure you chmod the file as described in the manual.
    The alternative would be to set up a crontab for another user, and place
    the .pgpass in their home-dir.
    > I only have two postgresql users right now, myself and postgres. On the
    > redhat server I have only two users, myself and root, there is no user
    > postgres.
    Are you sure? There are almost certainly dozens of users in /etc/passwd
    and if you installed by RPM then there *will* be a user postgres. That's
    not to say you can just login as them though - they might have their
    shell disabled.

    --
    Richard Huxton
    Archonet Ltd

    ---------------------------(end of broadcast)---------------------------
    TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [email]majordomopostgresql.org[/email])

    Richard Huxton Guest

  6. #6

    Default Re: pg_dump shell script with ~/.pgpass

    On Thu, Jan 27, 2005 at 08:47:40 -0800,
    [email]MargaretGillonchromalloy.com[/email] wrote:
    >
    > What should the command look like using ~/.pgpass ?
    You might also consider using using ident as the authentication method if
    it is supported by your os.

    ---------------------------(end of broadcast)---------------------------
    TIP 1: subscribe and unsubscribe commands go to [email]majordomopostgresql.org[/email]

    Bruno Wolff III Guest

  7. #7

    Default Re: pg_dump shell script with ~/.pgpass

    On Thu, 27 Jan 2005, Richard Huxton wrote:
    > [email]MargaretGillonchromalloy.com[/email] wrote:
    [snip]
    >> I need to create a shell script for cron.daily to run that will do pg_dump
    >> for my database. I am using Redhat 9 and Postgresql v7.3.4. Currently when
    >> I run the dump manually the command I use is
    >>
    >> #pg_dump -u -C -D -f /tmp/owl.sql owl
    >>
    >> What should the command look like using ~/.pgpass ?
    >
    > Well, from cron, I'd add an explicit username "-U username" and then in your
    > .pgpass add the host/port/db/user/password as described in the manuals
    > (client interfaces/libc/files).
    Personally I _hate_ having passwords in files, and avoid it whenever possible.
    [1] It's another instance that I have to change when the password expires;
    and [B] it's a possible avenue for a security failure (or, at least requires
    real thought and attention to avoid turning into a security problem).

    What I do instead is have the cron listing run a simple script which uses su :

    su --command="INSERT YOUR PG COMMAND HERE" $PGNAME

    where PGNAME has previously been set to, for example, 'postgres'.
    This script can only be run by root (or the su will fail); and if run
    by root, and the PGNAME is postgres, no additional password will be
    needed for DB admin.

    [how to accomplish this in WinXX I have no idea]

    HTH,

    -frank

    ---------------------------(end of broadcast)---------------------------
    TIP 5: Have you checked our extensive FAQ?

    [url]http://www.postgresql.org/docs/faq[/url]

    Frank Miles Guest

Similar Threads

  1. shell script help!!
    By Louis in forum Linux / Unix Administration
    Replies: 9
    Last Post: August 20th, 03:44 PM
  2. shell script and chown
    By Tony in forum Linux / Unix Administration
    Replies: 14
    Last Post: November 26th, 05:31 AM
  3. Replies: 1
    Last Post: November 7th, 07:40 PM
  4. shell script with different results
    By cbe32 in forum Linux / Unix Administration
    Replies: 8
    Last Post: September 13th, 05:22 AM
  5. Execute shell script from a perl script
    By kderaedt in forum Perl / CGI
    Replies: 3
    Last Post: June 26th, 08:26 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139