Is this for perhaps log rotating or backups ken?
Here is the sh script I use for backups & rotating. It creates SQL dumps of databases listed in a file (db-list.txt) and then rotates them. It puts all the files in a daily backup directory where they're stored for 4 days, but then also copies the most recent one to a uploads folder for transfering to a backup server via FTP.
Code:
#!/bin/bash
# Set a value that we can use for a datestamp
DATE=`date +%Y-%m-%d` $
# Our Base backup directory
BASEBACKUP="/home/backups/daily"
for DATABASE in `cat /home/backups/db-list.txt`
do
# This is where we throw our backups.
FILEDIR="$BASEBACKUP/$DATABASE"
# Test to see if our backup directory exists.
# If not, create it.
if [ ! -d $FILEDIR ]
then
mkdir -p $FILEDIR
fi
echo -n "Exporting database: $DATABASE"
mysqldump --user=root --opt $DATABASE | gzip -c -9 > $FILEDIR/$DATABASE-$DATE.sql.gz
echo " ......[ Done Exporting to local backup, now exporting for remote backup] "
cp $FILEDIR/$DATABASE-$DATE.sql.gz /home/backups/uploads/$DATABASE.sql.gz
echo " .......[Done]"
done
# AutoPrune our backups. This will find all files
# that are "MaxFileAge" days old and delete them.
MaxFileAge=4
find $BASEBACKUP -name '*.gz' -type f -mtime +$MaxFileAge -exec rm -f {} \;
Bookmarks