We have a content database on our live moss server. It contains one site collection with several sub-sites. I'm using the stsadm export command to produce a cmp file, then moving this to our test server in a different farm.
I then want to import this content into the content database on our test farm, using the import stsadm command results in me being left with all the existing test data as well as the live data. I tried detaching the existing content database from test in central admin and creating a new empty one,to the then run the import against that but the import failed as obviously there's not root site in the empty db.
Can anyone suggest a good approach to this type of problem?
I would either backup the whole site collection (backup/restore) and use the overwrite switch, or if you must you export/import, delete the test site and then create a new blank site. Then you can import your data into the blank site and there shouldn't be any problems.
Probably all your missing here is the awareness that STSADM -o import needs an existing site collection to import to. Likewise if you were importing a list (not possible with STSADM, but is with the underlying API) it needs the parent web present to import into.
If you don't want the imported data to sit alongside test data, you either need to delete and recreate the site collection, or else leave the original and create a new separate site collection to import into.
There's no specific need to create a new content database unless you wish to for other reasons.
One of the easist ways for moving site collections between environments, especially if they are in a dedicated content DB, is by copying the DB between the production and test SQL servers.
This assumes you have access to the Database servers for both environments. I found this is often quicker and easier than export/import but it is an all or nothing strategy. As long as you are happy to move the entire site collection from production to test then it will work and the following TechNet article outlines the process: