postgresql backup
Posted TonyBen2018
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了postgresql backup相关的知识,希望对你有一定的参考价值。
#!/bin/sh # Database backup script # Backup use postgres pg_dump command: # pg_dump -U <user> -Fc <db> > <DB_DUMP_FILE> # To restore, use postgres pg_restore command: # pg_restore -d postgres <DB_DUMP_FILE> HOST_IP=`/sbin/ifconfig | sed -n ‘s/.*inet addr:\([0-9.]\+\)\s.*/\1/p‘ | head -n1` POSTGRES_HOME=/opt/postgres BACKUP_DIR=/backup/$HOST_IP BACKUP_FILENAME_PREFIX="db_backup_" CURRENT_TIME=`date +‘%Y-%m-%d_%H%M%S‘` KEEP_DAYS=30 mkdir -p $BACKUP_DIR BACKUP_FILE=$BACKUP_DIR/$BACKUP_FILENAME_PREFIX$CURRENT_TIME.dump echo "`date` starting database backup: $BACKUP_FILE" #full database backup $POSTGRES_HOME/bin/pg_dump -U postgres -Fc postgres > $BACKUP_FILE echo "`date` database backup completed: $BACKUP_FILE" #delete files older than $KEEP_DAYS find $BACKUP_DIR -mtime +$KEEP_DAYS -exec rm {} \;
以上是关于postgresql backup的主要内容,如果未能解决你的问题,请参考以下文章
在 PostgreSQL 中授予对函数 pg_start_backup 的执行不起作用
How to backup a remote PostgreSQL db and restore it locally?