Created
April 23, 2018 16:42
-
-
Save KevinWang15/b7f176dd30019fb8384e97d3a6ab8fa7 to your computer and use it in GitHub Desktop.
backup mysql
This file contains 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 | |
# crontab: | |
# 30 */8 * * * /root/backup/mysql.sh | |
databases=(db1 db2 db3) | |
basepath='/root/backup/mysql/' | |
if [ ! -d "$basepath" ]; then | |
mkdir -p "$basepath" | |
fi | |
for db in ${databases[*]} | |
do | |
/usr/bin/nice -n 19 /usr/bin/mysqldump -u root --password=[password here] --databases $db > $basepath$db-$(date +%Y-%m-%d_%H).sql | |
/usr/bin/nice -n 19 gzip -f $basepath$db-$(date +%Y-%m-%d_%H).sql | |
find $basepath -mtime +30 -name "*.sql.gz" -exec rm -rf {} \; | |
done | |
rm -rf $basepath/*.sql | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment