Fixes broken v1 and v2 api backup-restore

Also adds unit tests.

Change-Id: I741889d49cffe46bf9165b266a62f2b328354e01
Fixes: bug 1240151
Merge "Fixes broken v1 and v2 api backup-restore"