All posts by bakefy

Universal_Phone_Tripod_Mount_2

My First Product

I created my first 3D printed product.  It is a universal phone mount for a tripod.  I had to print it a couple times to get the design just right, but I feel like I learned a ton along the way.  I used Sketchup to design the print.  The reason I made my own design when others have STL files available is because all of them seemed to require a nut from the hardware store.  While that is probably a more universal fit for every tripod, it involved a trip to the store.  I made my design in mind of not purchasing any additional hardware (I happen to have rubber bands lying around).

My tripod has a 41 x 41 mm (1 5/8 x 1 5/8 inch) quick release plate on top.  I researched that this is called a 3502 Quick Release Plate.  I designed it with an opening in the center so that I can change out parts and make it more universal.  It is also designed to be wider at the bottom to stop it from pulling completely out.  This same part that slides through the mount plate has a hook at the bottom to secure the rubber band tied to the cap.

The cap is designed to slide in and out of the tallest part to allow for different sized phones.  It also has a few different sizes cut into the portion that grips the phone.  I specifically designed this for my phone and my girlfriends phone (HTC DNA, LG Nexus 7).  I would imagine any of the newer iPhone’s would fit just fine.  If your phone is roughly 70 mm wide it should make a great fit.  The trouble with any fit will likely be your tripod.

 

if you would like to download this print for your own printer, check it out:
http://www.thingiverse.com/thing:730489

 

 

Air_Horn_Prank_2

My Best April Fools Day Prank

Last year for April Fools day I decided to play a prank on my girlfriend.  She always leaves for work much earlier in the morning than I did at the time.  I got my prank idea from a picture of an air horn duct taped under a computer chair.  The idea here is that the air horn would go off when the target sat in his or her chair.

Air Horn Prank

Of course I got this idea at 1 AM that night.  I got up out of bed, and went to the store.  I tried to go to a Walmart that stated it was 24 hours.  Their hours were marked wrong online (and I am sure they still are).  I tried to go to a CVS, and a Walgreen’s, they didn’t have any air horns.  So I traveled 20 minutes north to the nearest Meijer.  They had mini air horns!  These were perfect to hide.  I bought three.  I also bought some funny duct tape (mustache) and some cream cheese (we will get to that later).

I secured my traps all around the house in a way that forced her to hit all three.  She would have had to leave through a window in order to avoid any of them.  I was renting a house built in the early 1900s at the time.  So there were no shortage of unnecessary doors.  The first horn was placed behind the bathroom door.  There was only one full bathroom in that house, so it was a sure thing.  The next horn was placed behind a swinging butler door that led to the kitchen.  Lastly, I placed the remaining horn behind a door that separates the kitchen from the basement / outside door.  She could have avoided this horn if she left through the front or back door, but she always left through the side door.

I forgot to mention that I tested these horns in my car at 2 AM on the way home so I would not wake anyone up near my house (they were SO LOUD).  I was so giddy with laughter I could hardly get to sleep.

April 1st she wakes up and gets out of bed.  She starts to make her way out of the bedroom and I am literally biting my pillow to keep myself from bursting out with laughter.  She immediately goes to the bathroom door (like we all do when we wake up) and the horn honks full blast.  She yells some swear words and goes about her day.  I try to go back to sleep (it’s 5 in the morning).  30 minutes later or so, she makes her way down to the kitchen and I hear that horn blast.  This time she is pissed.  She comes running up to the bedroom where I am sleeping / laughing uncontrollably and she punches me in the shoulder (it was playful).  She asks me if there are any more, and I avoid the question.  This time an hour goes by and she is just going about her morning rituals while I sleep in bed.  The last horn blasts!  She screams and leaves the house.

Anyway all that and it was an incredible morning for the both of us.  This was all possibly because of the tile floors.  Carpet would have posed some difficult problems when attempting to secure anything down.

This wasn’t all I did.  Luckily, its all she encountered.  For some reason she had this habit of using my deodorant.  I guess she ran out and just never bothered to replace hers.  I talked to her about this, I wasn’t a fan of sharing deodorant.  So I rolled my deodorant stick in a few inches while pushing into the cream cheese.  They were both about the same constancy and color.  I even put a little arm hair in the top and molded to to look like it was used.  Then I just rolled it back down and sat it back in the medicine cabinet.

Luckily for me, she didn’t use this.  This could have been a relationship deal breaker after all I did.

Cream_Cheese_Deodorant

Old_Bulb_Sizes

Replace your Incandescent Bulbs

So I just bought my first home and it was about time.  I purchased a home that was built in the early 60’s and it shows.  The structure of the home is fantastic.  However, the efficiency of the home has room for improvement.  The first thing I noticed is the amount of lights around the house.  There were so many bulbs and they were all incandescent.  This is the classic style of bulb we all grew up with (unless you were born after 2000).  The actual definition of incandescent is: emitting light as a result of being heated.  That right there is a loss of energy in the form of heat.  In the winter you might not be complaining as much, but in the summer you are only hurting your bills more.

So what do you do?  Well, there are two options: Compact Florescent Lights (CFL) or Light Emitting Diode (LED).  I am sure you have heard of both by now.  They are certainly not new technologies, but LED is just now becoming affordable and practical to use in the home.

I am going to briefly compare the two options.  I am not going to talk about incandescent any longer.  It’s only purpose is wasting your money via electric bill.

CFL is a great option at this point in time.  These bulbs have become extremely affordable, with no real drawbacks.  They are not as efficient as LED, but they are obviously better than that bulb we no longer speak of.  CFL bulbs also last a really long time.  The only real drawback I have read about is that they may have issues with flickering or fluctuating power sources.

LED’s are the choice for me.  Their only real drawback is the initial cost.  They are dramatically going down in price, but still more expensive than the alternative.  Something else I have noticed is that they can flicker with AC interference.  The only time I have noticed this is when I have a space heater and lamp connected to the same breaker.  I am guessing any power hungry alternating current device will cause this effect.  This also could be a result of my home not having adequate wiring to the standards of today.  80% of my outlets do not have a ground plug.

So really you have the option of spending more upfront and slowing saving over time or spending less and paying more in the end.  The LED’s are supposed to outlast the CFL’s by several years.  Some LED’s are rated to last over a decade (maybe more).  I didn’t bother buying anything at that quality because they are more expensive and by the time they burn out, I imagine the technology will be even further advanced.  We may have a whole new type of bulb in 2030.

I spend just over 300 dollars on LED bulbs.  The research I did said that I should be saving roughly 30 dollars a month with LED bulbs (there are calculators online to estimate these savings).  So in a matter of ten months they will have paid for themselves and the 5 or so years after will all be savings.

When I first bought them all at once, the clerk commented “this is the price of a round trip to Florida!”  While that is true during some parts of the year, I will be saving as much as 360 dollars a year by making this switch.  After 5 years (minimum guaranteed lifespan of LED bulbs) I will have saved $1800 dollars.

So you decide, whats the best option for your home?

Keep in mind, there are bulbs that are not worth replacing.  If you have a bulb in your fridge that is only one for 2 minutes a day, you will not see the savings.  If you want to make the switch to LED, replace the bulbs that are on the most.

Old_Bulb_Sizes
These are some old bulbs that I found in my home. From left to right is a standard 65 W, 200 W, and 300 W!
MakerFarm_Prusa_i3v_12

My First 3D Printer

I have been dreaming of owning a 3D printer for several years now.  It was hard to justify the purchase of such an expensive hobby when I was still a slave to rent.  Well, I finally bought my first home, so now I can justify it!

I still wanted to be conservative about the price point, and I didn’t want to miss out on any features.  I decided to go with a proven printer that was also a kit.  I went with the Prusa i3v 12 inch model.  This model uses aluminum slotted rails for movement.  I am not personally familiar with the rod models, but I have read my version can print faster.  I also think it adds to the stability of the printer.  Especially since the frame consists of laser cut wood.

So I ordered my kit from MakerFarm for roughly $700 USD.  I added several rolls of PLA and ABS, so it was a little more.  I also upgraded to us RAMBo electronics and a hexagon hot end (0.4mm).

So I ordered the printer and the waiting game began.  There was a 10 business day lead time, so I had to patiently wait for my new toy to arrive.

During that time I read and researched every little upgrade I was going to do.

The printer arrived on time (maybe even a day early).  I waited until the weekend to assemble it.  I dedicated my entire weekend to assembling that printer. I read that it would take roughly 18 hours. I took a much longer time because I am a perfectionist about my assembly and wiring. I gave a lot of thought to every part assembled. I also utilized heat shrink to make every wire safe and clean looking. In the end my printer looks fantastic. Once I did finally get everything assembled and configured my first prints were so good. Makerfarm provided me with a configuration file that leaves very little room for improvement. It was extremely encouraging to see the results I achieved in the first few days.

MakerFarm_Prusa_i3v_12
This is my MakerFarm Prusa i3v 12 inch 3D printer. It was made from a laser cut wood kit.

I have made many improvements since I first assembled the printer. I am now using a 1/8th inch thick mirror glass with clipped corners for my print surface.  I researched that the thin metal surface on a mirror helps distribute the heat from the heat bed more evenly.  I am also utilizing an aero gel insulation under the heat bed.  I implemented this because heat being transferred to the wooden frame was causing issues with warping.  Now the aerogel insulation keeps virtually all heat away from the wooden surface. This means zero warping. Warping causes the y-axis to jiggle as well as distorting the print bed. The print bed is virtually impossible to get perfectly flat across all 144 square inches. I have a cure for that as well.

This problem is solved with a self leveling z-axis.  I utilized some existing plans and models that I printed to accomplish this.  A servo motor controls an arm with a sensor that detects the distance to the print surface. The servo is excellent because it allows the mechanism to pivot out of the way before a print.  This method of setting the z-axis is preferred because it can be mapped in several points on the grid.  This compensates for any warping in the print surface.

Another addition I made to this printer is a print cooling fan. This will improve both ABS and PLA prints.  In order for me to be able to install this upgrade I had to reroute the hexagon hot end always on fan.  It now sits under the larger extruding gear and pulls the air away from the print.  This not only frees up room for the additional fan but improves the airflow.  It requires an ultra tiny fan and a few custom mounting pieces.  Everything was found on Thingiverse.

Some of the more basic things I did to improve my print quality were making sure that I had a stable surface to print on as well as providing a cushion to dampen any vibration.

I have also made a small change the the universal extruder. It was designed for both 3mm and 1.75 mm filament. Using a white Teflon tube I filled the gap and removed any room for filament to jam between the hobbed bolt and the hot end.

I am also hoping to print flexible filaments with this improvement. When I first started printing I had issues with the extruder losing grip of the filament. Luckily I overcame this issue by simply tightening the spring pressure mechanism forcing the hobbed bolt to have more pressure.

Network Labels

How to Properly Wire CAT6 (Part 3 of 3) [Terminating and Testing Your Runs]

So by now you should have read how to run the cable as well as plan your project.  The last things you will need to do are terminate your connections and test them!

First we should quickly go over the two RJ45 wiring standards.  There is A (T-568A) and B (T-568B) standards.  There really isn’t a benefit to one over the other, as long as they match on both ends (thats how you get a straight through connection) you’re going to have success.  However, the standards A and B are color coded on pretty much any jack and patch panels you purchase for your project.

In my example I went with the B standard because I researched it is more common in corporate networking.  I believe A is older, but more popular in conjunction with running phone lines.

So first you are going to want to strip a short length of your cable.  If you strip further back in order to immediately unsheathe the full amount you risk the chance of damaging the pairs you are about to punch down.  They are extremely small gauge and easy to damage.  You might not even see it, but you will find out you did it when the cable doesn’t pass its tests.  So only expose a short amount of the pairs.  You will be presented with 4 pairs of wires, a cable protector, and a pull string.  This may be only present in higher quality CAT6.  So pull the pull string, and it will unsheathe more of the protective coating and reveal more of the pairs.  This will avoid the possibility of damaging the pairs during the stripping process.  Once you wires are exposed, you will want to cut away the pull string and wire divider.

Next, you want to start unraveling your wire in order to place it in the proper location to be terminated.  Make sure you only unravel as little as possible.  The twists in the pairs improve the signal quality.  The jacks you are placing the wires into should be color coded to the patter you decided to go with.

Lastly you will want to punch down the cables.  Your punch down tool has a sharp end an an end that doesn’t cut the wire.  You want to punch down each wire in a way that the outside of the wire is discarded when its fully punched.

Once you have punched down all the pairs, keep the jack exposed before tucking everything away.  I recommend testing your connections before cleaning up everything up.  Punching down into the back of the patch panel is extremely similar to the wall jacks.  Stick with either A or B standards on both sides or you will create a crossover cable, and most likely have some strange networking issues because of that.

I recommend securing your patch panel to a network rack that is not able to move around.  The last thing you want is one of the pairs coming lose.  If your rack is on wheels, you’re likely going to be seeing networking issues over time.

You will also want to mount your switch right above or below your patch panel.  This will give you the ability to utilize short length patch cables and quickly get your network up and running.

Lastly you want to test each connection.  This is straight forward.  Test each pair then label them on both sides to help you stay on top of what ports have already been tested.

Once everything is labeled and tested you can tidy up your wall plates and clean up!

Don’t forget to put any drop ceiling tiles in their place.  You want to leave a good impression and I have always been told to leave places cleaner than they were.

How to Properly Wire CAT6 (Part 2 of 3) [Estimating Your Job and Running the Cable]

Alright, you already read what tools and supplies you will need, now lets move on to the next steps.  Are you doing this for yourself or for a company?  Are you getting paid?  You need to give that company an accurate estimate.  In order for you to do this, it would be best if you had a PDF floor plan of their office.  If you don’t have a some kind of floor plan, you might as well make a quick one.  You are going to want an accurate estimate.  I would recommend billing them for the time it takes to properly quote them (especially if you have to manually measure the office).  If this is a leased space, the building manager may have a floor plan.  If for some reason there isn’t a floor plan to scale, pick up a long tape measure.  I would recommend at least the 300 feet tape measure because 28 feet more and you’re exceeding CAT6’s length limitations.  With some graph paper or some office layout software scratch out a rough draft of their office (to scale).  You will want to walk around and take note of where they want new runs, where CAT5 is being replaced with CAT6 and where lines are being removed.  Keep in mind obvious limitations and avoid being parallel to power when possible.  You will also want to take a look at how the building is constructed.  Are the studs metal or wood?  Metal beams often have access holes or tabs that can be lifted to run wire.  With wood you will have to drill access holes.  All of this will cut into your time.  If you are replacing old wire you’re probably in luck.  Sometimes the holes may not always be wide enough.  Just estimate to the best of your abilities.  You don’t want to tear the place apart getting accurate measurements, you just want to spend a little time to save yourself in the end.  Something else that is also extremely important, measure the height of the ceilings.  This will add to your cable lengths and will certainly add to your estimate.

Once you have a properly created a PDF floor map with termination locations marked use a program called Foxit Reader to quickly measure distances.  Make sure to set the scale to equal your drawing.

officemeasure

At this time I create an Excel or Google document that looks like this:

 

Room Distance Drops Total Distance Ceiling Hieght
Entrance 101 20.36 1 38.36 9
102 A 24.7 1 42.7
102 B 18.47 4 145.88
Office 105 18.74 4 146.96
Office 108 21.92 4 159.68
Office 109 A 9.71 4 110.84
Office 109 B 16.05 4 136.2
Office 110 28.25 4 185
Office 111 A 22.54 4 162.16
Office 111 B 29.32 4 189.28
Office 112 39.17 4 228.68
Backroom 114 50.88 2 137.76
Garage 115 51.44 2 138.88
Wireless 1 18.47 1 36.47
Wireless 2 16.08 1 34.08
Wireless 3 34.92 1 52.92
45 1945.85

 

From here I have each location (room) defined as well as the distance.  The distance automatically adds in the ceiling height.  From here you input all of your drops and locations and you have your total length.  Now you know how much CAT6 you will need for this job.  You can also copy your work onto another worksheet and alter the amount of drops per office.  This is a quick way to provide a very detailed and accurate estimate.  The next part is something you need to figure out for yourself.  How are you going to charge the customer?  Do you charge per drop or per foot?  Depending on your location companies are charging as much as $400 per drop.  This is completely up to you.  Just as long as you cover your costs.  I would not do it for less than $1.50 a foot.  That is an extremely cheap price (this is only if its an easy job, you like the customer, or you’re hurt for cash).  You will make money, but you will wish you asked for more.  Running cable is hard work, make sure you are compensated appropriately.  You also need to charge for your equipment installations.  I would suggest that you make another excel sheet to spell out all your additional expenses  (patch panel, network rack, cover plates, patch cables, switches, battery backup) and make sure you are estimating proper hours for all the punch downs, testing, labeling, and of course running of cable.

So lets run some cable!

I’m sure there are several ways you can run cable.  I am going to go through the only two I can think of using.  The first way, the cable already exists.  Lets just say you are replacing CAT5 with CAT6 (or maybe a faulty wire).  First you will want to use your tester and make sure that where you are pulling matches start and finish.  Use your toner and trace the cables.  If you are unsure, test the pairs of the cables in question.  Once you have proven that you have the right wire on both ends, secure new wire to one of the ends.  If you are replacing a single run with two runs, hopefully you have two spools of wire (if you only have one spool but need two runs use a pole rope).  Using duct tape wrap two new runs to this old CAT5 you have already pulled from its punch down panel or port.  Wrap this as tightly and securely as you possibly can.  You will also want to take this time to mark one of the wire to distinguish the two new cables.  Hopefully you have a partner helping you.  This will really speed up the wiring process.  One person will be feeding wire and the other will be gently pulling.  There are so many things that it can get stuck on even in a drop ceiling construction building, so take your time.  If you manage to pull the old wire out and away from the new runs, you will be creating more work for yourself.  Fishing new line through a whole in the wall can be a real challenge.  I can’t stress enough to secure your new line tightly to the old line.  If something gets snagged get up on a ladder and find out what is holding you back.  Don’t keep pulling.  The wire will give (or worse, something else gives).  This is where having two ladders and 2-way radios is very helpful.  When you finally make it through pull the new line at least three feet out of its opening.  It’s always good to have a little extra on both ends so you never cut yourself short.  You also don’t want this run to be necessarily tight.  There is no need to put stress on the cable.

The other way you would run a wire is if its a brand new building with new wire to be run.  You would want to use a cable snake.  The snake is handy because it wont tangle up easily.  It makes it possible to guide the flimsy wire through small and tight places.  If you are running wire in a drop ceiling with enough room, you can probably toss a coil of cable in the general direction of the future termination, then finish the job with the snake.

Often times a building will have whats called a firewall in the construction of the walls.  If that’s the case you will need a special extra long drill bit.  A firewall is essentially a horizontal 2 by 4 that stops a fire from spreading as quickly.  These are great to have, but extremely difficult when running wire.  What you will want to do in this case is look for a location to run all or the majority of your runs up into the attic, then move down (or in the basement and up, whatever makes sense).  That way you are not constantly drilling.  I would much rather use more cable than be drilling holes all day for the project.  Especially if there are firewall beams hidden in the walls.  Just think about that before planning our your cable runs.  Time is money, and your time is much more valuable than a few hundred extra length of CAT6

I can not stress enough how important it is to turn power off in the areas you are running wire.  With that being said, I would recommend the use of flashlights.  Headlamps are the absolute best thing.  You can not have enough flashlights!

That concludes today’s lesson, next I will tell you about punching down your runs, and testing those cables.

 

How to Properly Wire CAT6 (Part 1 of 3) [Tools and Supplies]

Tonight I am going to go over something every tech person should do at least once.  I feel every system administrator or tech geek should be able to wire their home or office with at least a few network runs.  In order to do it properly you will want the following tools:

You will also need the following supplies:

I am going to go over the list above in greater detail.  I feel like the cable snake is a pretty important tool for running new wire.  You can sometimes get by without a snake if you are replacing CAT5 with CAT6 (or some other wire).  With this method you may be able to use duct tape to secure to the old wire and pull your new runs.  The cable snake is going to be essential for wiring a building with no runs in place.  Another great tool to have is pull rope, or twine.  A pull rope is preferred because it is designed for the job, but twine will usually work if you have it already.  This is extremely nice if you are pulling multiple lines and only have one spool.  Or maybe you are just pulling more lines than you have spools of CAT6.  In this method you would pull your CAT6 and secure the pull rope for future runs.  This is especially recommended if you have any drywall to repair after running cables.

A Dremel is just a great tool to have.  It can get you out of trouble when things just don’t fit right.  It will cut through metal, wood, drywall, you name it.  A Jab Saw should get you buy in most cases, but I highly recommend a Dremel.

Next is a Cordless Drill.  Corded will work, but its a pain when you need to drill in the attic or high in the ceiling.  A charged battery should last you the entire job, and be more than enough.  I also use my drill with a screw driver bit.  This speeds up the process of removing wall plates and will help with unnecessary fatigue.

If you are punching down to any wall plates you will want a punch down tool.  Don’t go cheap on this tool, it is very important you are not screwing these connections up.  You will pay for it in the end.

An RJ45 Crimping Tool will be needed if you are terminating to an RJ45 Connector.  This would really only be if you are making patch cables or sometimes PoE AP’s would want this end terminated.

Wire Cutters are very important.  The cutters built into any crimping tool or multi-tool (however, very nice to have) will just slow you down.  Get the real thing and keep them with you.

Screw drivers are an obvious need here.  You probably already have some, but make sure you do, because this is not optional.  Many times wall plates are flat head (I really don’t know why they went that route).  Another good idea here would be screw bits for your cordless drill.  If you have bits for your drill, have at least a regular flat head and Philips screwdrivers on hand.  I have gone to quickly in the past and ruined an outlet by slipping with the drill.  This wont happen with hand tools.

A flashlight is important.  Many times when you are running wire it may be near some power.  Don’t chance jabbing your metal cable snake into that life-ender, (They do make fiberglass tools to run wire, but you’re still running a copper line, just be safe!) just turn the power off, and use flashlights.  I recommend a headlamp of course.  Sure, it looks like you are spelunking, but you’ll get the job done faster and with much less frustration.  Thinking back to before I was using a headlamp was dark times (lol, a pun!).

A network tester is important.  You can certainly go cheaper than what I have linked.  However, if you plan on doing this professionally, I would recommend getting a nice cable tester.  They will tell you everything you need to know.  If you want to go the cheap route, you can get a toner and a cable pin out reader.

A label maker is really nice to make the job look professional.  I can’t tell you how many placed I have been to where they just write on the wall plate with a pen.  It looks trashy and you can’t always read their handwriting.  Not to mention it makes you wonder how well they ran or crimped the cables.

Two-Way Radios are a big help because this is usually a two person job.  You don’t want to be yelling down the halls during business hours, and they make it more fun as well!

You will need a ladder.  You shouldn’t be standing on chairs and desks, you need a ladder.  A folding ladder like the one linked is incredibly handy.  Mine fits in my little compact car (with the seats down) and it can fold into a ladder twice the size.  The only downfall is that it is a tad heavy.

 

Some other tools that may be needed are a socket set, a set of pliers and a nice knife.  You never know what you are getting into.  For example I had to assemble a small server cabinet that had rolling casters.  Many network and server cabinets (even two post) will require a socket set.  If you are installing a two-post rack, you will want to secure it to the floor.  This usually means drilling into cement.  Get yourself a nice masonry bit set for the job.

Once you have collected all or most of the tools above, you will be ready for the next part of this post.  If you are on a budget and just want to get the minimal tools you can just pick up a simple networking kit.

How to Backup your Linux Server with Google Drive (Step 3 of 3) [Remote Backup Script & Grive Script]

This is the last post for this how to.  Hopefully you have already read and completed the following posts:

Part 1 – Local backup script

Part 2 – Installing Grive

Now we create another script.  This script may be different depending on whether or not you decided to go with a separate backup server.  I am going to paste this entire script into my post and you just need to read anything past the # for any comments.

Create this script in etc/cron.hourly.  Make sure to take off the .sh and make it executable.

#!/bin/bash
#Rsync multiple servers then Google Drive Sync
#Manipulate this script to match your server names, usernames, and associated passwords. 
#SSH will also need to trust the connecting server, so make sure to test each of the SSHPASS lines below in an SSH session.  Another option would just be to have previously SSH'd to all of the connecting servers.

#EXAMPLEWEBserver1 - [websites and databases]
sshpass -p "PASSWORD" rsync -avs --delete [email protected]:/var/backups/files /root/GoogleDrive/Backups/EXAMPLEWEBserver1

#EXAMPLEWEBserver2 - [websites and databases]
sshpass -p "PASSWORD" rsync -avs --delete [email protected]:/var/backups/files /root/GoogleDrive/Backups/EXAMPLEWEBserver2

#EXAMPLENAMEserver1 - [main bind files]
sshpass -p "PASSWORD" rsync -avs [email protected]:/etc/named.conf /root/GoogleDrive/Backups/EXAMPLENAMEserver1
sshpass -p "PASSWORD" rsync -avs --delete [email protected]:/var/backups /root/GoogleDrive/Backups/EXAMPLENAMEserver1

# Directory to backup
BACKUPDIR=/root/GoogleDrive/Backups

# Google Drive directory
GDRIVEDIR=/root/GoogleDrive

# Directory target in remote
TARGETDIR=/Backups

# =====================================================================
# It is unlikely you will need to edit anything below this line.
# Config END

# Create backup dir if not exists
echo Creating ${GDRIVEDIR}/${TARGETDIR} if needed
if [ ! -d "${GDRIVEDIR}/${TARGETDIR}" ]; then mkdir ${GDRIVEDIR}/${TARGETDIR}; fi

# Moving to Gdrive Dir
echo Entering ${GDRIVEDIR}
cd ${GDRIVEDIR}

# Initial sync
echo Initial Google Drive Sync
grive

# Coping new content
echo Copying from ${BACKUPDIR}/* to ${GDRIVEDIR}/${TARGETDIR}/
cp -R ${BACKUPDIR}/* ${GDRIVEDIR}/${TARGETDIR}/

# Showing files copied
echo Files to sync
find ${GDRIVEDIR}/${TARGETDIR}/

# Final sync
echo Final Google Drive Sync
grive

Like I mentioned in the comments of the above script, you will need to run each individual SSHPASS line to build a relationship between each rsync server.

 

A possibly more simple approach would be to just initiate a remote SSH connection from the backup server.

root@backup:~# ssh EXAMPLEWEBserver1.yourdomain.com
The authenticity of host 'EXAMPLEWEBserver1.yourdomain.com (127.0.0.1)' can't be established.
ECDSA key fingerprint is 03:3e:79:2c:3e:bb:ea:8a:fa:39:30:86:1a:d1:9f:24.
Are you sure you want to continue connecting (yes/no)?
root@backup:~#

Each of those lines are pulling files down from the remote server onto a local drive so they can be synced with Google Drive.  If the line has –delete in the script it will clean up and local files that have since been deleted on the remote location.  This keeps files that are past that 5 day old length automatically cleaned up.  Otherwise you will end up syncing every file your server ever puts in its backup directory.

If this script is running properly that is all you need to do.  Backups should be showing up on your Google drive regularly!

**With this current setup files will not be automatically cleaned up from the trash in Google Drive.  I believe this can be fixed, so I am currently working on that.**

GRIVE

How to Backup your Linux Server with Google Drive (Step 2 of 3) [Installing Grive]

GRIVEWelcome back! Hopefully you have already read my previous post.  Now that you have local backups automatically running on your Linux server, we need to get those files synced to Google Drive.  I am going to explain the step where I pull all my backup files to a backup server.  If this is unnecessary for your needs, feel free to skip to installing Grive on your Linux Server.

On my dedicated backup VPS I have a script that runs hourly to pull down backups and sync with Google Drive.  This server is nice to have separated from the other web servers in my environment because I want to practice “best practice”.  Right now I just have a friend of mine that I am managing a Linux server for, but I would like to be in a position where I can support others without additional configuration.  When you install Grive you will understand why I did it this way.  If you install Grive on a per server basis, each server will have a copy of all backups.  With one dedicated server, you limit the amount of copies.  This improves security and is just an overall cleaner install.

So lets install Grive:

My backup server is 64bit Ubuntu 12.04.  At this point 64 might be the only supported OS.

If you are using Ubuntu 12.04 you will need to run this command:
This step can likely be skipped on newer versions of Ubuntu Server

sudo apt-get update && sudo apt-get install python-software-properties

Once that is installed you will be able to install this reposiltory:

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install grive

So now you have Grive installed.  We need to create a directory for Grive to work in.

mkdir ~/google_drive
cd ~/google_drive
grive -a

The command you just ran will eventually provide you with a URL to Authenticate with your Google account.  Copy that URL into your Broswer, then allow Grive to access your account.

Grive should begin to sync the files in your Google Drive account.  Now, you understand why you may not want this on your web server.

So now you have Grive installed, authenticated, and syncing with your Google Drive account.  The last step is configuring another script to automate syncs as well as pull them down form your various servers.

Please check that out in my next post.

Linux_Plus_Google_Drive

How to Backup your Linux Server with Google Drive (Step 1 of 3) [Local Backup Script]

Linux_Plus_Google_DriveI have a couple of Ubuntu and Centos VPS’s and I needed a solution to backup to a remote location.  I wanted this backup location to be something I could trust, but also inexpensive.  My main concern was keeping this backup separated from my VPS provider (Not that they have not been more than adequate).  There is a saying, and I believe it goes “Don’t put all of your eggs in one basket”.  I believe I first heard that saying with investing.  I try to live by that rule whenever feasible.  So I really had two choices.  Back it up to my home server (and eat up my bandwidth at times) or attempt to back it up to Google Drive.  I went with the ladder.

Google Drive is an optimal choice because it is included with my Business Apps account.  Even a free Gmail account will include 15 GBs of Drive space.  The problem is, Drive has no official support for Linux.  However there is an open source solution.  There always is, that’s why you have a Linux server right?

So, how did I accomplish this?

Well I went about this using some pretty simple tasks.

  1. I have multiple servers with multiple sites and databases on each server.  I use a simple bash script that runs every night in a cron job to keep a local copy of both my databases and my web content.  These files are automatically removed after being more than 5 days old.  They are also compressed into a tar.gz file.  This cuts down on storage size as well as transfer time.
  2. Because I manage multiple servers and I don’t want all of them to have full access to my Google Drive data, I have a VPS dedicated to backups.  This server has the open source version of Google Drive installed as well as some other scripts targeted at syncing backup directories.  These data syncs happens via SSH and RSync.  The other responsibility of this server is to trust the other servers.  This way none of the servers I am backing up have access to any of the data but their own.
  3. Then the data is synced hourly with Google Drive.  Now, that may seem strange to make this sync run hourly, but I will tell you way.  Google Drive for Linux is not supported and a bit buggy.  I have seen it fail a few times and it constantly says there is an error, even though it works fine.  I have found that running the script again after a failure eventually fixes it, usually the first time around.  Plus, if there is no new data to sync, then the script is done running in seconds.  This error I am seeing could possibly be a configuration issue on my end, but I don’t really care all too much because it has not failed to backup one night.
  4. I have had this in place for over a month now, and each time I check my Google Drive is in sync with my backup server.  It is a thing of beauty.  So not only are my backups being stored in the cloud, now I have the option to sync those backups locally with my machine.  I especially like this because what if I screw up and forget to pay my Google apps bill?  At least I will have the latest backup stored on my laptop (along with everything else on Google Drive).  Thankfully I am setup with autopay, and don’t think that will be an issue.  Another great feature is that I can share backup directories.  Now that these files are in my Google Drive I just right click and share that directory with the customer this data belongs to.  In my case I just run a server for a very close friend of mine.  However, we both always have access to local or cloud backups at any time.

Having backups of your data is extremely important.  You never know what may happen to your server.  This is peace of mind that you just can’t afford to live without.  I feel confident that I could spin up another VPS and have my sites back up and running before DNS would propagate (My TTL is 1 hour).  Google also automatically keeps files that are deleted for 25 days.  This means that even if I delete a line of code and I don’t realize the bad effect this has on my site, I can still find and restore that line I removed up to a month back.

Okay, so lets get started:

First you need to have a file or directory of files to backup.  So let’s create your local backup files.  I will paste my backup script below and explain it line by line.  At some point I borrowed this script, if I can find the original creator I will link to your site.

#!/bin/sh

THESITE1="website_name"
THEDB1="website_db_name"

THEDBUSER="put_your_db_username_here"
THEDBPW="**************"
THEDATE=`date +%d%m%y%H%M`

mysqldump -u $THEDBUSER -p${THEDBPW} $THEDB1 | gzip > /var/backups/files/dbbackup_${THEDB1}_${THEDATE}.bak.gz

tar czf /var/backups/files/sitebackup_${THESITE1}_${THEDATE}.tar -C / var/www/$THESITE1
gzip /var/backups/files/sitebackup_${THESITE1}_${THEDATE}.tar

find /var/backups/files/site* -mtime +5 -exec rm {} \;
find /var/backups/files/db* -mtime +5 -exec rm {} \;

Line 1 is commented out, so that’s nothing to worry about.  Just defining that this is indeed a bash script.

Line 3 is just calling out the website name.  This will be used in the script below to name the files.  The same goes for line 4, but this is for the database.

Lines 6 and 7 are asking for the MySQL database username and password.  Line 8 you can leave alone, it just defines the format of the date.

Line 10 is the script that actually dumps the database.  Here you will want to make sure that the file location above exists and is where you want everything to end up.

Lines 12 and 13 are backing up and compressing the site data.  You will also want to make sure the website location and backup location are correct.

Lastly Lines 15 and 16 keep the files no more than 5 days old.  You can certainly alter that number to keep more or less depending on your needs.

 

This script can handle multiple databases and websites.  You just need to make sure that you create multiple variables for each site, database, user and password.  Then you will need to duplicate the code below those variables and replace them so each site has its own set of instructions.

Now you need to test this script.  Save it as backup.sh and make sure to make it executable.

Run this script in SSH and test to see if everything was created properly.  If you have any errors along the way feel free to post a comment below.  I will try to answer as soon as I can.

If this script ran and you now see your site files where they are supposed to be, everything worked!  A big tip: you should attempt to restore that file eventually.  You never want to assume everything is fine.  I try to pull down a backup at least once a month and test to make sure its not corrupt.

Now, we want to setup a cron job.  I would recommend just putting this newly created file in your daily cron directory (etc/cron.daily/).  I have seen where they sometimes don’t like the .sh extension.  Just remove that and make sure its executable.  Let this run for a few days, and keep up with it.  Maybe even try to restore a database and a few files.  Once you are sure it is working as you want you will be ready for the next step.

As for me, I need to get some rest, so I am going to write that bit in Sunday’s blog post.

Thanks for reading!