Backup PostgreSQL

0

Witam,
kombinuje nad zrobieniem automatu do tworzenia kopi zapasowych bazy danych w PostgreSQL.

W necie wyczytałem że można z poziomu konsoli wywołać jakieś polecenie i zrobi się kopia automatycznie:

pg_dump -c -O -U postgres test -h localhost -p 5432 --disable-dollar-quoting -i > plik.sql
to polecenie zwraca mi błąd dostępu (Permission denided)
jak zostawie samo:
pg_dump -U postgres to polecenie działa (ale nie tworzy pliku z kopią bazy)...

w pgAdminie jak sprawdzam to właściccielem bazy jest postgres... czyli powinno działać..

wiecie może dlaczego??

Northwest

0

a nie wymaga czasem podania hasla dla uzytkownika?
jak tak to mozesz wykorzystac expect

0

nooo właśnie powinien zapytać o hasło - a nie pyta tylko od razu błędem sypie :///
expect - tzn??

0
  1. sprawdz plik pg_hba.conf (powinien byc tam gdzie ci postgres siedzi /var/db.. roznie), pole METHOD powinno byc na password, ewentualnie mozesz dodac do pg_dump parametr -W

  2. expect to fajne narządko ktore umozliwia automatyzowanie zadan wymagajacych interakcji z uzytkownikiem, np: skrypt sam moze podac haslo do su ssh lub wlasnie pg_dumpa :P

ja automatyczny backup realizowalem tak:

plik dump.sh

#!/usr/bin/expect

set filename [lindex $argv 0]
set db_name [lindex $argv 1]
set db_host [lindex $argv 2]
set db_user [lindex $argv 3]
set db_password [lindex $argv 4]

spawn ./dump2.sh $filename $db_name $db_host $db_user
expect "Password:"
exp_send $db_password\n
wait

plik dump2.sh

#!/bin/bash

filename=$1
db_name=$2
db_host=$3
db_user=$4

touch backup/dump.lock
pg_dump -U $db_user -W $db_name -h $db_host | gzip > backup/$filename
rm -f backup/dump.lock

uruchomienie:

./dump.sh plik.gz baza host user haslo

cos w te manke :P

0

dzięki :)
tylko kurcze ja mam windowsowego i tam nie ma ssh i w tym pliku wartości method...

Takie polecenie:
pg_dump -U postgres -W - działa prawidłowo, jak podam hasło skrypt startuje
ale już takie coś: pg_dump -U postgres >baza.sql powoduję odmowę dostępu... :/

Mój plik pg_hba.conf wygląda tak:

  1. PostgreSQL Client Authentication Configuration File
  2. ===================================================

  1. Refer to the "Client Authentication" section in the
  2. PostgreSQL documentation for a complete description
  3. of this file. A short synopsis follows.

  1. This file controls: which hosts are allowed to connect, how clients
  2. are authenticated, which PostgreSQL user names they can use, which
  3. databases they can access. Records take one of these forms:

  1. local DATABASE USER METHOD [OPTION]
  2. host DATABASE USER CIDR-ADDRESS METHOD [OPTION]
  3. hostssl DATABASE USER CIDR-ADDRESS METHOD [OPTION]
  4. hostnossl DATABASE USER CIDR-ADDRESS METHOD [OPTION]

  1. (The uppercase items must be replaced by actual values.)

  1. The first field is the connection type: "local" is a Unix-domain socket,
  2. "host" is either a plain or SSL-encrypted TCP/IP socket, "hostssl" is an
  3. SSL-encrypted TCP/IP socket, and "hostnossl" is a plain TCP/IP socket.

  1. DATABASE can be "all", "sameuser", "samerole", a database name, or
  2. a comma-separated list thereof.

  1. USER can be "all", a user name, a group name prefixed with "+", or
  2. a comma-separated list thereof. In both the DATABASE and USER fields
  3. you can also write a file name prefixed with "@" to include names from
  4. a separate file.

  1. CIDR-ADDRESS specifies the set of hosts the record matches.
  2. It is made up of an IP address and a CIDR mask that is an integer
  3. (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that specifies
  4. the number of significant bits in the mask. Alternatively, you can write
  5. an IP address and netmask in separate columns to specify the set of hosts.

  1. METHOD can be "trust", "reject", "md5", "crypt", "password", "gss", "sspi",
  2. "krb5", "ident", "pam" or "ldap". Note that "password" sends passwords
  3. in clear text; "md5" is preferred since it sends encrypted passwords.

  1. OPTION is the ident map or the name of the PAM service, depending on METHOD.

  1. Database and user names containing spaces, commas, quotes and other special
  2. characters must be quoted. Quoting one of the keywords "all", "sameuser" or
  3. "samerole" makes the name lose its special character, and just match a
  4. database or username with that name.

  1. This file is read on server startup and when the postmaster receives

  2. a SIGHUP signal. If you edit the file on a running system, you have

  3. to SIGHUP the postmaster for the changes to take effect. You can use

  4. "pg_ctl reload" to do that.

  5. Put your actual configuration here


  1. If you want to allow non-local connections, you need to add more
  2. "host" records. In that case you will also need to make PostgreSQL listen
  3. on a non-local interface via the listen_addresses configuration parameter,
  4. or via the -i or -h command line switches.

TYPE DATABASE USER CIDR-ADDRESS METHOD

IPv4 local connections:

host all all 127.0.0.1/32 md5

IPv6 local connections:

host all all ::1/128 md5

0
Northwest napisał(a)

dzięki :)
tylko kurcze ja mam windowsowego i tam nie ma ssh i w tym pliku wartości method...
lacze sie w bulu :D

no czyli wszystko wporzo, pole method masz na md5 czyli kodowane haselko
a co pg_dumpa to wymaga hasla
wiec samo pg_dump -U xxx nie zadziala
musisz dac
pg_dump -U user -W > plik.sql

0

pg_dump -U user -W > plik.sql i
pg_dump -U user -W xxx > plik.sql

obie kombinacje nie działają :/

0

a pojawia sie prompt o haslo?

0

nie pojawia :/ od razu krzyczy że brak dostępu :/

1 użytkowników online, w tym zalogowanych: 0, gości: 1