Advertisement
Guest User

Untitled

a guest
May 31st, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.10 KB | None | 0 0
  1. #!/bin/bash
  2. HOST=10.xxx.xx.xx
  3. USER=root
  4. WHOAMI=$(hostname)
  5. DIR="/home/web/ /home/correo/ /etc/ /home/web_people/"
  6. RDIR="/respaldos/"
  7. PORT=22
  8. DBHOST=db
  9. DBUSER=xxx
  10. DBPASS=xxxxxx
  11. DBDIR=/home/web/backups_db
  12.  
  13. ###guardamos un listado de rpms
  14. rpm -qa > /etc/packages.list
  15.  
  16.  
  17. ###listamos las bases de dato, y por cada base generamos un .sql
  18. for i in $(mysql -h$DBHOST -u$DBUSER -p$DBPASS -e "show databases"); do
  19.         mysqldump --skip-comments -h$DBHOST -u$DBUSER -p$DBPASS $i > $DBDIR/$i.sql;
  20. done
  21.  
  22. ###por cada carpeta, la creamos, luego la copiamos borrando lo antiguo, sin reemplazar la .git
  23. for i in $DIR; do
  24. echo "backup de: $i"
  25.         ssh -p$PORT $USER@$HOST "mkdir -p $RDIR$WHOAMI$i"
  26. echo "Ejecutando Rsync"
  27.         rsync --rsh="ssh -p$PORT" -azv --delete-after --exclude=.git $i $USER@$HOST:$RDIR$WHOAMI$i
  28. echo "Fin Rsync"
  29.  
  30. ###ejecutamos git para tener el control de versiones sobre lo respaldado
  31. echo "ejecutando Git"
  32.         ssh -p$PORT $USER@$HOST "cd $RDIR$WHOAMI$i ; git add .; git commit -a -m"respaldo";git tag $(date +%y-%m-%d-%s)"
  33.  
  34. ###tamos listos
  35. echo "Fin Backup de: $i"
  36. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement