Advertisement
Guest User

Exportar usuarios zentyal

a guest
Oct 15th, 2018
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.97 KB | None | 0 0
  1. #!/bin/sh
  2. env | grep limite
  3. env | grep max
  4. echo "Escolhar uma opção"
  5. echo "1 - Backup de dados"
  6. echo "2 - Restaurar dados"
  7. read escolha
  8. if [ $escolha = "1" ]
  9. then
  10. echo "Selecionado Backup de dados"
  11. sleep 1s
  12. echo "Qual seu sistema?"
  13. echo "1 - RHEL/CentOS/Fedora Core"
  14. echo "2 - Debian and Ubuntu Linux"
  15. read linux
  16. if [ $linux = "1" ]
  17. then
  18. echo "Selecionado RHEL/CentOS/Fedora Core"
  19. sleep 1s
  20. set limite = 500
  21. set max = 65534
  22. fi
  23. if [ $linux = "2" ]
  24. then
  25. echo "Selecionado Debian and Ubuntu Linux"
  26. sleep 1s
  27. set limite = 1000
  28. set max = 29999
  29. fi
  30. echo "Onde salvar?"
  31. echo "ex /mnt/usb0/backup"
  32. read lugar
  33. echo "Salvar em $lugar"
  34. sleep 1s
  35. mkdir $lugar
  36. mkdir $lugar/mover/
  37. echo "Diretorio $lugar criado"
  38. sleep 1s
  39. export UGIDLIMIT=$limite
  40. echo "Exportando usuarios"
  41. awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=$max)' /etc/passwd > $lugar/mover/passwd.mig
  42. sleep 0.5s
  43. echo "Usuarios exportados"
  44. echo "Exportando grupos"
  45. awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=$max)' /etc/group > $lugar/mover/group.mig
  46. sleep 0.5s
  47. echo "Grupos exportados"
  48. echo "Exportando permissões"
  49. awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=$max) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > $lugar/mover/shadow.mig   
  50. sleep 0.5s
  51. echo "Permissões exportadas"
  52. echo "Exportando usuarios do samba"
  53. pdbedit -e tdbsam:$lugar/mover/samba_backup.bak
  54. sleep 0.5s
  55. echo "Usuarios samba exportados"
  56. echo "Exportando compartilhamentos samba"
  57. cp /etc/samba/shares.conf $lugar/mover/shares.bak
  58. sleep 0.5s
  59. echo "Compartilhamento samba exportado"
  60. echo "Exportando gshadow"
  61. cp /etc/gshadow $lugar/mover/gshadow.mig
  62. sleep 0.5s
  63. echo "gshadow exportado"
  64. echo "Compatando dados dos usuarios"
  65. tar -zcvpf $lugar/mover/home.tar.gz /home
  66. sleep 0.5s
  67. echo "Dados compactados"
  68. echo "Compactando emails"
  69. tar -zcvpf $lugar/mover/mail.tar.gz /var/spool/mail
  70. sleep 0.5s
  71. echo "Emails compactados"
  72. echo "Pronto agora copie a pasta $lugar para um pendrive ou hd"
  73. echo "execute o script no novo servidor e escolha restaurar dados[2]"
  74. fi
  75. if [ $escolha = "2" ]
  76. then
  77. echo "Onde está os arquivos?"
  78. echo "ex mnt/usb0/backup"
  79. read diretorio
  80.  cd $diretorio/mover
  81.  echo "Restaurando usuarios"
  82.  cat passwd.mig >> /etc/passwd
  83.  echo "Restaurando grupos"
  84.  cat group.mig >> /etc/group
  85.  echo "Restaurando permisões"
  86.  cat shadow.mig >> /etc/shadow
  87.  echo "Restaurando usuarios samba"
  88.  pdbedit -i tdbsam:samba_backup.bak
  89.  echo "Restaurando gshadow"
  90.  /bin/cp gshadow.mig /etc/gshadow
  91.  echo "Restaurando compartilhamentos samba"
  92.  /bin/cp shares.bak /etc/samba/shares.conf
  93.  cd /
  94.  echo "Restaurando arquivos pessoais"
  95.  tar -zxvf /$diretorio/mover/home.tar.gz
  96.  cd /
  97.  echo "Restaurando emails"
  98.  tar -zxvf /$diretorio/mover/mail.tar.gz
  99.  echo "Concluido reinicie para terminar"
  100.  echo "Reiniciar[Y/n]"
  101.  read reiniciar
  102.  if [ $reiniciar = "y" ]
  103.  then
  104.  reboot
  105.  fi
  106.  if [ $reiniciar = "Y" ]
  107.  then
  108.  reboot
  109.  fi
  110.  if [ $reiniciar = "n" ]
  111.  then
  112.  exit
  113.  fi
  114.  if [ $reiniciar = "N" ]
  115.  then
  116.  exit
  117.  fi
  118. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement