When property liable to an execution against several persons is sold thereon, and more than a due proportion of the judgment is levied upon the property of one of them, or one of them pays without a sale more than his proportion, he may compel contribution from the others. When a judgment is against several, and is upon an obligation or contract of one of them as security for another, and the surety pays the amount, or any part thereof, either by sale of his property or before sale, he may compel repayment from the principal. In such cases the person so paying or contributing shall be entitled to the benefit of the judgment to enforce contribution or repayment, if within thirty days after his payment he files with the clerk of the court where the judgment was rendered notice of his payment and claim to contribution or repayment; upon filing such notice the clerk shall make an entry thereof in the margin of the docket where the judgment is entered.