Apple has a pretty great backup utility built into OS X called Time Machine. If you’re not using it, you really should.
If you are using it, you may not realize that it is working even when you’re not connected to your backup drive.
If you’re using a laptop, and you have Time Machine turned on, OS X automatically enables local snapshots to save your files in a local cache even when your backup drive is not available.
You can read the whole document here, but long story short, when you turn on Time machine, OS X makes local snapshots and saves them to your boot drive (in an invisible directory at the root of your boot drive, named .MobileBackups). That way, even if your backup drive is offline, if you trash a file, you can recover it from the snapshot. In mavericks and earlier, the tickmarks on the right side of the Time Machine interface are pink if they are on the backup drive, and grey if they are local snapshots. Yosemite does away with any distinctions.
OS X will stop saving snapshots if they threaten to fill up your hard drive. If your drive gets 80% full, it will delete older snapshots to make way for new ones, and if your drive gets to 90%, it will stop altogether. You can see how full your drive is, and what its full of (including snapshots) in the About This Mac window. Click the Storage tab.
By the way, this feature is always on on laptops, and off on desktops. To change that:
sudo tmutil disablelocal
sudo tmutil enablelocal