I can preserve ownership of
folderB and all files and folders inside when creating and extracting a tar file as follows:
tar -cpf out.tar folderA/folderB sudo tar -xpf out.tar --same-owner
folderA is owned by root when extracting unless the folder already exists. Is there any way to preserve ownership of the entire folder hierarchy with tar?