When using the -z mode to compress data when running rsync, is the compression lossless?
sudo rsync -az /path_to/A /path_to/B
How can one ensure that any compression would be lossless?
The short answer is yes.
The long answer is that all generic data compression is lossless, and almost all media encoding is lossy. I'll try to explain why below.
There are two types of compression, lossless and lossy. In lossless compression no information is lost and so the original data can be reconstructed perfectly from the compressed version. In lossy compression, some information is lost, and so the original data cannot be reconstructed perfectly from the compressed version. In this case, the reconstructed version is an approximation of the original, but the file size will be smaller than would ever be possible with a lossless algorithm.
Lossy compression is commonly used for media such as JPG (images), MP3 (audio), and MP4 (video). Using lossy compression results in much, much smaller files because we can get rid of data such that the human eye or ear doesn't notice its absence. This is actually pretty interesting, and usually involves a frequency transformation such as the Discrete Cosine Transform (DCT), but that's beyond the scope of this question.
In the case of generic data compression, when you might be compressing text files or executables, as far as I am aware lossy compression is NEVER used. If you compressed a text file in a lossy manner, you would lose some information, and thus you would forever lose some of the text. If you compressed an executable file in a lossy manner, it would not work the same way (if at all) after you uncompressed it.
Taking it a step further, let's say you have an MP3 file. The audio inside has already undergone lossy compression. However, the MP3 file itself is organized in a very specific manner so that audio players understand how to play its data. If you were to lossy compress an MP3 file, you would lose information, the organization would be destroyed, and in all likelihood it would be unplayable.
CREDITS ... This program uses the excellent zlib compression library written by Jean-loup Gailly and Mark Adler.
zlib is designed to be a free, general-purpose, legally unencumbered -- that is, not covered by any patents -- lossless data-compression library ...
zlib, which is a very well-known, widely-used compression library, there's nothing much you can do.