Last active
March 1, 2019 16:13
-
-
Save jelcaf/5045907 to your computer and use it in GitHub Desktop.
Backup de repositorios Git
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 | |
########################################### | |
# Backup de aplicaciones git del servidor # | |
########################################### | |
################# | |
# Configuración # | |
################# | |
# Servidor | |
SERVER_IP=X.X.X.X | |
SERVER_APP_DIR=fap | |
# Aplicaciones a las que hay que realizar el backup | |
APPS=( tesis estancias ) | |
# Directorio donde se ubicará la copia del repositorio Git | |
LOCAL_APP_DIR=/home/fap/backupServerLinux/aplicacionesGit | |
# Fichero de LOG del script | |
LOG_FILE=/home/fap/backupServerLinux/backupServerLinux.log | |
################# | |
function logger () { | |
echo "$(date): $@" >> $LOG_FILE | |
} | |
# Realiza el clone de la applicacion | |
# Parámetros: | |
# 1. aplicacion a clonar | |
function cloneApp () { | |
if [ -z "$1" ] | |
then | |
logger "La función cloneApp NN tiene parámetros" | |
exit | |
else | |
app=$1 | |
appDir=$LOCAL_APP_DIR/$app.git | |
if [ -d $appDir ]; then | |
logger "$app" | |
else | |
logger "Clone $app" | |
cd $LOCAL_APP_DIR | |
log_status=`git clone --mirror git@$SERVER_IP:$SERVER_APP_DIR/$app` | |
logger $log_status | |
fi | |
cd $appDir | |
log_status=`git remote update` | |
logger $log_status | |
fi | |
} | |
######################################################### | |
# Para cada unas de las aplicaciones hacemos el backup | |
for app in ${APPS[@]} | |
do | |
cloneApp $app | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment