On the amplification of magnetic fields in cosmic filaments and galaxy clusters