Following shell script for storing back up of laste 10 database.
but there is small problem.
the script create *.zip file of each data base with date and time and stored in backup folder.
so if i have 4 data base so it will create 4 zip file. And for laste 10 days back up, that mean total i have 40 data base back up.
I want to store the back up of database in last 10 days with seperate folder. so that each folder contain the back up of database.
Following is the shell script.
MHOST=localhost
MUSER=backup
MPASS=SECRET
BACKUPDIR="/mnt/backup"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"
DBPREFIX="$(hostname -s).mysqldb"
echo "Run MySQL backup"
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
FILE=${BACKUPDIR}/${DBPREFIX}.${db}.`date +%Y%m%d`.gz
$MYSQLDUMP --no-tablespaces --skip-lock-tables -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done
find -name "${BACKUPDIR}/${DBPREFIX}*" -type f -mtime +10 -exec rm -f '{}' ';'
I am new to the Linux environment.
Please help me on the same
Best Regards
Arvind Porlekar
1 Answer