Welcome Anonymousregister
Categories
· Home
· Authors and Articles
· Downloads
· Feedback
· Forums
· Journal
· Private Messages
· Recommend Us
· Stories Archive
· Submit News
· Surveys
· Top 10
· Topics
· Web Links
· Your Account

Survey
What Topics Of FreeBSD Servers & Workstations Do You Want More Information About?

FreeBSD Installation
Webserver Setup
E-Mail Server Setup
IRC Server Setup
Mailing Lists
Autoresponders
Scripting
Software Coding
Server Security
Installing Ports
Domain Servers
Website Design



Results
Polls

Votes: 23
Comments: 0

 Title : Scripting: Using Date Function To Automate Saving Of Mysql Database Files
Scripting



We Show You How To Use The Date Function To Save Reoccurring Files Which Would Otherwise Get Overwritten

One of the first things I ran into when beginning my FreeBSD adventure was finding a way to automatically backup my web servers mysql database files. I found that even webmin (an application management interface) wasn't able to handle saving of my mysql database files without overwriting the previously saved (day before) files.

As you may already know it's especially important with websites that you have progressive saves of the database in case you find a problem that requires you use a version of your site that happened 7 days previously.  If you are new to scripting then all of this may not be something you will understand right off the bat, but eventually you'll understand the power of using the date function within your scripts when saving files.  Essentially what this date function does is add a time stamp to the end of your file name so that it is completely unique because it's based off the current time of when the file is being saved. 

What I did in my case was create a small script called websiteback.sh that I then placed in a bin directory within my home such as /root/bin/websiteback.sh.  For this example I simplified the code within this file just for the sake of simplicity for those new to scripting.  Basically what this file contains a line for each database within my system as follows:

<-----Begin File Code----->
#!/bin/sh
/usr/local/bin/mysqldump -u root --password=aBcD1234 dataBaseName > /location/you/want/to/save/backup/dataBaseName.`date +%m%d%Y%H%M%S`

/usr/local/bin/mysqldump -u root --password=aBcD1234 dataBaseName2 > /location/you/want/to/save/backup/dataBaseName2.`date +%m%d%Y%H%M%S`
<-----End File Code------>

The first line executes this file as a shell script via sh which needs to be set as an executable otherwise it will not run.  See man chmod if you aren't sure how to set it executable. 

Once you have created this file, the only thing left to do is create a cron job to execute the above file on a daily basis.  For example you would create a cron job like the following:

0 8 * * * /root/bin/websiteback.sh

See man crontab for more information about how to set a cron job within FreeBSD.  That's all there is to it! 

Using the date function is very versatile and you can use it directly within your scripts and can use them within paths as I've shown above.  I hope you find it as useful as I do and if you have any questions or comments, please feel free to post them here. 



Posted on Friday, November 30, 2007 @ 22:16:20 EST by Michael

Using Date Function To Automate Saving Of Mysql Database Files | Login/Create an Account | 0 comments
The comments are owned by the poster. We aren't responsible for their content.

No Comments Allowed for Anonymous, please register

 
Related Links
· More about Scripting
· News by Michael


Most read story about Scripting:
How To Batch Remove ^M From PC Files


Article Rating
Average Score: 5
Votes: 1


Please take a second and vote for this article:

Excellent
Very Good
Good
Regular
Bad


Options

 Printer Friendly Printer Friendly



Associated Topics

Scripting

1: Credit Repair Combat
128 times
2: My Internet Business
123 times
4.965 Seconds