Created
February 16, 2017 01:49
-
-
Save gwmoura/e8108e53f3618b333bb277f7fc4fcfe9 to your computer and use it in GitHub Desktop.
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 | |
#Variaveis | |
server="mysql.dominio.com.br" #Servidor mysql | |
login="nome_do_usuario_do_mysql" #login da base | |
pw="senha" #senha | |
nome_temp="all" #nome do arquivo temporário mysql | |
bk="$HOME/backup_mysql/" #Diretório para salvar arquivos de backup | |
nw=$(date "+%Y%m%d") #Buscar pela data | |
nb=3 #número de cópias do banco de dados | |
hs="backup" #nome do arquivo compactado | |
function backup() | |
{ | |
echo "Realizando backup do servidor mysql" | |
mysqldump -u$login -p$pw -h$server --add-drop-table --quote-names --all-databases --add-drop-database > "$HOME/$hs.sql" | |
echo "Compactando arquivo de backup $hs.sql.gz ..." | |
gzip -f "$HOME/"$hs.sql | |
if [ ! -d $bk ]; then | |
mkdir $bk | |
fi | |
cp -f "$HOME/"$hs.sql.gz "$bk/$nw.sql.gz" | |
a=0 | |
b=$(ls -t $bk) | |
c=$nb | |
for arq in $b; do | |
a=$(($a+1)) | |
if [ "$a" -gt $c ]; then | |
rm -f "$bk/$arq" | |
fi | |
done | |
} | |
backup |
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
#!/usr/bin/bash | |
#Variaveis | |
server="postgres01.dominio.com.br" #Servidor postgres | |
login="login_da_base" #login da base | |
pw="*******" #senha | |
nome_temp="all" #nome do arquivo temporário postgres | |
bk="$HOME/backup_postgres/" #Diretório para salvar arquivos de backup | |
nw=$(date "+%Y%m%d") #Buscar pela data | |
nb=3 #número de cópias do banco de dados | |
function backup() | |
{ | |
echo "Realizando backup do servidor postgres" | |
export PGPASSWORD=$pw | |
pg_dump -v -F c -h $server $login -U $login -i > "$HOME/$hs.dmp" | |
echo "Compactando arquivo de backup $fn.dmp.gz ..." | |
gzip -f "$HOME/"$fn.dmp | |
if [ -d $bk ]; then | |
continue | |
else | |
mkdir $bk | |
fi | |
cp -f "$HOME/"$hs.dmp.gz "$bk/$nw.dmp.gz" | |
a=0 | |
b=$(ls -t $bk) | |
c=$nb | |
for arq in $b; do | |
a=$(($a+1)) | |
if [ "$a" -gt $c ]; then | |
rm -f "$bk/$arq" | |
fi | |
done | |
} | |
backup postgres |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment