Created
May 17, 2017 19:22
-
-
Save hectorgool/432f6238a711a3bfe2e3440ee99c7154 to your computer and use it in GitHub Desktop.
bash
This file contains hidden or 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 hacer respaldos de bases de datos | |
| #Por el Rafa el 24-05-07 | |
| server=localhost | |
| user=postgres | |
| backup=/repo/mako/db | |
| backup2=/repo/mako/www | |
| backup3=/repo/mako/apache | |
| origen1=/var/www | |
| origen2=/etc/apache2 | |
| fecha=`date +%d-%m-%Y` | |
| log=respaldos_servidor.log | |
| host=`/sbin/ifconfig eth0 |awk -F'[: ]+' '/inet addr:/ {print $4}'|awk -F "." '{print $1"."$2"."$3"."4}'` | |
| if [ -n ${host} ]; then | |
| host=`/sbin/ifconfig em1 |awk -F'[: ]+' '/Direc. inet:/ {print $4}'|awk -F "." '{print $1"."$2"."$3"."4}'` | |
| fi | |
| #### Mandamos un mensaje de inicio y limpiamos la pantalla #### | |
| clear | |
| echo -e "\t\t*** Programa para respaldar Bases de Datos ***" | |
| if [ ! -d $backup ]; then | |
| mkdir -p $backup | |
| fi | |
| cd $backup | |
| #### Preguntamos al servidor por todas las bases de datos #### | |
| respaldoDB="$(psql -h $host -U $user -l | awk ' (NR > 2) && (/[a-zA-Z0-9]+[ ]+[|]/) && ( $0 !~ /template[0-9]/) && ( $1 !~ /postgres/ ) { print $1 }')" | |
| echo $respaldoDB | |
| echo $host | |
| #for DB in $respaldoDB ; do | |
| # echo "* Backuping PostgreSQL database from $DB@$host " | |
| # pg_dump -h $host -U $user $DB > $backup/$DB-$host-$fecha.sql 2>> $log | |
| # bzip2 $backup/$DB-$host-$fecha.sql 2>&1|tee $log | |
| #done | |
| find $backup/* -type f -ctime +8 -print -exec rm {} \; 2>&1|tee $log | |
| eval `ssh-agent -s` | |
| ssh-add /root/.ssh/id-repo-mako-backup_mako.rsa | |
| #origen1=/var/www | |
| #backup2=/repo/mako/www | |
| /usr/bin/rsync -rlptgovaz -e 'ssh -o StrictHostKeyChecking=no -p 22' root@$host:$origen1/* $backup2/ | |
| #origen2=/etc/apache2 | |
| #backup3=/repo/mako/apache | |
| /usr/bin/rsync -rlptgovaz -e 'ssh -o StrictHostKeyChecking=no -p 22' root@$host:$origen2/* $backup3/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment