Step 1: SSH keypair in your old server. Check if you already have one in /root/.ssh/ (normally it’s id_rsa.pub and id_rsa). If not, create one with ssh-keygen
Step 2: copy the content of the public key (i.e. id_rsa.pub) and paste it in the file /root/.ssh/authorized_keys on the new server. (Create the file if it does not exist and make sure the permissions are set to 600)
Step 3: edit these lines in the script on your old server and use the path to your SSH private file, i.e.
export REMOTE_SSH_KEY=/root/.ssh/id_rsa
export REMOTE_SSH_PORT=22
export REMOTE_SSH_HOST=your.new.server
(You can use your IP as well)
Step 4: install rsync on both servers
Step 5: check if ssh is working with public key auth from your old server to the new server
ssh your.new.server
Step 6: run the script 🙂