mySQL Backup Bash Script
It isn’t pretty but I wrote this little script which saves 10 full mySQL backups (compressed) to a specified directory.
export DIR="BACKUP DIRECTORY HERE" export UNAME="MYSQL USERNAME HERE" export PASS="MYSQL PASSWORD HERE" ### End Config ### printf "Starting at " date "+%m-%d-%Y %H:%M:%S" printf "Rotating Backup files..." rm -rf $DIR/10 for ((i=9;i>0;i-=1)); do n=$(($i+1)) i2=$i case $i2 in [0-9]) i2=0$i esac case $n in [0-9]) n=0$n esac mv $DIR/$i2 $DIR/$n done mkdir $DIR/01 printf "Done!\n" printf "Creating new backup..." mysqldump --user=$UNAME --password=$PASS --all-databases | bzip2 > $DIR/01/mysql-`date +%m-%d-%Y`.bz2 printf "Done!\n" printf "*** COMPLETE ***\n" printf "Ending at " date "+%m-%d-%Y %H:%M:%S" exit 0
2008
16
May
- Posted by Aaron Rosenfeld at 02:28 pm
- Permalink for this entry
- Filed under: Databases, Programming, Servers
- RSS comments feed of this entry
- TrackBack URI
No comments
Leave a comment