Last active
October 11, 2015 18:17
-
-
Save gysel/3899477 to your computer and use it in GitHub Desktop.
simple backup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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