[ZTE Axon 7 ROMs, Kernels, Recoveries, & Other Deve] dnlilas:
Finally the solution is to use tenfar's signed TWRP : twrp_3.0.2-2_tenfar_signed.img (18,347,298 bytes, md5 6eeb1a9d02470a840bc68019184d9a72)

to backup data before relock then restore after relock.

So I succeed to relock bootloader without losing data by restoring using tenfar's signed TWRP immediatelry after bootloader is locked (which erase data = factory reset). My device id is not changed, banking apps are still functioning. Note: TWRP data backup does not include /data/media, so it is up to you

to backup them (music, video, SMS...). Contacts, Google accounts etc... are synchronized by Google.

Rough steps:

1) You must be stock ROM: boot, recovery, system..., otherwise phone would brick after relock. This work only for Nougat and maybe Marshmallow (not tested). Oreo and later version would not work since tenfar's signed TWRP does not support Oreo.

2) fastboot enabled by using either Axon 7 toolkit or Axon 7 EDL Toolkit (fastboot.img and emmc_appsboot.mbn (aka aboot) flashed).

3) boot bootloader using adb, then load tenfar's TWRP to backup data to external SD card (not internal SD, since on relock, internal data will be wiped):

fastboot boot "twrp_3.0.2-2_tenfar_signed.img" (since bootloader is not yet locked, the fastboot boot command works, without flashing recovery partition)

4) relock by booting to bootloader from inside twrp (reboot button) , then in bootloader mode: "fastboot oem lock" (your data is wiped = factory reset) and bootloader locked.

5) Since bootloader is locked, you have to flash tenfar's signed TWRP: fastboot flash recovery twrp_3.0.2-2_tenfar_signed.img" (fastboot boot command is now rejected).

6) from bootloader menu goto recovery (= tenfar's TWRP), restore the data from backup taken in step 3). Important: refer to Note below to delete lock screen files, otherwise you might not be able to log in to Android

7) without quitting tenfar's recovery, reboot to bootloader, then flash stock recovery corresponding corresponding to your ROM. You remain stock ROM.

8) Reboot system.

Under Windows, USB cable connected, and Device Manager to launch for monitoring connection and states.

Check connection and device id with:

adb devices

In bootloader mode:

fastboot devices

fastboot oem device-info

Reboot to recovery:

adb reboot recovery

In fastboot mode, use fastboot menu (Vol-Up, Vol-Down) to return to recovery.

Reboot to bootloader:

adb reboot bootloader

or use stock recovery menu, or use TWRP button.

To (re)lock bootloader:

fastboot oem lock

To reboot system from adb: adb reboot

To reboot system from fastboot: fastboot reboot

Notes: for backup/restore, tenfar's signed TWRP works well for recovery, boot, system, system image. Do not use it to backup and restore EFS since it seems to have bugs that could brick your phone (lost IMEI...).

For encrypted phone, you have to cancel password input from TWRP, reformat data partition, reboot again immediately in TWRP, then restore from backup.

To delete lock files:

In TWRP, go to Advanced > File Manager, then navigate to /data/system folder. Delete:

locksettings.db

locksettings.db-shm

locksettings.db-wal

gatekeeper.password.key

gatekeeper.pattern.key

Reference:

https://xdaforums.com/showpost.php?p=68546553&postcount=121

"Current TWRP works, i have restore many times DATA , CACHE, BOOT, RECOVERY, SYSTEM (EVEN SYSTEM_IMAGE 6gb) , thrust me been flashing CM13 a lot ,i just haven't try restoring EFS cuz i have NOT had any problems that require that partition .... i did add a NOTE about not restoring EFS Partition thou."