码迷,mamicode.com
首页 > 数据库 > 详细

postgresql backup

时间:2018-05-03 15:27:35      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:exe   database   col   net   find   tab   base   exec   pre   

#!/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

标签:exe   database   col   net   find   tab   base   exec   pre   

原文地址:https://www.cnblogs.com/tben/p/8985110.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!