#!/bin/bash

## Variables
NOW=$(date +"%d-%m-%Y %T")
readonly NOW

# IP o nombre del servidor
readonly SERVER=maverick

## Destino del backup
readonly BACKUP_MOUNT=/sustancia/backup
readonly BACKUP_TARGET=${BACKUP_MOUNT}/macbook_air
readonly TARGET_FILES=${BACKUP_TARGET}/files
readonly TARGET_HOME=${BACKUP_TARGET}/home

## Backup de la carpeta home
readonly BACKUP_HOME=/Users/sergio

## Empieza el proceso de backup
printf "\n\nCOMIENZA LA COPIA DE SEGURIDAD (%s)\n" "${NOW}"

## Backup de ficheros
FILES=".gitconfig .git-credentials"
for FILE in $FILES; do
    printf "\n\n>> COPIANDO FICHEROS\n"
    if [ -f "${BACKUP_HOME}"/"${FILE}" ]; then
        rsync -avhP --delete --rsync-path="mkdir -p "${TARGET_FILES}/" && rsync" "${BACKUP_HOME}"/"${FILE}" "${SERVER}":"${TARGET_FILES}/"
    fi
done

## Backup de las carpetas del directorio home
FOLDERS=".ssh Documents Downloads Pictures Movies"
for FOLDER in $FOLDERS; do
    if [ -d "${BACKUP_HOME}"/"${FOLDER}" ]; then
        printf "\n\n>> COPIANDO %s\n" "${FOLDER}"
        rsync -avhP --delete --rsync-path="mkdir -p "${TARGET_HOME}/" && rsync" "${BACKUP_HOME}"/"${FOLDER}" "${SERVER}":"${TARGET_HOME}"
    fi
done