Protecting the "western" border was the job of the only standing army battalion left as an organized unit after the Revolutionary War. That group, finally called the "Legion of the United States," was comprised of about 5000 soldiers and officers in battalions that included infantry, riflemen, dragoons (cavalry), and artillery. It was disbanded in 1796, and was replaced by separately organized brigades of the four types of land troops. Everything else was handled by the "well regulated militia." The War of 1812 proved (a) that the army could function effectively, (b) that militias were not enough to protect against enemies foreign, (c) that there weren't nearly enough army troops, and finally (d) that the US had better get itself more regular army soldiers if it was going to succeed in dealing with enemies foreign. So by 1815 the feds reorganized and expanded the standing army, used mostly in the many Indian Wars from 1815 onwards. The militia therefore declined in importance because the standing army replaced its function, and continued to be relatively unimportant until after the Spanish American War, when the Militia Act of 1903 established the National Guard. The National Guard, then, is the direct descendant of the "well regulated militia" that the 2nd amendment refers to.
MACTECH ubi dolor ibi digitus