


    host_dst="192.168.3.5"
    zfs_root_dst="rpool/vm/jls/" # MUST ends with a /
    zfs_root_src="zroot/vm/jls/" # Must ands with a /
    jail_name="jlstest"
    
    
    # check destination dataset exist
    if $(ssh root@$host_dst "zfs list -o name -H | grep -q $zfs_root_dsti$jail_name"); then
       echo "dataset $zfs_root_dst$jail_name found on $host_dst"
    else
       echo "dataset $zfs_root_dst$jail_name not found on $host_dst"
       if $(ssh root@$host_dst "zfs create -p $zfs_root_dst$jail_name"); then
           echo "dataset $zfs_root_dst$jail_name created on $host_dst"
       else
           echo "Failed to create $zfs_root_dst$jail_name on $host_dst"
           echo "exiting"
           exit 1
       fi
    fi

    # Getting the mountpoint at destination
    mount_point_dst=$(ssh root@$host_dst "zfs get -H -o value mountpoint $zfs_root_dst$jail_name")
    echo "mount point: $mount_point_dst ***"
    
    # Create a uniq snapshot name
    snap_date="$(date +%Y%m%d-%H%M%S)_s1"
    
    echo "create snapshot: $zfs_root_src$jail_name@$snap_date"
    zfs snapshot $zfs_root_src$jail_name@$snap_date  || { echo "Failed to make a snapshot of $zfs_root_src$jail_name on this machne"; exit 1;}
    
    # Getting the last snapshot's names
    existing_snap_dst=$(ssh root@$host_dst "zfs list -t snap -o name -H | grep $zfs_root_dst$jail_name | tail -n 1")

    # We create a snapshot and send it to destination
    if [ -n "$existing_snap_dst" ]; then
       existing_snap_src=$(zfs list -t snap -o name -s creation -H | grep $zfs_root_src$jail_name | tail -n 2 | head -n 1)
       if [ -n "$existing_snap_src" ]; then
           echo "send incremental snapshot $existing_snap_src with $zfs_root_src$jail_name@$snap_date to $host_dst in $zfs_root_dst$jail_name"
           zfs send -v -i $existing_snap_src $zfs_root_src$jail_name@$snap_date | ssh root@$host_dst zfs receive -v -F $zfs_root_dst$jail_name || { echo "Failed to send $zfs_root_src$jail_name to $host_dst in $zfs_root_dst$jail_name"; exit 1;}
       else
           echo "ERROR; we have a snapshot on $host_dst, but not here"
           echo "Snapshot at destination: $existing_snap_dst"
           echo "please solve this situation"
           exit 1
       fi
    else
       echo "send the snapshot $zfs_root_src$jail_name@$snap_date to $host_dst in $zfs_root_dst$jail_name"
       zfs send -v $zfs_root_src$jail_name@$snap_date | ssh root@$host_dst zfs receive -v -F $zfs_root_dst$jail_name || { echo "Failed to send $zfs_root_src$jail_name to $host_dst in $zfs_root_dst$jail_name"; exit 1;}
    fi
    
