Biography:

Location: Dayton, OH
College: Cedarville University, Cedarville, OH
Degree: B.A. Management Information Systems (2002)
Certifications: Microsoft Certified Professional (MCP) 2002

Interests:

Music, Playing Guitar, Working on Cars, Home Improvement, Photography, Computers, Website Programming, Driving in the snow, NHL Hockey, Sand Volleyball, Settlers of Catan board game

Favorites:

Foods: Lasagna, Carrot Casserole, Chicken Parmesan
Sports: Hockey, Football, Volleyball, Soccer
Desserts: Peanut Butter Pie, Peanut Butter Passion ice cream

Employment Information:

Current Resume: Download PDF Resume


Contact Me:
Use this area to send me a note or message:
Name:
Email:
Comments:
Security Code:

Fun links you should probably check out:


Fun games you might want to play:


Current Code Samples:


Future Code Samples:

  • LINQ-to-XML Dynamic Where Clauses Using Ternary Operators
  • C# List delegate alphanumeric sort
  • Using HTML form input arrays with ColdFusion 7
  • Capture selected text or cursor position in a TEXTAREA with JavaScript
  • Show/Hide all SELECT input items on a page with JavaScript
  • Show/Hide element with opacity level fading using JavaScript
  • CAPTCHA form-protection of images using PHP and GD 2.0 library
  • Resizing images using PHP and the GD 2.0 library
  • Rotating images using PHP and the GD 2.0 library
  • Cropping images using JavaScript, PHP, and the GD 2.0 library
  • Add image watermarks using PHP and the GD 2.0 library
CODE TUTORIAL: MySQL FTP Backup Script
Here is a script I've modified that will allow you to set up a CRON job on your Linux/Apache webserver and create automated MySQL DB backups that can be transferred for offsite backup to an FTP server of your choosing. I use this on one of my e-commerce websites to create full MySQL DB backups every 6hrs of the important db tables. Yes, my hosting provider has backups and RAID1 redundancy, but an extra level of security and off-site backup for my e-commerce business is an added plus.

Here's the code you'll need to set this up on your webserver:
PERL CODE: "mysql_ftp_backup.pl"
#!/usr/bin/perl
use Net::FTP; #INCLUDE FTP library
use MIME::Lite; #INCLUDE MIME email library


# ***************
# DESCRIPTION: **
# *******************************************************************************
# This is a simple script to place in your CPanel CRON job scheduler that will **
# FTP new backups of your MySQL databases to any FTP server you wish. By doing **
# this, you can have automated backups of your MySQL databases sent to an FTP  **
# server on a routine basis. Then, you will have peace of mind knowing that if **
# your servers were to go offline or become corrupt, you'd have recent backups **
# *******************************************************************************


# ********************
# REVISION HISTORY: **
# ********************
# Original MySQL backup script:  October 2003 - David Sierkowski (scripts@phonism.net)
# Added FTP Functionality:  November 26, 2003 - Justin Tubbs (justin@justintubbs.com)
# Cleaned up code and proofed the text:  December 5, 2006 - Justin Tubbs (justin@justintubbs.com)


# ****************
# INSTALLATION: **
# ****************
# 1. Download and save this script to your local computer.
# 2. Open the file in a text editor like Notepad (Word Wrap turned off!)
# 3. Edit the variables with the <> symbols around them.
#
#    SEE PROGRAMMER'S NOTE SECTION BELOW!!!!
#
#    (Make sure you leave OFF your username from the database names. 
#    For a complete list of db names, check out your "Backup" section in CPanel)
#
# 4. Save the document and then rename it to "mysql_ftp_backup.pl"
# 5. Upload the file to your webserver's home directory 
#
#    (On my webserver, I put this file in the parent folder above my "public_html/" folder)
#
# 6. Verify that the file has been renamed to "mysql_ftp_backup.pl"
# 7. Verify that the CHMOD setting for the file is executable (mode 755)
#
#    (You can CHMOD the permissions on the field to 755 with any FTP client program)


# *****************************
# PROGRAMMER'S NOTE SECTION: **
# *****************************************************************************
# In this section, any variables with <> around them need to be filled.      **
# Remove the "<>" marks and the text inside and replace with your parameters **
# *****************************************************************************

# FTP server IP Address/Domain Name
$ftp_host = "<FTP_HOST_IP>; # EX: ftp.ebay.com
# FTP server username
$ftp_user = "<FTP_USERNAME>"; # EX: ebayuser
# FTP server password
$ftp_pass = "<FTP_PASSWORD>"; # EX: eBaypAss#8


# Enter the list of databases you want to have backed up to your FTP server.
#
# USE THIS FORMAT - CASE SENSITIVE AND SPACE SEPARATED
# @db_names = qw(db235622801 db235623160);
#
@db_names = qw(db235622801 db235623160 db241887495);


# Enter the plaintext name for databases (This allows you to save the .sql
# file to a different name than your actual MySQL DB name -- Useful when 
# your webhost provider doesn't allow you to name your DBs)
#
# USE THIS FORMAT - CASE SENSITIVE AND SPACE SEPARATED
# @db_friendlynames = qw(address_book calendar mailing_list);
#
@db_friendlynames = qw(address_book calendar mailing_list);


# Enter all MySQL DB usernames (separated by spaces)
@db_users = qw(mySqlUser1 mySqlUser2 mySqlUser3);


# Enter all MySQL DB passwords (separated by spaces)
@db_passes = qw(uUUA9nja y2.x2FJk 5W8q6f68);


# Enter the MySQL DB hosts (separated by spaces)
@db_hosts = qw(db2.yourhost.com db3.yourhost.com db4.yourhost.com);


# Enter the MySQL DB ports (separated by spaces -- 3306 is default)
@db_ports = qw(3306 3306 3306);



# Local Server Temporary Directory
# - This is the directory path on your webserver from the root 
#   to where you want to store your MySQL DB dumps
#$tmp_dir = "/homepages/htdocs";
$tmp_dir = "/homepages/htdocs";

# MySQLdump options to make a cPanel restore compatible dump
#
# NOTE: if you want to have a backup compatible with cPanel's restore
# mechanism, leave the $dump_opts alone. Only change this if you know what
# you are doing.
$dump_opts = "-c --add-drop-table";

# Name the file you want to contain backup log information
$msg_file = $tmp_dir . "/msg.txt";

# Set a variable with today's date in it
$date = `date +'%m-%d-%Y'`;

# Create a log file of the databases that are exported
open(MSG,">$msg_file");
print MSG "Here are the MySQL Dumps, generated by SQL_Backup: \n";
print MSG "\nThe backup FTP directory being used is: $bkpdir\n\n";


# **********************
# 6-HOUR BACKUP SETUP **
# ***************************************************************************
# This area checks the current time (on the webserver) to determine        **
# what folder on the remote FTP server to put these backup files in.       **
# I set up the CRON job to run every 6hrs at 0000, 0600, 1200, 1800        **
# so I can have (4) separate copies of my MySQL databases at all times.    **
# Doing things this way requires that there must be (4) folders with       **
# names like the following: "0", "6", "12", "18".                          **
# ***************************************************************************

# Set a variable with current time of the day in it
@current_time = localtime;

# Determine whether the current 24Hour is one of our (4) options
if ($current_time[2] < 6)
{
$bkpdir = "0";
}
elsif ($current_time[2] < 12)
{
$bkpdir = "6";
}
elsif ($current_time[2] < 18)
{
$bkpdir = "12";
}
elsif ($current_time[2] < 24)
{
$bkpdir = "18";
}
else
{
$bkpdir = "/";
}

# Add a new line to the log file
print MSG "\nThe following databases are enclosed: \n\n";

$count = 0;
# Loop through the array of db names and send each backup script to FTP server
foreach $db (@db_names)
{
system("mysqldump $dump_opts --host=$db_hosts[$count] --port=$db_ports[$count] --user=$db_users[$count] --password=$db_passes[$count] $db > $tmp_dir/$db.sql");
# Add a new line to the log file
print MSG "\t $db\n";
push(@atts,"$tmp_dir/$db.sql");

# Connect to FTP server, copy MySQL backup file
$ftp = Net::FTP->new($ftp_host, Debug => 0) or die "Cannot connect to $ftp_host: $@ ";
$ftp->login($ftp_user, $ftp_pass) or die "Cannot login to FTP server using these credentials: $ftp_user $ftp_pass\n ", $ftp->message;
$ftp->cwd("$bkpdir") or die "Cannot change working directory to $bkpdir ", $ftp->message;
$ftp->put("$tmp_dir/$db.sql", "$db_names[$count]_$db_friendlynames[$count].sql") or die "PUT of the MySQL db failed ", $ftp->message;
$ftp->quit;

# Increment our counter
$count++;
}
print MSG "\n";

# Close the log file message and quit
close(MSG);


# *************************
# LICENSE AND GUARANTEE: **
# *************************
# (From the BSD license. In short, I'm not accountable for anything this script does to you.)
# *********************************************************************************
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"    **
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE      **
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE **
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE    **
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL     **
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR     **
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER     **
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,  **
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  **
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.           **
# *********************************************************************************