Advertisement
sergio_educacionit

super_backup.sh

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