Advertisement
AgarHeroYT
Jan 11th, 2024
49
1
Never
This is comment for paste super_backup.sh
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. I fixed your bash code you forgot to put double Quotes
  2.  
  3. #!/bin/bash
  4.  
  5.  
  6. fecha=$(date +%H-%M-%S)
  7. server=192.168.0.209
  8.  
  9.  
  10. if [ "$1" == "ssh-key" ]; then
  11.  
  12.     ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
  13.  
  14.     ssh-copy-id -i "$HOME/.ssh/id_rsa.pub backupsrv@$server"
  15.  
  16.     exit 0
  17.  
  18. elif [ "$1" == "gpg-key" ]; then
  19.  
  20.     gpg --batch --gen-key <<EOF
  21. %no-protection
  22. Key-Type: RSA
  23. Key-Length: 2048
  24. Subkey-Type: RSA
  25. Subkey-Length: 2048
  26. Name-Real: Your Name
  27. Name-Email: educacionit@$HOSTNAME
  28. Expire-Date: 0
  29. %commit
  30. EOF
  31.  
  32.  
  33. gpg --export -a "educacionit@$HOSTNAME" > "educacionit.$HOSTNAME.asc"
  34.  
  35.  
  36. scp educacionit."$HOSTNAME".asc backupsrv@$server:~/
  37.  
  38. ssh backupsrv@$server  gpg --import educacionit."$HOSTNAME".asc
  39.  
  40. exit 0
  41.  
  42. fi
  43.  
  44.  
  45.  
  46.  
  47. mysqldump --all-databases > /var/backups/"${fecha}"_all-db.sql
  48.  
  49. gpg --detach-sign /var/backups/"${fecha}"_all-db.sql
  50.  
  51.  
  52.  
  53. # Crear directorio en el remoto.
  54.  
  55. ssh backupsrv@$server mkdir -p /home/backupsrv/"$HOSNTNAME"
  56.  
  57. rsync -a -v  -e "ssh -i ~/.ssh/id_rsa" /var/backups/  backupsrv@${server}:~/"$HOSTNAME"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement