Skip to content

Instantly share code, notes, and snippets.

@gysel
Last active October 11, 2015 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gysel/3899477 to your computer and use it in GitHub Desktop.
Save gysel/3899477 to your computer and use it in GitHub Desktop.
simple backup script
dbname="mydb"
user="user"
pass="pass"
scriptpath="/home/sqlbackup"
logfile="$scriptpath/backup.log"
timestamp=`/bin/date +%Y%m%d-%H%M`
# number of days to keep the backups
keepfordays=14
mysqldump -u $user -h localhost -p$pass $dbname | gzip -9 > $scriptpath/backups/$dbname-$timestamp.sql.gz
echo "$timestamp created new backup $dbname-$timestamp.sql.gz" >> $logfile
for file in "$( /usr/bin/find $scriptpath/backups -type f -mtime +$keepfordays )"
do
/bin/rm -f $file
echo "$timestamp deleted $file" >> $logfile
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment