It shall be the duty of such sheriff, on such surrender and the delivery to him of a certified copy of the recognizance by which such surety or sureties are bound, to take such person or persons so charged as aforesaid into custody, and by writing acknowledge such surrender, and thereupon the surety or sureties shall be discharged from any such recognizance, upon payment of all costs occasioned thereby.