LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-21-2011, 07:50 PM   #1
tintin184
LQ Newbie
 
Registered: Jun 2011
Posts: 2

Rep: Reputation: Disabled
Mysql dump adding current date


Hi I am trying to make a bash file to dump my mysql database for backup but also append the current date so I know which version it is, this is my current code

NOWDATE=`date +%d%m%y`
mysqldump -uroot -ppwd --otp db1 > /backup/db1$NOWDATE.sql

I'm not sure if the mysqldump command can support adding the date if there is a step Iv missed I would love to hear your input.

(database name and password removed for obvious reasons )

Thanks
 
Old 08-21-2011, 08:45 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,324
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
I wrote up a script that worked for me several years ago. You are welcome to look at it, in case it helps.

http://www.pineviewfarm.net/weblog/?p=3113

The display loses some of the plain text formatting.

I don't use it anymore because I no longer self-host.
 
Old 08-21-2011, 08:57 PM   #3
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Actually your script sets the data in bash. If you want to append the data at the end of the file, then do as below:

Code:
NOWDATE=`date +%d%m%y`
mysqldump -uroot -ppwd --otp db1 > /backup/db1$NOWDATE.sql
date >> /backup/db1$NOWDATE.sql
OK

Note the double >. This is important.

Last edited by AnanthaP; 08-21-2011 at 08:59 PM.
 
Old 08-21-2011, 09:34 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,324
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
I did it in BASH because I wanted to do more stuff than just a mysql dump and I wanted to run it as a daily cron job. It seemed to me that a script was the best option.

And thank you for the command reference. I've made a note of it.

MySQL is so huge that any help I can get with using it is always appreciated.
 
Old 08-22-2011, 07:18 AM   #5
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
I'm confused by AnanthaP's response and frankbell's second response. The script segment in the original post should be fine. It appends the date to the filename so that you can tell when the backup was done (which version of the backup). The output of mysqldump is being sent to the file. The shell won't care how you made up the filename.

Using `date >> dumpfile.sql` doesn't make sense to me. The dump file consists of the sql statements necessary to rebuild the database. You import it back into mysql to restore. A raw date is not an sql statement as far as I know. It would generate an error message on recovery.
 
Old 08-22-2011, 09:58 AM   #6
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
Well the OP said "but also append the current date" but it seemed quite obvious from the example that it was as a suffix to the filename, not desired in the file as you rightly point out.
 
Old 08-22-2011, 08:18 PM   #7
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,324
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
Unless I misunderstood, AnanthaP was showing how to append the date to the dump file as part of the mysqldump command without writing a script, though the two lines posted could make a convenient little script.
 
Old 08-23-2011, 07:51 AM   #8
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
Quote:
Originally Posted by frankbell View Post
AnanthaP was showing how to append the date to the dump file....
Understood. But why either of you would think that is a good idea is the puzzle. The dump file consists of sql commands necessary to rebuild the database. Extraneous cruft at the end of the file will generate error messages. So just put the date in the filename where it is more useful and easier to see anyway.
 
  


Reply



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
How can I do a dump of the current contents in RAM to a file? abefroman Linux - Server 1 12-11-2009 12:58 AM
How do I INSERT IGNORE the current date into a table in MYSQL? resetreset Programming 9 12-15-2008 01:39 AM
slackware-current out-to-date? sparc86 Slackware 77 03-27-2007 08:42 AM
current date - yesterday's date newbie_adm Linux - Newbie 4 09-04-2006 03:56 PM
Shell scripting: Doing MySQL Dump base on date Swakoo Linux - General 2 09-21-2005 10:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:32 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