Created
June 1, 2017 11:09
-
-
Save rafabarzotto/c19d0df74fe8ad170e184a81bdf6d1fe to your computer and use it in GitHub Desktop.
Script Backup Postgres
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#################### SCRIPT PARA BACKUP POSTGRES #################### | |
# Jeferson R. Costa <rc.jeferson@gmail.com> # | |
# Created Feb, 2013 # | |
# Update Feb, 2013 # | |
# Definindo parametros do MySQL | |
echo " -- Definindo parametros do PGSQL ..." | |
DB_NAME='esus' | |
DB_USER='postgres' | |
DB_PASS='esus' | |
export PGPASSWORD=esus; | |
# Definindo parametros do sistema | |
echo " -- Definindo parametros do sistema ..." | |
DATE=`date +%Y-%m-%d` | |
PGDUMP=/usr/bin/pg_dump | |
BACKUP_DIR=/home/opt/backup/esus | |
BACKUP_NAME=esus-$DATE.backup | |
BACKUP_TAR=esus-$DATE.tar | |
#Gerando arquivo sql | |
echo " -- Gerando Backup da base de dados $DB_NAME em $BACKUP_DIR/$BACKUP_NAME ..." | |
$PGDUMP -U $DB_USER $DB_NAME> $BACKUP_DIR/$BACKUP_NAME | |
# Compactando arquivo em tar | |
echo " -- Compactando arquivo em tar ..." | |
tar -cf $BACKUP_DIR/$BACKUP_TAR -C $BACKUP_DIR $BACKUP_NAME | |
# Compactando arquivo em bzip2 | |
echo " -- Compactando arquivo em bzip2 ..." | |
bzip2 $BACKUP_DIR/$BACKUP_TAR | |
# Excluindo arquivos desnecessarios | |
echo " -- Excluindo arquivos desnecessarios ..." | |
rm -rf $BACKUP_DIR/$BACKUP_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment