Extract the call "retry" from an outbound call

I posted this in the “General” category because this question can be used for more than just fax applications.

I would like to know if anyone knows how to extract the call retry from an outbound call so I can put it in my database?

fax02*CLI>
– Attempting call on PJSIP/15097900097@provider for fax_out@fax_context:1 (Retry 1)
– Called 15097900097@provider
– PJSIP/provider-0000024f is making progress
– PJSIP/provider-0000024f answered
– Executing [fax_out@fax_context:1] NoOp(“PJSIP/provider-0000024f”, " ** outbound fax ** ") in new stack

Here is my dialplan:
[fax_context]
exten => fax_out,1,NoOp( ** outbound fax ** )
same => n,Set(FAXFILE=${TIFF_FILE})
same => n,Set(FAXOPT(ecm)=yes)
same => n,Set(FAXOPT(maxrate)=14400)
same => n,Set(FAXOPT(minrate)=2400)
same => n,Set(S_CALLERID=${S_CALLERID})
same => n,Set(RetryNumber=${???})
same => n,SendFax(${FAXFILE},dfzs)

exten => h,1,AGI(write_log.sh,"${ACCOUNT}","${FILENAME}","${S_CALLERID}","${D_CALLERID}","${RetryNumber}","${FAXOPT(error)}","${FAXOPT(status)}")