LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script to create new directory with date (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-create-new-directory-with-date-876398/)

moyorakkhi 04-21-2011 03:01 PM

Script to create new directory with date
 
Hi,

I'm trying to write a script which will take mysqldump from a server and put it in a directory with today's date. Here's the script i've written so far:


Code:

#!/bin/sh
BACKUP=/data/backup/sql2/new_backup/daily
cd $BACKUP
mkdir `date '+%m%d%y'`
NOW=$(date +"%d-%m-%Y")

MUSER="root"
MPASS="mypass"
MHOST="sql2"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"

DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
 FILE=$BACKUP/mysql-$db.$NOW-$(date +"%T").sql.gz
 $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS --lock-all-tables $db | $GZIP -9 > $FILE
done

I want to put the mysql dump in the today's directory. How can i declare this?

Thanks.

jcalzare 04-21-2011 04:00 PM

WHy don't you just use $NOW for the directory name and then output to $FILE as you've been doing?


FILE=$BACKUP/$NOW/mysql-$db.$NOW.sql.gz

spankbot 04-21-2011 06:26 PM

Quote:

Originally Posted by moyorakkhi (Post 4331934)
Hi,

I'm trying to write a script which will take mysqldump from a server and put it in a directory with today's date. Here's the script i've written so far:

Thanks.


Check out http://sourceforge.net/projects/automysqlbackup/ it's a great way to automate MySQL dumps and rotate them...

moyorakkhi 04-22-2011 03:14 AM

Quote:

Originally Posted by jcalzare (Post 4331981)
WHy don't you just use $NOW for the directory name and then output to $FILE as you've been doing?


FILE=$BACKUP/$NOW/mysql-$db.$NOW.sql.gz

Thanks a lot. It worked!

---------- Post added 04-22-11 at 03:14 AM ----------

Quote:

Originally Posted by spankbot (Post 4332081)
Check out http://sourceforge.net/projects/automysqlbackup/ it's a great way to automate MySQL dumps and rotate them...

Thanks for the info


All times are GMT -5. The time now is 07:11 PM.