Advertisement
sergio_educacionit

incremental_diferencial.sh

Mar 11th, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. ## Instrucciones
  5. # 1. Definir variables
  6.  
  7. fecha=$(date +%s)
  8. # Servidor de backup
  9. server=192.168.0.71
  10. # Usuario remoto
  11. usuario=educacionit
  12.  
  13. # 2. Crear llave publica.
  14. #
  15. # ./incremental_diferencial.sh ssh-key
  16. #
  17. # 3. Crear par de claves gpg.
  18. #
  19. # ./incremental_diferencial.sh gpg-key
  20. #
  21.  
  22.  
  23.  
  24. # Creacion de llave ssh si contraseña
  25.  
  26. if [ "$1" == "ssh-key" ]; then
  27.  
  28. ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
  29.  
  30. ssh-copy-id -i $HOME/.ssh/id_rsa.pub ${usuario}@$server
  31.  
  32. exit 0
  33.  
  34. elif [ "$1" == "gpg-key" ]; then
  35.  
  36. gpg --batch --gen-key <<EOF
  37. %no-protection
  38. Key-Type: RSA
  39. Key-Length: 2048
  40. Subkey-Type: RSA
  41. Subkey-Length: 2048
  42. Name-Real: Your Name
  43. Name-Email: ${USER}@$HOSTNAME
  44. Expire-Date: 0
  45. %commit
  46. EOF
  47.  
  48.  
  49. gpg --export -a "${USER}@$HOSTNAME" > ${USER}.${HOSTNAME}.asc
  50.  
  51.  
  52. scp ${USER}.${HOSTNAME}.asc ${usuario}@$server:~/
  53.  
  54. ssh ${usuario}@$server gpg --import ${USER}.$HOSTNAME.asc
  55.  
  56. exit 0
  57.  
  58. fi
  59.  
  60.  
  61.  
  62.  
  63. mysqldump --all-databases > /var/backups/${fecha}_all-db.sql
  64.  
  65. gpg --detach-sign /var/backups/${fecha}_all-db.sql
  66.  
  67.  
  68.  
  69. # Crear directorio en el remoto.
  70.  
  71. ssh $usuario@$server mkdir -p ${HOSNTNAME}-backup.00
  72.  
  73. rsync -a -v -e "ssh -i ~/.ssh/id_rsa" /var/backups/ $usuario@${server}:~/${HOSTNAME}-backup.00
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement