用于postgres的Shell脚本安装和从远程客户端恢复数据库

时间:2014-05-27 07:50:52

标签: linux postgresql ubuntu

我正在尝试从远程客户端(使用jcraft将一个系统连接到另一个系统)在ubuntu 12.04(具有相同操作系统的客户端和服务器)中安装postgres 9.3。

当我将下面的脚本运行到主系统时(使用主系统的终端,我安装postgresql 9.3),它执行正常。成功安装和创建模式并恢复数据库。

但是当我尝试从远程客户端运行相同的脚本时(使用jcraft,我首先将脚本上传到我将安装postgres的系统,然后运行脚本显示一些身份验证错误。

(致命:用户“postgres”的密码验证失败)

有人知道我做错了吗?

这是我的剧本

PASS=dici

gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
gpg -a --export E084DAB9 | sudo apt-key add -

echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > ./pgdg.list

echo $PASS | sudo -S mv ./pgdg.list /etc/apt/sources.list.d/

echo $PASS | sudo -S apt-get update

echo $PASS |sudo -S apt-get -y -q install python-software-properties software-properties-common
echo $PASS |sudo -S apt-get -y --force-yes install postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3

echo "localhost:5432:*:postgres:postgres" >> .pgpass
echo $PASS | sudo -S chmod 600 .pgpass


echo $PASS|sudo -S su - postgres<<-'EOF'
 psql template1
 alter user postgres with password 'postgres';
 CREATE SCHEMA ayata AUTHORIZATION postgres;
 \q
 logout
EOF



echo $PASS | sudo -S chmod 777 /etc/postgresql/9.3/main/pg_hba.conf 

echo $PASS| sudo -S echo "host all  all  peer  md5" >> /etc/postgresql/9.3/main/pg_hba.conf

echo $PASS | sudo -S chmod 777 /etc/postgresql/9.3/main/postgresql.conf

echo $PASS| sudo -S echo "listen_addresses = '*'" >> /etc/postgresql/9.3/main/postgresql.conf


echo $PASS | sudo -S chmod 640 /etc/postgresql/9.3/main/pg_hba.conf

echo $PASS | sudo -S chmod 644 /etc/postgresql/9.3/main/postgresql.conf

 echo $PASS| sudo -S service postgresql restart

echo "------------------ restore datatbase ----------------------------------------"
/usr/bin/pg_restore --host localhost --port 5432 --username "postgres" --dbname "postgres" --role "postgres" --no-password  --verbose "ayata.backup"
--------------------------------------------

0 个答案:

没有答案