您现在的位置是:首页 > 文章详情

阿里云postgreSQL数据库逻辑备份

日期:2019-07-09点击:584

一、创建阿里云存储网关
参考链接:https://help.aliyun.com/document_detail/108244.html
image

注意购买OSS bucket的区域与数据库实例所在的区域不同。

二、在与存储网关同一区域的ECS机器上面,挂载存储网关:
mount.nfs x.x.x.x:/shares /oss
x.x.x.x:/shares是网关的挂载点,/oss为本地目录
参考链接:https://help.aliyun.com/document_detail/108284.html
最好将nfs挂载点也写入/etc/fstab文件,重启自动挂载。

三、在ECS机器上安装postgreSQL备份工具
1、https://www.postgresql.org/ftp/source/ 下载相应的数据库版本(与云rds版本相近)

2、解压、安装编译
安装目录为:/usr/local/pgsql/
gunzip postgresql-10.1.tar.gz
tar xf postgresql-10.1.tar
./configure --prefix=/usr/local/pgsql/
make
make install

在pg_dump用户目录下,新建.pgpass文件,权限设为600,或者更小的权限
格式形如: hostname:port:database:username:password

四、编写postgreSQL备份脚本

#!/bin/bash hostname=xxx.pg.rds.aliyuncs.com username=xxx port=xxx database=xxx dt=`date +%Y%m%d` /usr/local/pgsql/bin/pg_dump -h $hostname -U $username -p $port -d $database -o -f /oss/db_$dt.bak if [ -z "`find /oss -name "*.bak" -mtime 0 -print0`" ] then echo "warning!postgreSQL_backup is failure,please check it!" | mail -s postgreSQL-backup xxx@xxx.com fi

将脚本添加进任务计划中,即可。

五、还原方法
登录ECS主机,执行命令:
/usr/local/pgsql/bin/pgsql -h xxx.pg.rds.aliyuncs.com -U xxx -d xxx < db_xxx.bak

原文链接:https://yq.aliyun.com/articles/708466
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章