配置文件备份:
1、查找程序目录 ps -ef|grep postmaster 或者进入库show data_directory;
2、进入程序目录 备份 postgresql.conf,pg_hba.conf,pg_ident.conf
配置文件恢复:
1、cp 最新备份到指定位置即可
PostgreSQL恢复步骤:
1. 定位数据丢失的时间点;
2. 根据crontab中的备份脚本找到备份数据目录,根据步骤1的时间点确认最近的需要做恢复的全量备份文件;
3. 停止应用访问对应的数据库;
4. 删除数据丢失的数据库;
eg. drop database testdb;
5. 恢复数据库到上一个全量备份点;
eg. pg_restore -d testdb -U postgres /db/PostgreSQL/backup/data/testdb.sql
6. 恢复应用
#!/bin/bash
# Shell script to backup PostgreSQL database
# Set these variables
PGUSER="postgres" # DB_USERNAME
# PGPASS="密码
" # DB_PASSWORD
# PGHOST="xxxxxxxxx"# DB_HOSTNAME
# PGPORT="端口" # DB_PORT
# Get date in dd-mm-yyyy format
NOW="$(date +"%d-%m-%Y_%s")"
# Backup Dest directory
# You must create individual folder for backup data and log as this script will remove old files in the end!!!
DEST="/db/PostgreSQL/backup/data"
LOGPATH="/db/PostgreSQL/backup/log"
LOGFILE="$LOGPATH/$NOW.log"
# Email for notifications
# EMAIL=""
# How many days old files must be to be removed
DAYS=7
# Remote server to store backup copy
# SCP_IP=IP地址
# Linux bin paths
PSQL="$(which psql)"
PGDUMP="$(which pg_dump)"
GZIP="$(which gzip)"