Sooner or later in our computer-connected existence, most of us will face a hard drive disaster — usually at the most inopportune time. Important financial documents, the kids’ schoolwork, business files, music, videos, all of your photos — the very elements that make up your life also make up your hard drive. So it’s natural to panic when it appears your hard drive has failed. But don’t throw your hands up in surrender right away. There’s a good chance you can save all of that data.

Here’s what to do before and after a crash.

Related: How to Lock Down Your Home Internet

Before a crash

How many times have you heard prevention is the best medicine? “The biggest thing [you can do] is to keep backups of everything you have,” says John Iemma, director of education at the Bay State School of Technology in Canton, Massachusetts. Here are some ways to do that.

● Use imaging software to create a virtual copy of your hard drive that mirrors its contents. The copy can go into a cloud storage system, external hard drive, flash drive or other devices. “You can have that whole machine ready to go again in basically no time at all,” Iemma says.

● Put your most important files — or your entire hard drive — on an external hard drive. Invest in one as large as or larger than your current hard drive to make sure there’s enough room for all the data.

● Use a cloud storage system, like Google Drive or iCloud. Both provide you with a few gigs of storage, so you can put your most vital documents in a virtual cloud that’s almost immune to failure. The basic options for both of those cloud systems are free, with expanded storage for both in monthly pricing tiers.

Additionally, follow healthy computer practices like keeping up with system updates and watching what you download to avoid dangerous files. If you’re a PC user, Iemma also recommends running the “defragment” hard drive program on a regular basis, which can be found in your Control Panel. (Most modern Macs don’t need to be defragmented.) Make sure you have a good anti-virus system to cut down on the risk of hard drive failure in the first place.

“There are a couple of physical precautions you can take, too,” Iemma says. “Hard drives don’t like to be out in the cold. Same thing with the heat. And don’t drop it — that vibration alone can dent the ends on a hard drive and could kill it.”

Related: What to Do When Your Electronic Treasures Become Trash

After a crash

A hard drive can fail for one of two reasons. The first is mechanical failure, in which the hard drive is physically damaged due to wear and tear or some other type of harm. Keep an ear out for this kind of trouble: When your hard drive starts making clanking, grinding, buzzing, rattling or clicking noises, it’s time to start saving your data before the whole hard drive goes.

“If you do hear noises coming from the hard drive, go out and find somebody [to repair it] that knows what they’re doing. I would recommend a local computer shop, since the big chain stores can get expensive,” says Iemma.

Another option for recovery if your hard drive collapses due to mechanical failure: You can remove the hard drive, pack it up and send it to a professional restorer to get your data back. It’s not cheap — in fact, it can get pretty pricey — but the odds are usually good that you’ll get your data back.

The other type of failure is called logical failure In this case, the hard drive is physically sound, but the loading software on the drive is damaged, usually because of a virus or corrupted file. “In this case, your operating system’s loading files go bad,” Iemma says. If you don’t hear any noises associated with mechanical failure, the failure is likely the logical kind.

You may be able to fix the problem yourself. The process varies from system to system. With older computers, you might be able to use the computer’s system discs to boot up and recover the loading files. But newer computers don’t come with discs. Here, you might be able to use the computer’s built-in recovery programs to set the computer back to a point where the data isn’t corrupted ( on a modern Mac, this will be called the Recovery program using the “Time Machine” feature). Check the documentation that came with your computer or contact the manufacturer to find out the best recovery or restore process for your computer.

If you feel confident in your technical prowess — and the recovery systems aren’t working for you — you can try to remove the hard drive, connect it to a working computer and recover your data. “Just because the [broken] computer isn’t letting you onto the logon screen doesn’t mean you can’t access it from another machine,” says David Zimmerman, the CEO of file and data recovery company LC Technology International in Clearwater, Florida. “It’s not that difficult. Nowadays, to remove a hard drive from your computer, you can just log onto YouTube, and you can find all sorts of tutorials. It’s normally just a couple of screws and that’s it.”

If you’re going to try to take out the hard drive and connect it to a different computer, use caution: You don’t want to do any physical damage to the drive. Once you’ve hooked up the old hard drive, you should be able to browse to the hard drive and recover your data. However, if the drive still doesn’t show up on the new computer, it might be time to enlist professional help.

Related: 5 Smart Ways to Choose and Manage Online Passwords

Michael Nadeau is a freelance writer and occasional, regretful 5K participant living in suburban Massachusetts.