]SK[
One of Freddy's beloved
- Joined
- Dec 22, 2003
- Messages
- 302
I use this script to backup my mysql databases, the filename changes per day so I know which backup is from which day. The only thing is these after 30 days I have 60 backups in one folder. I cant think of a way to auto delete files that are 5+days old. Any ideas here?
Code:
#!/bin/sh
# List all of the MySQL databases that you want to backup in here,
# each seperated by a space
databases="mysql vbulletin"
# Directory where you want the backup files to be placed
backupdir=/root/backups/mysql
# MySQL dump command, use the full path name here
mysqldumpcmd=mysqldump
# MySQL Username and password
userpassword=" --user=root --password=xxxxxxxx"
# MySQL dump options
dumpoptions=" --quick --add-drop-table --add-locks --extended-insert --lock-tables"
# Unix Commands
gzip=/bin/gzip
uuencode=/usr/bin/uuencode
mail=/bin/mail
# Send Backup? Would you like the backup emailed to you?
# Set to "y" if you do
sendbackup="n"
subject="Your MySQL Backup"
mailto="root@localhost"
# Create our backup directory if not already there
mkdir -p ${backupdir}
if [ ! -d ${backupdir} ]
then
echo "Not a directory: ${backupdir}"
exit 1
fi
# Get currentdate
today=`date +%d-%m-%Y`
# Dump all of our databases
echo "Dumping MySQL Databases"
for database in $databases
do
$mysqldumpcmd $userpassword $dumpoptions $database > ${backupdir}/${database}-$today.sql
done