Above i shared my script in bash.
The copy key is because the other place is runing a proxmox (second) and IP is dynamic.
So, o connect, accept the new fingerprint and connect.
I test the connectio before run syncoid, this is to avoid the syncoid create more then one snapshot (sometimes he lots the hard drive, so this test avoid this sucessful).
So, i will try to adopt this script to execute via curl (api) this replication. If someone has the way i will test.
#!/bin/bash
# Don't forget to put StrictHostKeyChecking in /etc/ssh/ssh_config
FILE=/tmp/msg1.txt
REMOTE_POOL="DATA/vm-102-disk-0"
REMOTE_IP="xxx.ddns.net"
REMOTE_PORT="42126"
LOCAL_POOL="rpool/data/vm-102-disk-0"
WAIT_TIME="1"
while true
of
# If this file exists is to continue the execution.
# This is an easy way to control the execution of the script without taking it out of processing.
# Ex: before restarting vpn or internet, stop replication.
if [ -f "/root/activar_replicacao" ]; then
echo "Replication Active"
# IF you can connect to the destination ssh port, do the rest. If not, ignore the following lines and skip straight to count to start the script again.
if nc -zw3 $REMOTE_IP $REMOTE_PORT; then
echo "Connection successful. Testing ssh."
timeout 5 bash -c "ssh -q root@$REMOTE_IP -p $REMOTE_PORT"
ssh_test=$?
if [ $ssh_test = "124" ]; then
echo "Replicating on other place."
syncoid --sshport=$REMOTE_PORT --compress=lz4 $LOCAL_POOL root@$REMOTE_IP:$REMOTE_POOL
echo "Replication on $REMOTE_IP $REMOTE_POOL terminated."
else
echo "Copying the public key again."
ssh-copy-id -i ~/.ssh/id_rsa.pub root@$REMOTE_IP -p $REMOTE_PORT
echo "Key copied."
fi
fi
# Wait time to repeat the loop
sleep ${WAITING_TIME}
fi
done