My day to day workhorse is a fairly well battered 5-year-old MacBook Pro, which has been feeling it’s age recently. Everyone told me these things last forever, but recently I wasn’t so sure that that was the case. GPU panics and High Sierra hijinks have been causing me no end of pain, but in the process of troubleshooting the latest 10.13.x issues I have discovered a great new feature of APFS; Apple’s new filesystem included in the High Sierra upgrade.
Snapshots aren’t anything new to the world of filesystems, indeed we introduced it previously on Smoothwall’s Linux OS using BTRFS, but this is the first time I’ve seen it native on macOS.
Filesystem snapshots as the name implies allow you to take a complete snapshot of the current state of the filesystem. These are stored locally within the volume, and typically incremental so you don’t need the same amount of free space as the volume contains to create a snapshot. Allowing you to store multiple snapshots from different times on one volume.
If you find you have a serious problem, malware infection, or even a system which won’t boot (as I did) you can restore to a previous snapshot almost instantly and resume where you left off. Much more convenient than re-installing and restoring all your files individually from backups.
Great, how do I use this new feature?
Well it seems Apple decided they’d take care of that for you (It just works™, right?). The snapshot management has been left with macOS’ built in Time Machine to handle. As of High Sierra Apple claims it takes snapshots automatically;
- Once every 24 hours (of time powered on)
- Once every week
- Prior to any system update being installed.
It will also self-manage the local storage of snapshots, and prune any older ones as free space becomes low. For this reason, you won’t see the snapshot storage included in disk space calculations.
When you come to restore, you can either use Time Machine normally, selecting the files and the date you wish to restore from, and if the files are available on a local snapshot they’ll be restored even without your backup drive plugged in.
In my case I wanted to restore the whole volume to a previous state, and when using Time Machine restore option from recovery mode (hold CMD+R on boot) you are presented with the time and date of all locally stored snapshots which you can restore to. Once you hit restore, it takes seconds to complete and begin successfully rebooting!
What if I want to manually take a snapshot or see when the last one was taken?
Apple don’t appear to have made it obvious on how to figure out when the last snapshot was taken, and there are no controls in Time Machine to force a new APFS snapshot. In my case I was troubleshooting a problem I had with the 10.13.2 update rendering my system unusable so wanted to ensure I had a recent snapshot before retrying again.
Thankfully there are some CLI tools available which make this easy, I’ve outlined the basics below;
tmutil – Time Machine utility
Tmutil is a command line utility for managing your Time Machine backups. It has many options for controlling traditional time machine backups which I won’t go into for now but also contains controls for the APFS snapshots!
View your current snapshots use command: “tmutil listlocalsnapshotdates /”
The trailing slash is your volume mount point so you could change this to an another APFS volume if you’re not looking at your system volume.
You’ll get a list of dates of each snapshot:
Chriss-MacBook-Pro:~ chris$ tmutil listlocalsnapshotdates / Snapshot dates for disk /: 2017-12-17-150752 2017-12-17-221223 2017-12-18-001128 2017-12-18-011636 2017-12-18-114405 2017-12-18-171942 2017-12-18-181929 2017-12-18-192243
You can see I’ve got quite a few for today already.
Create new snapshot
If you want to test out something which could break your machine, and you want to make sure you have a current snapshot, you can force Time Machine to take one manually using: tmutil localsnapshot
Chriss-MacBook-Pro:~ chris$ tmutil localsnapshot Created local snapshot with date: 2017-12-18-193125
That’s it! Should be pretty much instant, and you don’t need to close files or reboot. It will only save the state of saved files as they are on disk so don’t expect that unsaved document to be included.
So there you have it, while High Sierra is proving to be a the more buggy of recent releases at least now we have APFS and snapshots to restore back to when it all goes wrong! Erm.. thanks Apple.