#! /bin/bash #Autor: Cleiton Rodrigues 2020-07-16 #UBKP="userbkp" #PBKP="UserBkP" echo "User BD: " read UBKP read -s -p "Password: " PBKP PATH_BKP="/var/backups/bkp-my-server/bds" if [ ! -d $PATH_BKP ] then mkdir $PATH_BKP fi cd $PATH_BKP #listar os bancos existentes no arquivo "all-bds.txt": mysql -u $UBKP -p$PBKP -e "show databases;" > all-bds.txt #ler linha por linha do arquivo "all-bds.txt", e roda o comando de dump: while read line do #existe duas linhas no arquivo que nao sao bancos, pulando elas: if [ $line != "Database" ] && [ $line != "information_schema" ] && [ $line != "performance_schema" ] then echo -e "==> fazendo bkp de $line -----------------" mysqldump -u $UBKP -p$PBKP $line > "$line".sql echo -e "compactando $line" tar -cvzf "$line".sql.tar.gz "$line".sql echo -e "removendo $line.sql" rm "$line".sql echo -e "feito $line!" fi done < all-bds.txt