Last active
August 17, 2017 12:37
-
-
Save guiliredu/ac355a550d773382a455d2cf8c52a768 to your computer and use it in GitHub Desktop.
bash script for databse backups
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/bash | |
DATE=`date +"%Y_%m_%d_%H"` | |
# lista de bancos para fazer backup | |
array=( "database_1" "database_2" ) | |
# varre o array dos bancos | |
for i in "${array[@]}" | |
do | |
FILE=/var/www/backups/${DATE}_$i.sql | |
mysqldump --opt --user=USER --password=PASS $i > $FILE | |
tar -czvf $FILE.gz $FILE | |
rm $FILE | |
done | |
# remove arquivos com mais de 30 dias | |
find /var/www/backups/* -mtime +30 -type f -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment