ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197
Rep:
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.
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.
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.
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197
Rep:
Quote:
Originally Posted by frankbell
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.