You didn't say what you want to do with files of the same size.
You also didn't say if you wanted to overwrite files in your 'A'
or your 'B' directory.
I don't know that you can do this with rsync or cp alone. In this example '/tmp/A' is the source directory, '/tmp/B' is the target,
and '/tmp/C' is the destination for backups.
I backup and overwrite files in 'B' that are larger. I simply overwrite
smaller files and do nothing with files of the same size.
# get the size and filnames of files in '/tmp/A' directory and loop through each file found
ls /tmp/A | while read filename
do
# get the size of file in 'A' directory
sizeA=$( ls -l "/tmp/A/${filename}" | awk '{print $5}')
# get the size of corresponding file in 'B' directory
sizeB=$(ls -l "/tmp/B/${filename}" | awk '{print $5}')
# compare file sizes and perform appropriate action
if [ ${sizeB} -gt ${sizeA} ]
then
echo "file in B named \"${filename}\" is larger than A file"
# Backup and overwrite the file
cp "/tmp/B/${filename}" /tmp/C/
cp -f "/tmp/A/${filename}" /tmp/B/
else
if [ ${sizeB} -lt ${sizeA} ]
then
echo "file in B named \"${filename}\" is smaller than A file"
# overwrite the file
cp -f "/tmp/A/${filename}" /tmp/B/
else
echo "The files \"${filename}\" are the same size"
fi
fi
done
I did a really limited test, and it seemed to work. Please test carefully and modify to suit your needs.