Automatic MySQL databases backup with unix
Hello folks, of course you manage a lot of nasty DBMS and of course you have no time to care about backup-ing them all manually.
Here i come with a simple yet nice .sh script for all the seasons to use under any (i suppose) unix system.
- Create a new .sh file, name it as you like, maybe backup.sh
- Open and edit it, add this lines and fill all the required fields
############# § Backup My MySQL § ############## ### BMMSQL 1.0 Lite - By Jonathan Argentiero ### ### This script tastes better with Cronjobs! ### ################################################ #################### ### System Setup ### #################### BACKUP=(insert folder here) # REQUIRED # NOW=$(date +"%d-%m-%Y") INCFILE="/root/tar-inc-backup.dat" DAY=$(date +"%a") ################### ### MySQL Setup ### ################### MUSER="(insert username here)" # REQUIRED # MPASS="(insert password here)" # REQUIRED # MHOST="(insert mysql ip here)" # REQUIRED # MYSQL="$(which mysql)" # OPTIONAL # MYSQLDUMP="$(which mysqldump)" # OPTIONAL # GZIP="$(which gzip)" # OPTIONAL # ########################## ### Start MySQL Backup ### ########################## DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')" for db in $DBS do FILE=$BACKUP/mysql-$db.$NOW-$(date +"%T").gz $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE done ################# ### Good Job! ### #################
- create a cronjob
crontab -e
similar to
1 1 * * * sh /home/backup.sh
..and it’s done!
No comments yet.