db-backup.sh

This is a simple backup script for my MySQL database. Nothing fancy, but it works.

#!/bin/sh
dir=`date +%Y-%m-%d`
username='root'
password=''
outputpath='/var/backup/databases'
outputfile='alldbs.sql'
tarfile='alldbs.tgz'
email='[email protected]'
emailsubject='Daily backup for '$dir
 
mkdir $outputpath/$dir -p
rm -rf $outputpath/$dir/*
mysqldump -B --user=$username --password=$password --all-databases  > $outputpath/$dir/$outputfile
tar -czvf $outputpath/$dir/$tarfile $outputpath/$dir/$outputfile 2> /dev/null
rm -f $outputpath/$dir/$outputfile
mutt -s "$emailsubject" -a $outputpath/$dir/$tarfile $email < /dev/null
  1. No comments yet.
(will not be published)