Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- env | grep limite
- env | grep max
- echo "Escolhar uma opção"
- echo "1 - Backup de dados"
- echo "2 - Restaurar dados"
- read escolha
- if [ $escolha = "1" ]
- then
- echo "Selecionado Backup de dados"
- sleep 1s
- echo "Qual seu sistema?"
- echo "1 - RHEL/CentOS/Fedora Core"
- echo "2 - Debian and Ubuntu Linux"
- read linux
- if [ $linux = "1" ]
- then
- echo "Selecionado RHEL/CentOS/Fedora Core"
- sleep 1s
- set limite = 500
- set max = 65534
- fi
- if [ $linux = "2" ]
- then
- echo "Selecionado Debian and Ubuntu Linux"
- sleep 1s
- set limite = 1000
- set max = 29999
- fi
- echo "Onde salvar?"
- echo "ex /mnt/usb0/backup"
- read lugar
- echo "Salvar em $lugar"
- sleep 1s
- mkdir $lugar
- mkdir $lugar/mover/
- echo "Diretorio $lugar criado"
- sleep 1s
- export UGIDLIMIT=$limite
- echo "Exportando usuarios"
- awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=$max)' /etc/passwd > $lugar/mover/passwd.mig
- sleep 0.5s
- echo "Usuarios exportados"
- echo "Exportando grupos"
- awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=$max)' /etc/group > $lugar/mover/group.mig
- sleep 0.5s
- echo "Grupos exportados"
- echo "Exportando permissões"
- awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=$max) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > $lugar/mover/shadow.mig
- sleep 0.5s
- echo "Permissões exportadas"
- echo "Exportando usuarios do samba"
- pdbedit -e tdbsam:$lugar/mover/samba_backup.bak
- sleep 0.5s
- echo "Usuarios samba exportados"
- echo "Exportando compartilhamentos samba"
- cp /etc/samba/shares.conf $lugar/mover/shares.bak
- sleep 0.5s
- echo "Compartilhamento samba exportado"
- echo "Exportando gshadow"
- cp /etc/gshadow $lugar/mover/gshadow.mig
- sleep 0.5s
- echo "gshadow exportado"
- echo "Compatando dados dos usuarios"
- tar -zcvpf $lugar/mover/home.tar.gz /home
- sleep 0.5s
- echo "Dados compactados"
- echo "Compactando emails"
- tar -zcvpf $lugar/mover/mail.tar.gz /var/spool/mail
- sleep 0.5s
- echo "Emails compactados"
- echo "Pronto agora copie a pasta $lugar para um pendrive ou hd"
- echo "execute o script no novo servidor e escolha restaurar dados[2]"
- fi
- if [ $escolha = "2" ]
- then
- echo "Onde está os arquivos?"
- echo "ex mnt/usb0/backup"
- read diretorio
- cd $diretorio/mover
- echo "Restaurando usuarios"
- cat passwd.mig >> /etc/passwd
- echo "Restaurando grupos"
- cat group.mig >> /etc/group
- echo "Restaurando permisões"
- cat shadow.mig >> /etc/shadow
- echo "Restaurando usuarios samba"
- pdbedit -i tdbsam:samba_backup.bak
- echo "Restaurando gshadow"
- /bin/cp gshadow.mig /etc/gshadow
- echo "Restaurando compartilhamentos samba"
- /bin/cp shares.bak /etc/samba/shares.conf
- cd /
- echo "Restaurando arquivos pessoais"
- tar -zxvf /$diretorio/mover/home.tar.gz
- cd /
- echo "Restaurando emails"
- tar -zxvf /$diretorio/mover/mail.tar.gz
- echo "Concluido reinicie para terminar"
- echo "Reiniciar[Y/n]"
- read reiniciar
- if [ $reiniciar = "y" ]
- then
- reboot
- fi
- if [ $reiniciar = "Y" ]
- then
- reboot
- fi
- if [ $reiniciar = "n" ]
- then
- exit
- fi
- if [ $reiniciar = "N" ]
- then
- exit
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement