Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ## Instrucciones
- # 1. Definir variables
- fecha=$(date +%s)
- # Servidor de backup
- server=192.168.0.71
- # Usuario remoto
- usuario=educacionit
- # 2. Crear llave publica.
- #
- # ./incremental_diferencial.sh ssh-key
- #
- # 3. Crear par de claves gpg.
- #
- # ./incremental_diferencial.sh gpg-key
- #
- # Creacion de llave ssh si contraseña
- if [ "$1" == "ssh-key" ]; then
- ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
- ssh-copy-id -i $HOME/.ssh/id_rsa.pub ${usuario}@$server
- exit 0
- elif [ "$1" == "gpg-key" ]; then
- gpg --batch --gen-key <<EOF
- %no-protection
- Key-Type: RSA
- Key-Length: 2048
- Subkey-Type: RSA
- Subkey-Length: 2048
- Name-Real: Your Name
- Name-Email: ${USER}@$HOSTNAME
- Expire-Date: 0
- %commit
- EOF
- gpg --export -a "${USER}@$HOSTNAME" > ${USER}.${HOSTNAME}.asc
- scp ${USER}.${HOSTNAME}.asc ${usuario}@$server:~/
- ssh ${usuario}@$server gpg --import ${USER}.$HOSTNAME.asc
- exit 0
- fi
- mysqldump --all-databases > /var/backups/${fecha}_all-db.sql
- gpg --detach-sign /var/backups/${fecha}_all-db.sql
- # Crear directorio en el remoto.
- ssh $usuario@$server mkdir -p ${HOSNTNAME}-backup.00
- rsync -a -v -e "ssh -i ~/.ssh/id_rsa" /var/backups/ $usuario@${server}:~/${HOSTNAME}-backup.00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement