Skip to content

Instantly share code, notes, and snippets.

@techbyvideo
Last active May 26, 2019 08:51
Show Gist options
  • Save techbyvideo/fb10f83c1a1bb939adb8be4c8d5281df to your computer and use it in GitHub Desktop.
Save techbyvideo/fb10f83c1a1bb939adb8be4c8d5281df to your computer and use it in GitHub Desktop.
#!/bin/bash
#Backups Folder
cd /backups/mysql/
# Get list of databases
LISTEBDD=$( echo 'show databases' | mysql -uroot -p'techbyvideo' )
# Save the current date
DATE=`date +%y_%m_%d`
##List of databases
for SQL in $LISTEBDD
do
if [ $SQL != "information_schema" ] && [ $SQL != "mysql" ] && [ $SQL != "performance_schema" ] && [ $SQL != "Database" ]; then
## backup database
mysqldump -uroot -p'techbyvideo' $SQL > ${SQL}_`date +"%Y-%m-%d"`.sql
## Compress file tar.bz2
tar jcf ${SQL}_`date +"%Y-%m-%d"`.sql.tar.bz2 ${SQL}_`date +"%Y-%m-%d"`.sql
## delete backups
rm ${SQL}_`date +"%Y-%m-%d"`.sql
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment