Tuesday, August 25, 2015

How to backup your Bluehost backups (or any other) to AWS and save on storage costs

Seems like no matter how much space you have, there is never enough for the giant backup files. On one of my VPS accounts I have this issue nearly ever week where I have to clean up. 
So without getting into too much detail this is basically what I did today:

1) I stopped all weekly backups from the WHM "Backup Configuration" page.
2) I deleted all weekly and monthly backup files from the server by SSHing in and going to the /backup/cpbackup/weekly directory ... And deleting the big tar file.
3) In the bottom of that same WHM "Backup Configuration" page I checked the "/scripts/postcpbackup" option and wrote the contents of that script. Which you'll find below:

#!/usr/bin/perl

$directory='/backup/cpbackup/daily/';
$filename='mybackup.tar';

$awsDir='/home4/myuser/phpbackupdir/';
$awsScriptPath='/home4/myuser/phpbackupdir/s3_backup.php';

chdir $directory;
`gzip -f $directory . $filename`;

chdir $awsDir;
`php5 $awsScriptPath`;



The above code basically compresses the file after it's been created. This alone will save you a huge amount of space.

Then it calls a php script that I downloaded from this site which uploads the resulting compressed file to Amazon S3. Admittedly I hacked that script a bit to comment out all the archiving since my bluehost account already does that for me. 

What I love about this is the postcpbackup script will automatically run after the backup is complete so I don't have to actually call that using a cron job.

I also added a mandrill bit to all this to send me an email when it's done. 

So what do I get with all this?
Well, I get to not only remove my monthly and weekly backups from the server saving me about 10GB, I also get to compress the daily file from about 5GB to 1.8GB which frees up another 3GB.

Not only that, I get to keep 30 days of backups on AWS (so like 60GB) and anytime I need to I can access that regardless of Bluehost being up or not.

What really surprised me was how fast the 1.8GB compressed file was transferred to AWS. I took about 2-3 minutes which is amazing speed. That must mean that Bluehost is basically hosted on AWS or they have a very big pipe for that transfer.

Either way, this 2 hour project is now going to save me $15/mo and provide me with 30 days of continuous full backups. 

You can figure out the hacks for yourself in the 33_backup.php script. If you need help, leave a comment below and I can help you figure it out.

Tuesday, June 30, 2015

The ridiculous cost of real estate transactions and a possible solution

Most people don't know this, but I have my real estate broker's license. About ten or so years ago I put in the time to get my license because I noticed that I was paying a 2-3% premium on everything I purchased or sold. I figured if I can save myself that 2-3% and perhaps my friends and family, then I would come out way ahead of the cost of maintaining the license. 

Since then I've done dozens of transactions for family and friends in addition to those that I've done for myself. It goes without saying that I contribute a good portion of my commission to their closing costs since they're friends. Lately though I've been noticing that with real estate costs as high as they are, my commission checks are disproportionately larger than the effort I have to put it. Don't get me wrong. I put in the necessary time for anyone I represent. I make sure I help them research the properties, I negotiate everything for them and help them avoid any costly mistakes associated with escrow, title, and lenders. I go above and beyond what anyone else would ever do for them because I want to make sure they're getting a good deal. But even then, even after all the hours, I still feel like the commission is disproportionately large compared to the effort. On rare occasions when the deal  becomes extremely complicated and requires several hundred hours of research, work, and negotiation, it might be somewhat feasible to get paid more than 1.5% of the total sales price, but otherwise ...

Here's an example of a typical deal in Southern California. A couple I recently work with had a purchase budget of $800,000. I spent a few hours talking to them to really understand what their needs were. I then did some research on the neighborhoods they were interested in and learned the streets where I thought they would want to live. I drove by a few properties, previewed all the good ones and worked out all the numbers for them. So far I was about 12 hours in. I then met with them on three separate occasions to look at homes. Having previewed everything and done all the numbers saves us all time so we only had to look at about 10 homes total. They went back to the same house over and over again and eventually we ended up making an offer well below asking price. After about 3 days of back and forth our offer was accepted and with about 25 total hours of work put in, my work was nearly done. Over the next 45 days I made sure that all the paperwork was getting signed by the right people and any inspections were getting done on time. We're talking maybe a total of 10 more hours for a total of 35 hours. 

The commission on this deal was 2.5% so I stood to make $20,000 for my 35 hours of work. That's $571/hour. I contributed a substantial portion of that towards my buyer's closing costs but even then I walked away with more than $10k. I know what most agents would say at this point: "What about all the hours you had to spent finding the customer and doing marketing and ...". To them I say: "That's true with every other business also".


A lot of agents/brokers earn their commission. They negotiate hard on behalf of their client and they look out for their best interests. But the majority of agents basically list a property on the MLS (about 8 hours of work including photos), then they sit back and wait for their commission check to arrive. That's total BS. It used to be they had to do a lot more work for the 2-3%. But with technology as good as it is, it's really a click-next wizard and you're done. How does that make sense that when you sell your hard earned asset through an agent, that somehow for less than 40 hours of work, he/she gets to keep 3% of your hard earned money?! It's ridiculous. Ridiculous considering that most agents won't even put a penny into advertising your place or even hold a proper open house for you.

I know I'm going to get attacked by a lot of agents for this. But it's time for reform. Everyone should have to earn what they keep. In a perfect world, you'd pay an agent a fixed fee regardless of the price of sale and a commission for every dollar over a certain threshold. For example, if your house comps for $800k, your agents would get $4k upon sale, and 10% of every dollar over $750k. That way, if your property sold for $740, you would only pay the agent $4k. But if it sold for $800, then you'd pay him $9k. Or some sliding scale like that.

Personally, I'm not in this business to make my living. I just do it to help friends and family. And I do believe in each agent's right to make a good living if they're willing to work hard for their clients. But in an environment like Irvine where the average house sells for over $1M, and the seller has to fork over $50K in commissions (2.5% to each agent), I think there is room for a disruption and the time has come. 

Thursday, June 11, 2015

How to encrypt an existing MySql database

One thing I want you to keep in mind as you're reading this, is that this is a very basic guide to quickly get some encryption on your data. It is by no means a failsafe enterprise-level chinese-hacker-proof way of encrypting your data. Furthermore, aside from just encrypting some of your data I recommend at least the following:

  • Encrypt the entire disk volume that your database resides on
  • Encrypt the entire database instance
  • Create firewalls at every levels of your infrastructure
  • Use the highest level of encryption that fits the limits of your performance window
  • Get a chastity belt and a few Assa Abloy padlocks to protect your server
Now with that said, here's a super simple way of encrypting your stuff.

Let's say you have a table called user that looks like this:


As you can see, nothing in this table is encrypted, because you can obviously read it. Don't worry this is all fake data ;)

Anyway, you probably want to encrypt that email column so if someone gets into your db they can't just steal all your email addresses. Here's the quick and easy way:


UPDATE user SET EMAIL = AES_ENCRYPT(EMAIL, 'password');

The 'password' should probably be a nice long string that you're going to guard with your life going forward. What this does is it encrypts the EMAIL field with the key 'password' and updates it in the database. So now what your result set looks like is this:


Hard to guess what those emails are now.

By now you're probably a bit impressed, but asking yourself, okay great, but how the heck do I use data that looks like this in my own application? Well, I'm glad you asked. Here's how:


SELECT FIRST,LAST,CAST(AES_DECRYPT(EMAIL,'password') AS CHAR) AS EMAIL, WHEN_CREATED FROM user



Hint: If you don't user the CAST( ... AS CHAR), you'll get a blob returned in MySQL which is probably not what you want. MySql needs to know how to interpret the encrypted data once it has decrypted it. Also, If you don't say "AS EMAIL" after the casting, you'll get the whole formula as your column name and it will be pretty nasty, so this is cleaner.

Some more very important stuff to consider:

  1. You should consider changing your data type to binary since this is no longer being stored as a varchar
  2. You should definitely consider increasing the size of the encrypted (now binary) column because it now takes up more room and you don't want crazy errors you can't debug later.
  3. Storing the key in a safe place goes without saying, but try to come up with a pretty cryptic string like 'HDIEdygygde783juinifiaaoeygyqyegyYYHGEYD' and just use that within your application to decrypt. The downside of doing this is that if you lose this key, then you are essentially screwed.
Happy encrypting

Saturday, April 18, 2015

How to upgrade your old laptop cheap and in less than an hour

Let me start by saying that my laptop is my entire business. Without it I'm basically out of work. My biggest problem is that buying a new laptop is a huge time investment. I have nearly 100 programs installed on my current laptop and I love the way it's setup. I don't even have the original install files for these programs and even if I did, it would take days or maybe weeks to configure everything and install every component just so I could get my work done right. Not to mention the 40+ VPN connections I have setup for my clients that I would need to figure out again. We're talking weeks and weeks on work. Which is exactly why, my new Lenovo T430 is still in the box two years after purchase and I never stopped using my T420 which I bought nearly 5 or 6 years ago.

When I bought my T420, it was the best money could buy. It had the latest i5 processor, 8GB of Ram and a 128GB SSD (Solid State Drive). I absolutely love my T420. It's still extremely fast; the 9-cell battery lasts about 8 hours of continuous use, and combined with the docking station, gives me exactly what I need in a professional machine. I should add that I also have a 500GB SATA drive in the bay for files, so my 128GB drive is for program installs and the OS only.

So last week, as the used capacity of my 128GB drive was coming to the 95% mark, I ordered a new, bigger SSD drive ($84) and a drive cloning device ($40)





Kingston Digital 240GB SSDNow V300 SATA 3 2.5-Inch Solid State Drive with Adapter (SV300S37A/240G)

Sabrent USB 3.0 to SATA Dual Bay External Hard Drive Docking Station for 2.5 or 3.5in HDD, SSD with Hard Drive Duplicator/Cloner Function [4TB Support] (EC-HDD2)


I simply cloned my smaller 128GB drive into the new 240GB drive using this drive copier in less than 15 minutes. But to my surprise, the new drive is 3.5 times faster than my old drive. The fact that it's also double the capacity for just about $90 is a really great bargain. Especially since this exact byte for byte clone functions exactly as my old drive with all my old programs and settings intact. While I was at it, I upgraded to 12GB of RAM and now my old T420 is screaming fast again with a new lease on life and double the drive space. The cloning device was only $40 and I can use it to make backups of my entire drive each month so I am never at risk of losing my business again. Keep in mind, having backups of my data is not really as relevant for me as having backups of my installed programs and VPN connections so a simple backup drive solution wouldn't work well for me. 

The entire project took me less than 1 hour (after the parts arrived) and cost me about $160 total, $40 of which is the copier device that I can continue to use for backups. Sure beats having to buy a new laptop for $1500+ and spending weeks getting it up to snuff. 

It's worth mentioning that I ran into some issues with partitioning the new drive which I was able to fix with AOMEI Partition Assistant:

http://download.cnet.com/AOMEI-Partition-Assistant-Standard-Edition/3000-2248_4-75118871.html

Also, when I plugged the drive into the old PC alongside the same drive (so both clones were on the same machine) I got a conflict which I resolved by following this video:

https://www.youtube.com/watch?v=-1mQIJJp-bE


Thursday, February 12, 2015

The single most important quality of a successful entrepreneur

Some of us are good at playing music, other at sports, or math, or cooking, or ... the list goes on. There's something about us that makes us very good at one or two things in life. It's quite obvious to me that regardless of how much I practice every day, I won't be able to compete against Usain Bolt in the 100 meter dash. He's just naturally better at running fast than I am, and that's a fact. But somehow when it comes to entrepreneurship, we don't think of one person being inherently better at it than another. Perhaps because we have seen successful entrepreneurs from all walks of life. Some short, some tall, some fat, some skinny, some with crazy wavy hair, some bald, some extroverts, some shy and introverted. But what do they all have in common? 

Running a business is a constantly evolving game and as an entrepreneur you have to act, and react faster than your competitors in order to survive. For every successful business there are hundreds of failures. Ask any entrepreneur how they feel about running a business and they are likely to not have a pleasant portrait of what it takes. Elon Musk has said numerous times that (and I paraphrase) entrepreneurship is like staring into the abyss and eating glass. I know exactly how it feels. My analogy for years had been that it's like climbing a mountain with a maze on it's surface. In recent years I have realized that it's more like climbing a mountain with a maze on it's surface while pushing a stone block. You get good at it, but it never gets easy. So what is it that makes one entrepreneur better than another? In the case of Usain it's his incredible physique, and his mental control over his facilities. I believe I have found the one factor that sets one entrepreneur apart from the rest. What makes Bill Gates, Elon Musk, Donald Trump, Steve Jobs, Larry Ellison, Richard Branson, Mark Zuckerberg, Jack Ma, Jeff Bezos, Ted Turner, Warren Buffett, and countless other successful multi-billionaires so different?


What single quality could be responsible for their incredible rise to the top? Ready? 

It's the ability to decide what to tackle next. 

Let me explain.

As a business owner, your mind is overflowing with thousands of great ideas of what to do for your business. There are countless decisions to be made and an enormous list of todos. What sets the super-star entrepreneur apart is knowing which of these thousands of things to tackle first. Execution of the task at hand is obviously important too but being able to prioritize the endless list of todos and picking the most strategic one is by far what sets the winners apart from the rest. Imagine the todo list on Elon's planner as he started SpaceX. What do you do first? Ask yourself that question. What would you do FIRST (not top ten, first) if you wanted to start your own commercial space craft company? See what I mean? It's probably akin to rocket science itself. How in the world do you decide which is the thing to do next when there are countless things to do? It's those early decisions we make as entrepreneurs that set the wheels in motion. It's the methodical way about climbing the maze to the top that sets them apart from the rest who are trying every avenue in hopes of finding the right path by accident.

So can this trait be learned? I can't be sure. How do you go about learning how to make the best next move consistently? I'm not saying all of these people make the best next decision every time, but they have a great track record for doing so. Failing quickly is a big key. If you are going down the wrong path, knowing when to stop and start over is definitely a big part of making good next decisions. I have found though that the majority of entrepreneurs I meet are very impulsive. They run with the first idea without enough pause to let the organic deduction process guide them. This is sometimes a good trait because that do-first, ask questions later attitude is also a big part of the risk-taking nature of good entrepreneurs. As with everything, practice might help. Perhaps taking 30 minutes to think things through before making final decisions is the best way to start. As simple as that proposition sounds, most entrepreneurs I've met would struggle with a 30 minute delay to taking action. I am convinced however that although practice may help, this innate ability to pick the next best move is rooted deep in the DNA of the super-star entrepreneur. Do you have it? Only one way to find out.