Archive for August, 2009


MySQL: Backup Database and Upload to Amazon S3 via PHP

Saturday, August 29th, 2009

Update (Dec 30/10) The following is how to load the dump into a db:

Code:
mysql -u #username# -p #database# < #dump_file#

I wrote a post a few years ago about a quick way to backup a MySQL database using email. Since then I’ve updated that script to upload the file to Amazon S3 instead of emailing it. I use an Amazon S3 PHP Class you can find here to make it happen. Your also going to need cURL enabled on your server. On Ubuntu/Debian that’s as easy as:

Code:
sudo apt-get install php5-curl 

Here is the script:

Code:
require_once 'S3.php';

if (!defined('awsAccessKey')) define('awsAccessKey', 'xxxxxxxxxxxxxxxxxxx');
if (!defined('awsSecretKey')) define('awsSecretKey', 'xxxxxxxxxxxxxxxxxxx');
//
// Check for CURL
if (!extension_loaded('curl') && !@dl(PHP_SHLIB_SUFFIX == 'so' ? 'curl.so' : 'php_curl.dll')) {
	exit("\nERROR: CURL extension not loaded\n\n");
}

$tmpDir = "/tmp/";
$user = "dbuser";
$password = "dbpassword";
$dbName = "dbname";
$prefix = "db_";

$sqlFile = $tmpDir.$prefix.date('Ymd_hisA').".sql";
$attachment = $tmpDir.$prefix.date('Ymd_hisA').".tgz";

$creatBackup = "mysqldump -u ".$user." --password=".$password." ".$dbName." > ".$sqlFile;
$createZip = "tar cvzf $attachment $sqlFile";
exec($creatBackup);
exec($createZip);

if (!file_exists($attachment) || !is_file($attachment)) {
	die("ERROR: No file");
}

$s3 = new S3(awsAccessKey, awsSecretKey);
$result = false;
if ($s3->putObjectFile($attachment, 'bucket-name', baseName($attachment), S3::ACL_PRIVATE)) {
	$result = true;
}

unlink($sqlFile);
unlink($attachment);

Taking Felix for a Checkup

Wednesday, August 26th, 2009

photo.jpg

Sicilian Rice Balls (Arancini) Italian Delight

Tuesday, August 25th, 2009

The 31st video is up on Thursday for Dinner:

Rice balls are fabulous as a side dish or an entrée. This dish can be modified in various ways; for a healthier version opt for ground turkey or chicken rather than beef, or if you are a vegetarian omit the meat altogether. We hope you enjoy our first Italian recipe!

For the written recipe click here. Subscribe by Email & iTunes.

Vegetarian Indian Potato Curry Video Recipe

Tuesday, August 25th, 2009

The 30th video is up on Thursday for Dinner:

This is a very simple reciepe to make a delicious potato curry or sabji. This sabji can be slightly modified to be made with or without a gravy. With a gravy, this dish goes great with rice, roti or even some toast. Without a gravy, this dish makes a great replacement for roasted or mashed potatoes usually had with dinner. Today we will be making this potato sabji with a tomato based gravy. Enjoy!

For the written recipe click here. Subscribe by Email & iTunes.

Apache: Stripping/Remove the www from URLS

Wednesday, August 19th, 2009

For reasons I won’t go into, I wanted to force Apache to strip the www from the URLs. So if someone typed in http://www.abc.com, Apache would automatically send them to http://abc.com. First thing to do is make sure ModRewrite is enabled, once that’s done simply put the following in your VirtualHost configuration or in the associated .htaccess file:

Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]