To create a backup copy of a disk while saving space, use
gzip </dev/sda >/path/to/sda.gz
When you want to restore the disk from backup, use:
gunzip -c /path/to/sda.gz >/dev/sda
This will likely save much more space than merely stripping trailing NUL bytes.
Removing trailing NUL bytes
If you really want to remove trailing NUL bytes and you have GNU sed, you might try:
sed '$ s/\x00*$//' /dev/sda >/path/to/sda.stripped
This might run into a problem if a large disk's data exceeds some internal limit of sed. While GNU sed has no built-in limit on data size, the GNU sed manual explains that system memory limitations may prevent processing of large files:
GNU sed has no built-in limit on line length; as long as it can
malloc() more (virtual) memory, you can feed or construct lines as
long as you like.
However, recursion is used to handle subpatterns and indefinite
repetition. This means that the available stack space may limit the
size of the buffer that can be processed by certain patterns.