How do I fully back up an Xperia Z2 phone? I'm thinking about moving onto a custom ROM, but I don't want to permanently lose any DRM keys. How do I go about fully backing up the contents of the phone before mucking around with it?
I figured it out eventually. It's not easy, because you need to get root before wiping anything (or unlocking the bootloader, which would wipe everything).


Download a copy of the old firmware, which you can find at the XDA forums. You will need to downgrade to this old firmware so that you can take advantage of an old root exploit (vulnerability). I used version 17.1.2.A.0.314 from the UK, but anything from 4.4.2 should work.
Obtain root and install a custom recovery so that we can use it upgrade the firmware. XZDualRecovery is popular. I used Z2-lockeddualrecovery2.8.21-RELEASE.installer.zip. This includes a root exploit so that it can install the recovery.
You can use the custom recovery (TWRP) to create a backup of the TA partition that includes the DRM keys. 
Use the recovery to upgrade back to an up-to-date official firmware version. You need a pre-rooted firmware (PRF) zip file. The best place to look for one is on XDA's Xperia forums. Here's an example for version 23.4.A.1.232. Don't forget to clear the Dalvik cache.


This process does not require you to unlock the bootloader, so the DRM keys are never wiped.