As Firelord asked me to sum things up, here we go:
First, you cannot do a backup using fastboot. Fastboot is like a one-way road: you can only use it to write partitions (either by flashing a corresponding image, or by wiping it) – but you cannot "pull" a partition.
Which leaves ADB. Yes, it's possible via ADB – but it will require root. As Firelord pointed out, to create a disk image one has to access the corresponding block device, which can only be done with root permissions, as root is who owns them. On rooted devices, one then can use the dd tool. My tool Adebar can prove helpful in identifying the partitions you might need, even creating a script for you to back them up (and to restore).
Whether that's possible with the bootloader locked might depend on the device. For some devices, directly replacing the recovery partition is even the recommended way to get a custom recovery running on it, while on others even that doesn't work. Certainly, the backup part would be possible in any case – but what you'll get is not a "pure stock ROM", but a "rooted stock ROM" – for the reasons pointed out. Only way around this would be doing so while booted into recovery-mode using a custom recovery (as stock recoveries usually don't ship equipped with ADB or other means to access the shell).
1: short for "data duplicator", "disk duplicator" – or "disk destroyer" (as you easily can end up that way if not being very careful)
dd
utility with input as block device file. In order to create an imagedd
must have appropriate permission to access the block device directly. The simplest way is to read from the block device file/dev/block/mmcblk***
. The permission on that file is restricted to root user and root group only, so non-root users definitely can't make an image.adb backup
functionality which does not need root or unlocked bootloaders.