Created
November 9, 2015 10:19
-
-
Save RELATO/5b8648c8be7126bee94d to your computer and use it in GitHub Desktop.
Backup mysql and folder sample script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # crontab ( adicionar a linha para backup as 5:15 todos os dias | |
| # 15 5 * * * root /usr/bin/backup.sh | |
| # | |
| # para rodar sem senha crie uma chave publica e privada e envie a publica para as maquinas que voce | |
| # quer fazer o backup: | |
| # ssh-keygen -t dsa -f ~/.ssh/id_dsa | |
| # cat ~/.ssh/id_dsa.pub | ssh root@maquina_remota 'cat - >> ~/.ssh/authorized_keys' | |
| # cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys | |
| DATE=`date +%Y%m%d` | |
| DOTDIR=`pwd` | |
| DDIR=/tmp/dbdump | |
| cd $DDIR | |
| if [ -d $DDIR ]; | |
| then | |
| rm $DDIR/* | |
| else | |
| [ -e $DDIR ] && rm -rf $DDIR | |
| mkdir $DDIR | |
| fi | |
| cd $DDIR | |
| DB=[dbname] | |
| SRVBKP=[server 1 ip address] | |
| SRVBKP2=[server 2 ip address] | |
| DESTFOLDER=[destination folder name] | |
| echo "Dumping $DB..." | |
| mysqldump -uroot -p[root passwd] --opt $DB > $DDIR/$DB.dmp | |
| tar cvzf /tmp/dump.tar.gz * | |
| scp /tmp/dump.tar.gz root@$SRVBKP:/backups/$DESTFOLDER/dump-$DATE.tar.gz | |
| scp /tmp/dump.tar.gz root@$SRVBKP2:/backups/$DESTFOLDER/dump-$DATE.tar.gz | |
| echo "Backup efetuado." > /root/backup.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment