Nov
20
2009
0

Perl: Simple MySQL Backup Script

#!/usr/bin/perl -w
#
# Quick and dirty dump and time-stamp of listed MySQL databases.
#
# by Timothy M. Kunau
# Note: There will be a point at which this will run out of diskspace for backs
#       and this script has no way of knowing. There is a companion script 
#       (find one-liner) that iterates through the ARCHIVES and erases files over 
#       a certain number of days old.
#       Assumes 'gzip' and 'mysqldump' are in the PATH.
#
#       Admittedly a bit fast and loose with variables and system returns. 
#       It might also be more useful if you could simply pass in the database name
#       as a variable.
#       These, and numerous other improvements, are left as an exercise for the reader.
 
my $workingdir = "/tmp";
my $host       = "localhost";
my $username   = "root";
my $pw         = "THE_ROOT_PASSWORD_FOR_YOUR_MYSQL_INSTANCE_GOES_HERE";
#
# Add a database you want to backup by name to the @dbs array below:
my @dbs        = qw{ hapmap_human concrete gallery2 wordpress };
 
###############  Nothing should need to change beyond this point.
 
# Create a $TIMESTAMP for log entry.
sub get_date {
   # brute force method
 
   my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
 
   if ($year < 10) { $year = "0$year"; }
   $year = $year + 1900;
   if ($mday < 10) { $mday = "0$mday"; }
   if ($hour < 10) { $hour = "0$hour"; }
   if ($min < 10) { $min = "0$min"; }
   if ($sec < 10) { $sec = "0$sec"; }
 
   # Format a $TIMESTAMP for easy sorting
   $monthord = $mon + 1;
   if ($monthord < 10) { $monthord = "0$monthord"; }
   $TIMESTAMP = "$year$monthord$mday$hour$min$sec";
}
 
####
 
# generate TIMESTAMP
&get_date;
 
foreach $db (@dbs) {
 
    # dump databse
    system("mysqldump --flush-logs --opt --host=$host --user=$username --password=$pw $db > $workingdir/$db-$TIMESTAMP.dmp");
 
    # compress dump file to save space
    system("gzip $workingdir/$db-$TIMESTAMP.dmp");
 
}
 
exit;

A simple place to begin, if you are looking for a script to backup your chosen MySQL databases. The code was written years ago and has been in production ever since. I haven’t had the chance or need to change it.

Suggestions for improvement are listed in the code. Please post your solutions in the comments.

Written by kunau in: databases,tools
Jun
24
2008
1

SpotCrime: Spotty Results

spotcrime-spotty_results.png

I liked the idea.

According to the default view, a crime committed in Wisconsin appears in Minneapolis, MN. Additionally, other local crimes committed in Minneapolis appear randomly all over the metro area, with little or no correlation to where they actually happened. There is some clever screen scraping and scripting behind SpotCrime. Though apparently not clever enough. These observations are of my hometown, if this is a representative sample you will likely see the same problems.

At best, the results are not accurate enough to be useful. At worst, they can construct a dangerously inaccurate view of a community.

(See also: SpotCrime: Minneapolis)
(See also: SpotCrime)

Apr
22
2008
0

Health Record Warning

“In very short order, a few large companies could hold larger patient databases than any clinical research center anywhere,” Dr. Mandl said in an interview.

(See also: NYTimes: Warning on the Storage of Health Records)

Jan
16
2008
0

Sun acquires MySQL AB

Sun_014.jpg

Sun is buying the ‘M’ in the LAMP* stack.

Not surprising when you consider the history Sun has with OpenOffice, JAVA, NetBeans, and other Open Source communities. Sun grew largely with the growth of the web. Though other companies have struggled, post-bubble, Sun has returned to profitability over the last four consecutive quarters. My reaction, along with much of the net, believes this is a good fit for both organizations.

Sun will pay approximately $800 million in cash in exchange for all MySQL stock and assume approximately $200 million in options. The transaction is expected to close in late Q3 or early Q4 of Sun’s fiscal 2008.

We support terabytes of MySQL databases on Sun Microsystems SPARC hardware running Solaris.

* Linux Apache MySQL Perl (LAMP)

(See also: Jonathan’s blog: helping dolphins fly)
(See also: MySQL: Sun to Acquire MySQL)
(See also: blogs.mysql.com)
(See also: New York Times: Sun Buying Swedish Software Firm for $1 Billion)
(See also: mysql.com)
(See also: sun.com)

Written by kunau in: databases
May
11
2007
0

Encyclopedia of Life

A bold new collaborative effort to catalog all know species on the planet is underway. Their abstract states:

Comprehensive, collaborative, ever-growing, and personalized, the Encyclopedia of Life is an ecosystem of websites that makes all key information about life on Earth accessible to anyone, anywhere in the world. Our goal is to create a constantly evolving encyclopedia that lives on the Internet, with contributions from scientists and amateurs alike. To transform the science of biology, and inspire a new generation of scientists, by aggregating all known data about every living species. And ultimately, to increase our collective understanding of life on Earth, and safeguard the richest possible spectrum of biodiversity.

Here is a video overview:

(See: http://www.eol.org/ Encyclopedia of Life )

Written by kunau in: databases,tools

Powered by WordPress. 14 queries in 3.120 seconds.