If you post a code snippet, ALWAYS USE CODE TAGS:
How to use code tags: Using code tags properly
The steps to clone TerrainData is simply to Instantiate() a fresh copy of it and reassign it to your Terrain, and possibly your TerrainCollider if you want.
TerrainData terrainData = Instantiate<TerrainData>( terrain.terrainData);
// TODO: change your terrainData here...
terrain.terrainData = terrainData;
Here’s another example of manipulating TerrainData: