Created
September 4, 2013 02:37
-
-
Save gabrielkfr/6432185 to your computer and use it in GitHub Desktop.
Script bash que permite realizar copias de seguridad de la información albergada en la herramienta Redmine, empaquetar las copias de seguridad, generar copias históricas y transferencia vía ftp a otros equipos de respaldo.
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 | |
# Realiza una copia de seguridad completa de la herramienta Redmine. | |
DIA=`date +"%Y%m%d"` | |
HORA=`date +"%H%M"` | |
BACKUP_PATH=/backups | |
# -- REDMINE | |
REDMINE_HOME=/opt/redmine | |
REDMINE_DB_TYPE=pg #[pg|mysql] | |
REDMINE_DB_NAME=redmine | |
REDMINE_DB_USER=redmine | |
REDMINE_DB_PASS=redmine | |
REDMINE_DB_BACKUP=$REDMINE_HOME/backups/redmine_db.sql | |
REDMINE_BACKUP_NAME="redmine_"$DIA"_"$HORA".tar.gz" | |
REDMINE_BACKUP_HISTO="histo_redmine_"$DIA"_"$HORA".tar.gz" | |
REDMINE_BACKUP_LIVE_TIME=30 | |
REDMINE_BACKUP_HISTO_LIVE_TIME=365 | |
# -- SVN | |
SVN_REPOS_PATH=$REDMINE_HOME/svn | |
SVN_BACKUP_PATH=$REDMINE_HOME/backups/svndumps | |
# -- PATRON LIMPIEZA | |
PATRON_BKP_DIARIO=redmine_*.tar.gz | |
PATRON_BKP_HISTO=histo_redmine_*.tar.gz | |
# -- FTP | |
FTP_SERVER=ip_servidor_backup_ftp | |
FTP_USER=usuario_ftp | |
FTP_PASS=password_ftp | |
FTP_REMOTE_CD=remote_backups | |
FTP_LOCAL_CD=$BACKUP_PATH | |
# Backup de Proyectos SVN | |
echo | |
echo "-->BACKUP DE REPOSITORIOS SVN" | |
echo "====================================================================" | |
cd $SVN_REPOS_PATH | |
for SVN_REPO_NAME in * | |
do | |
echo "---------- Iniciando exportacion del repositorio '$SVN_REPO_NAME' ----------" | |
/usr/bin/svnadmin dump $SVN_REPOS_PATH/$SVN_REPO_NAME > $SVN_BACKUP_PATH/$SVN_REPO_NAME.dump | |
echo "------------- Fin exportacion del repositorio '$SVN_REPO_NAME' -------------" | |
echo | |
done | |
# Segun el motor de base de datos especificado se procede a exportar la base de datos de Redmine. | |
echo | |
echo "-->BACKUP DE LA BASE DE DATOS DE REDMINE" | |
echo "====================================================================" | |
if [ $REDMINE_DB_TYPE == "mysql" ]; then | |
echo "Exportando la base de datos de Redmine a partir de MySQL. Aguarde un momento..." | |
mysqldump -v -u $REDMINE_DB_USER -p$REDMINE_DB_PASS --database $REDMINE_DB_NAME > $REDMINE_DB_BACKUP | |
echo "Fin del proceso de exportacion." | |
echo | |
elif [ $REDMINE_DB_TYPE == "pg" ]; then | |
echo "Exportando la base de datos de Redmine a partir de PostgreSQL. Aguarde un momento..." | |
export PGUSER=$REDMINE_DB_USER | |
export PGPASSWORD=$REDMINE_DB_PASS | |
pg_dump -b -F p --column-inserts $REDMINE_DB_NAME > $REDMINE_DB_BACKUP | |
unset PGUSER | |
unset PGPASSWORD | |
echo "Fin del proceso de exportacion." | |
fi | |
# Se generan los archivos con todas las copias de seguridad para ser enviadas a una unidad de cinta. | |
echo | |
echo "-->CREANDO FULL BACKUP DE REDMINE" | |
echo "====================================================================" | |
tar -czf $BACKUP_PATH/$REDMINE_BACKUP_NAME $REDMINE_HOME | |
# Almacenando una copia de seguridad alternativa si la fecha corresponde a fin de mes. | |
TOMORROW=`date --date=tomorrow +%d` | |
if [ $TOMORROW -eq "1" ]; then | |
echo | |
echo "-->CREANDO BACKUP HISTORICO POR SER FIN DE MES" | |
echo "====================================================================" | |
cp $BACKUP_PATH/$REDMINE_BACKUP_NAME $BACKUP_PATH/$REDMINE_BACKUP_HISTO | |
fi | |
# Para no llenar el disco duro con backups, se eliminan todos los backups diarios pasados la cantidad | |
# de dias especificados en la variable REDMINE_BACKUP_LIVE_TIME, lo backups historicos se eliminan luego | |
# de la cantidad de dias expecificados en la variable REDMINE_BACKUP_HISTO_LIVE_TIME. | |
echo | |
echo "-->LIMPIEZA DE BACKUPS ANTIGUOS" | |
echo "====================================================================" | |
find $BACKUP_PATH/$PATRON_BKP_DIARIO -mtime +$REDMINE_BACKUP_LIVE_TIME -exec rm {} \; | |
find $BACKUP_PATH/$PATRON_BKP_HISTO -mtime +$REDMINE_BACKUP_HISTO_LIVE_TIME -exec rm {} \; | |
# Se copia el full backup a un servidor de respaldo. | |
echo | |
echo "-->COPIANDO EL FULL BACKUP DE REDMINE A UN SERVIDOR DE RESPALDO" | |
echo "====================================================================" | |
/usr/bin/ftp -n <<EOD | |
open $FTP_SERVER | |
quote USER $FTP_USER | |
quote PASS $FTP_PASS | |
bin | |
cd $FTP_REMOTE_CD | |
lcd $FTP_LOCAL_CD | |
put $REDMINE_BACKUP_NAME | |
bye | |
EOD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment