PostgreSQL basebackup备份

前端之家收集整理的这篇文章主要介绍了PostgreSQL basebackup备份前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/bin/sh

lst=(
127.0.0.1:5432:xm_rep:123456
127.0.0.1:5432:xm_rep:123456
)

for item in ${lst[@]}
do
        host=$(echo ${item} | awk -F':' '{print $1}')
        port=$(echo ${item} | awk -F':' '{print $2}')
        user=$(echo ${item} | awk -F':' '{print $3}')
        passwd=$(echo ${item} | awk -F':' '{print $4}')

TMP="/home/work/data/tmp/dump.sh"

t=`date '+%Y%m%d%H%M%S'`
d="data${port}_${t}"

rm -f $TMP
# create expect script
cat > $TMP << EOF
set timeout 432000
spawn /home/work/app/postgresql-9.6.1/bin/pg_basebackup -h ${host} -p ${port} -U ${user} -F p -x -R -l backup${t} -r 30M -D /home/work/data/backup/postgresql/${d}
expect "Password:"
send "${passwd}\n"
expect eof
exit
EOF

/usr/bin/expect -f $TMP

cd /home/work/data/backup/postgresql/

tar zcf ${d}.tar.gz ${d}

find ./ -mtime +15 -name "*.tar.gz" -exec rm -rf {} \;

rm -rf ${d}

rm -f $TMP
done



pg_backup.sh 
#!/bin/sh

lst=(
127.0.0.1:5016:xm_rep:password
127.0.0.1:5006:xm_rep:password
127.0.0.1:5018:xm_rep:password
127.0.0.1:5022:xm_rep:password
)

> ~/.pgpass
chmod 600 ~/.pgpass

for item in ${lst[@]}
do
    host=$(echo ${item} | awk -F':' '{print $1}')
    port=$(echo ${item} | awk -F':' '{print $2}')
    db=$(echo ${item} | awk -F':' '{print $3}')
    user=$(echo ${item} | awk -F':' '{print $4}')
    passwd=$(echo ${item} | awk -F':' '{print $5}')
    echo "${host}:${port}:*:${user}:${passwd}" >> ~/.pgpass

    t=`date '+%Y%m%d%H%M%S'`
    d="${host}_${port}_${db}_data${port}_${t}"

    /home/work/app/postgresql/bin/pg_basebackup -h ${host} -p ${port} -U ${user} -w -F t -P -x -R -l backup${t} -r 30M -D - | lz4 -B4 | openssl enc -e -aes-256-cbc -k "key"
> /home/work/data/backup/postgresql/${d}.tar.lz4

    find /home/work/data/backup/postgresql/ -mtime +15 -name "*.tar.lz4" -exec rm -rf {} \;
done

原文链接:https://www.f2er.com/postgresql/194220.html

猜你在找的Postgre SQL相关文章