Technology TidBits

Answers to various technical questions on php programming, mysql, linux, and many more categories.
25% off Hosting at HostGator.com:
Use Code techbits25



What's an easy backup script for my mysql databases?

Last updated: 02/08/2012

Here's a short c-shell script you can run from cron.  This creates a backup based on the "day of the month", so you always have about 30 days worth of database backups.  You could also make this "day of week" if you only want 7 days of backups:

#!/bin/csh
cd [directory where this script resides]
set d=`/bin/date '+%d'`
mysqldump -u [database user] --password=[database password] -h [database host] [database name] > dump_$d.sql

Obviously, you need to modify the items in [ ] to correspond to your specific server and database information.

The cron entry could look like this:

0 3 * * * [directory where script resides]/dump.sh > /dev/null 2>&1

(run every day at 3 am)

 

blog comments powered by Disqus
Have your own Tech-bit to contribute? Submit it here

Other questions in this category:
How can I make a change to all files in a directory?



Powered by KnowledgebasePublisher 1.1
Host Gator
Content provided by Roberts WebForge, Inc.