LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-21-2011, 03:01 PM   #1
moyorakkhi
Member
 
Registered: Jan 2011
Location: Dhaka
Posts: 80

Rep: Reputation: 1
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.
 
Old 04-21-2011, 04:00 PM   #2
jcalzare
Member
 
Registered: Aug 2009
Location: Chicago
Distribution: CentOS
Posts: 114

Rep: Reputation: 34
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

Last edited by jcalzare; 04-21-2011 at 04:04 PM.
 
1 members found this post helpful.
Old 04-21-2011, 06:26 PM   #3
spankbot
Member
 
Registered: Aug 2007
Posts: 133

Rep: Reputation: 16
Quote:
Originally Posted by moyorakkhi View Post
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...
 
1 members found this post helpful.
Old 04-22-2011, 03:14 AM   #4
moyorakkhi
Member
 
Registered: Jan 2011
Location: Dhaka
Posts: 80

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by jcalzare View Post
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 View Post
Check out http://sourceforge.net/projects/automysqlbackup/ it's a great way to automate MySQL dumps and rotate them...
Thanks for the info
 
  


Reply

Tags
shell scripting



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script to create directory with date thetiger2003 Linux - Newbie 3 12-06-2010 04:40 AM
Bash Script - adding file modification date to end of filenames in directory themonkman Programming 2 09-01-2009 11:45 PM
Create a script to cd into my previous directory alpha883 Programming 4 05-08-2009 08:55 AM
How to create an executable script that starts execution at a specific date and time? jtag Linux - General 3 08-12-2008 08:36 PM
Bash script to read file and alter lines depending on create date ChristianHein Linux - General 13 08-04-2007 05:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration