Skip to content

Instantly share code, notes, and snippets.

@aycanirican
Created November 7, 2010 17:27
Show Gist options
  • Select an option

  • Save aycanirican/666262 to your computer and use it in GitHub Desktop.

Select an option

Save aycanirican/666262 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Parameters
HOST="localhost"
USER="user"
PASS="pass"
DB="database"
DDIR="/home/username/dbbackup"
D=`date +%Y%m%d`
DUMP="mysqldump -h $HOST -u $USER -p $PASS $DB"
# functions
function job {
$DUMP | gzip > $DDIR/$DB-$D.sql.gz
find $DDIR -mtime +7 -type f -iname "*.sql.gz" -exec rm -f {} \;
}
# action
job
# test by creating some files and executing the script
# touch -t <date ex: 201010190830> <filename>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment