Import-export Bamboo (Bitbucket) 6.0.0 build 60001 => 6.6.0 build 60604
Asked by Dmitry Martynkin:

Hello, I am trying migrating Bamboo server to a new VM.

I have original server running: Bamboo 6.0.0 build 60001 - 24 Apr 17  
New server running: 6.6.0 build 60604 - 25 Jun 18

During import of Bamboo backup created on server 6.0.0 build 60001 onto 6.6.0 build 60604 I get:

|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Import failed. Please contact Atlassian at <https://support.atlassian.com/> and attach your export file. \<br /\> java.lang.RuntimeException: Unexpected exception \<a lot of logs ommited\> Caused by: java.sql.BatchUpdateException: Violation of UNIQUE KEY constraint 'ASSIGNMENT_UNIQUE'. Cannot insert duplicate key in object 'dbo.AGENT_ASSIGNMENT'. The duplicate key value is (62619649, AGENT, 55934980, PROJECT). at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeBatch(SQLServerPreparedStatement.java:1824) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:2544) at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.performExecution(BatchingBatch.java:111) Prior to this I tried doing the following: ``` alter table dbo.AGENT_ASSIGNMENT drop constraint ASSIGNMENT_UNIQUE; ``` |


Answers:
author: Daniel Santos
body: Hi [@Dmitry Martynkin](/t5/user/viewprofilepage/user-id/1026612)

In version 6.0.0 we didn't have the following constraint:

```
CONSTRAINT ASSIGNMENT_UNIQUE UNIQUE (EXECUTOR_ID,
                                     EXECUTOR_TYPE,
                                     EXECUTABLE_ID,
                                     EXECUTABLE_TYPE)
```

It means that in the past we could have multiple rows with the same information and now this is prevented by the constraint as you already noticed.

**Possible reasons for this problem**

* **Case 1:**DB was copied multiple times creating the duplicates. Some times this happens when attempting multiple upgrades.
* **Case 2:**Corruption in the old DB.

**How to move forward**

* **Case 1:**Make sure you have a totally clean copy of your old DB when attempting the upgrade.
* ****Case 2:****You need to fix the duplicates. At least for this table, there is no harm on removing the rows that have the same combination of EXECUTOR_ID, EXECUTOR_TYPE, EXECUTABLE_ID, EXECUTABLE_TYPE.

comments: author: Dmitry Martynkin
body: Thank you for suggestions [@Daniel Santos](/t5/user/viewprofilepage/user-id/502125)

For the Case 2 I do not see any records in the table:

/\*\*\*\*\*\* Script for SelectTopNRows command from SSMS \*\*\*\*\*\*/  
SELECT TOP (1000) \[ASSIGNMENT_ID\]  
,\[EXECUTOR_ID\]  
,\[EXECUTOR_TYPE\]  
,\[EXECUTABLE_ID\]  
,\[EXECUTABLE_TYPE\]  
FROM \[bamboodb\].\[dbo\].\[AGENT_ASSIGNMENT\]

For the Case 1, could you please elaborate? I do not understand "clean copy of your old DB". I have a clean installation of 6.6.0 build 60604 with no plans or anything. Then I import backup from old server through Bamboo Administration page. I do not restore old server's DB onto new DB server. My understanding is that that "clean" DB will be populated with data from backup archive file during import.


author: Daniel Santos
body: > For the Case 2 I do not see any records in the table:

Is it possible that you don't have them now but had them at the moment of your Backup?

It is really strange that Bambo is facing issues with duplicates if there is no data in this table... it could be a strange bug.
> I have a clean installation of 6.6.0 build 60604 with no plans or anything. Then I import backup from old server through Bamboo Administration page. I do not restore old server's DB onto new DB server. My understanding is that that "clean" DB will be populated with data from backup archive file during import.

I got it, I thought you were using a different upgrade method, replicating the DB and using the copy to upgrade. In this process, you could have added upgrades, but I see this is not the case.

Can you try a new backup to check if this one will still have the same issue?

If it does, I'm afraid we will need to create a support ticket to analyze your data more closely and even replicate the issue.


Tags: bitbucket