How rsync preserves ownership of files depends on two things:
-a option includes the
-g, --group options designed to preserve ownership.
At the file-system level user and group ownership is stored in UID resp. GID numbers. When there is no mapping from UID/GID's to usernames and groupnames tools will simply display those numbers instead.
Users and groups with the same names can have different UID/GID numbers on different systems.
By default rsync will try to match the ownership by username resp. groupname. In other words when the user
vmail is the owner of a file at the source, rsync will make the user
vmail also the owner at the destination (even when they have different UID/GID numbers).
That is usually quite resilient and the most predictable for humans as we normally don't look at ownership in the form of UID/GID numbers.
When no matching user
vmail is present on the remote destination, then a fall-back scenario will happen. Rsync will then preserve the actual underlying UID/GID numbers and the UID number of the
vmail user on the source will used to set the owner.
That should preserver the correct ownership when you reverse the rsync direction and restore the backup.
man rsync :
This option causes rsync to set the owner of the destination file to be the same as the source file,
but only if the receiving rsync is being run as the super-user (see also the --super and --fake-super
options). Without this option, the owner of new and/or transferred files are set to the invoking user
on the receiving side.
The preservation of ownership will associate matching names by default, but may fall back to using the
ID number in some circumstances (see also the --numeric-ids option for a full discussion).
With this option rsync will transfer numeric group and user IDs rather than using user and group names
and mapping them at both ends.
By default rsync will use the username and groupname to determine what ownership to give files. The
special uid 0 and the special group 0 are never mapped via user/group names even if the --numeric-ids
option is not specified.
If a user or group has no name on the source system or it has no match on the destination system, then
the numeric ID from the source system is used instead. See also the comments on the "use chroot" set‐
ting in the rsyncd.conf manpage for information on how the chroot setting affects rsync’s ability to
look up the names of the users and groups and what you can do about it.