Skip to content

Instantly share code, notes, and snippets.

@guiliredu
Last active August 17, 2017 12:37
Show Gist options
  • Save guiliredu/ac355a550d773382a455d2cf8c52a768 to your computer and use it in GitHub Desktop.
Save guiliredu/ac355a550d773382a455d2cf8c52a768 to your computer and use it in GitHub Desktop.
bash script for databse backups
#!/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