Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Script that backs-up mysql databases
- filedate=`date +%Y-%m-%d`
- backupdir=
- username=root
- password=""
- hostname=localhost
- port=3306
- tarfile=databases-${filedate}.tar
- databases=`mysql -u${username} -p${password} -N -e "show databases"`
- mysqldump="mysqldump --force --add_drop_table --add_drop_database -c -e -u${username} -p${password} -h${hostname} -P${port}"
- cd ${backupdir}
- tdayfile=today.sql.tar.bz2
- ###############################################################
- # Action! -->
- ###############################################################
- cd ${backupdir}
- for database in ${databases}
- do
- ${mysqldump} -B ${database} > ${database}.sql
- if [ $? -gt 0 ] ; then
- echo "Database ${database} backup failed..."
- else echo "Database ${database} backup successful."
- fi
- done
- tar --remove-files -cf ${tarfile} `ls|grep \.sql$` && \ #tar up any .sql files
- echo "Compressing ${tarfile}" && \
- nice -n19 bzip2 -z9 ${tarfile} && \ #bziping .tar with max compression
- rm ${tdayfile} && \ #remove yesterday's "today" link
- ln -s ${tarfile}.bz2 ${tdayfile} #...and create today's "today" link
- if [ $? -gt 0 ] ; then
- echo "Archive creation failed..." #done!
- else echo "Archive creation Sucessful."
- fi
Add Comment
Please, Sign In to add comment