Tag Archives: Laughing Squid

Using diff (or rsync) to compare folders over SSH on two different servers

So I wanted to find a quick code that will allow me to a diff over two folders as I want to be sure all files get transfered as we are using Plesk migrator to move domains from one server to another. Found a Serverfault post titled How do diff over ssh? but most of the suggestions are for files and not folders and none that work recursively. Well using this answer from Server Fault and some man pages I have the following

diff <(ssh server1 'sudo ls -1aR /var/www/vhosts/domain.com') <(ssh server2 'sudo ls -1aR /var/www/vhosts/domain.com')

Update: So a lot of people in the ServerFault page I linked to mentioned rync with the –dry-run flag. I did not look in to this much but just as I posted this blog the first @reply i got on twitter was from @EvanHoffman asking if I had looked at using rsync. Ok so I thought I should revisited the problem and using rsync and I got the follow:

rsync --dry-run -rvce "ssh -p port#" [email protected]:/var/www/vhosts/ /var/www/vhosts/domain.com/
(I have not tested the rsync solution with a live box but from testing on my local system I assume this would work) One of the limitation of this you need to be on one of the two servers vs the solutions using diff is something you do on your computer that can SSH to both systems.