読者です 読者をやめる 読者になる 読者になる

pd_dump + scp


こんな感じで


# touch pg_backup.sh
# chmod 744 pg_backup.sh
# vi pg_backup.sh


#!/bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH

_DATE=`date +%Y%m%d`
_DSTHOST="IPADDRESS"
_BACKUPDIR="/usr/local/pgsql/backup"
_PGDUMP="/usr/local/pgsql/bin/pg_dump"

cd $_BACKUPDIR

while read DBNAME ;do

su - postgres -c "${_PGDUMP} -d ${DBNAME} > ${_BACKUPDIR}/${DBNAME}.dump.${_DATE}"

done << EOF
`sudo -u postgres /usr/local/pgsql/bin/psql -l -t 2>/dev/null | awk '{print $1}' | grep -v ^$`
EOF

scp -p ${_BACKUPDIR}/*.dump.${_DATE} ${_DSTHOST}:${_BACKUPDIR}
exit 0


# cat pd_backup.sh