# Running a backup while Continua CI is running

**URL:** https://www.finalbuilder.com/forums/t/running-a-backup-while-continua-ci-is-running/5651
**Category:** Discussion
**Created:** [December 23, 2016, 12:50pm UTC](https://www.finalbuilder.com/forums/t/running-a-backup-while-continua-ci-is-running/5651 "2016-12-23T12:50:04Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![philippe.mosberger](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@philippe.mosberger](https://www.finalbuilder.com/forums/u/philippe.mosberger)
#### Post date: [December 23, 2016, 12:50pm UTC](https://www.finalbuilder.com/forums/t/running-a-backup-while-continua-ci-is-running/5651/1 "2016-12-23T12:50:04Z")

</div>

Dear Sir/Madam  
  
We are running a daily database backup&nbsp;on our Continua CI database&nbsp;by issuing the following command: pg\_dump.exe -h localhost -p 9001 -U postgres -F p -f C:\continua\_backup.bak ContinuaCI  
[http://wiki.finalbuilder.com/displa…a+database](http://wiki.finalbuilder.com/display/continua/Backing+up+the+Continua+database)  
  
Sometimes the backup fails and sometimes the database is corrupted. We are wondering if it is save to dump the database while the Continua Service is running?  
  
Best regards,  
Philippe

---

<div class="post-metadata">

### Author: ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)
#### Post date: [January 2, 2017, 11:26am UTC](https://www.finalbuilder.com/forums/t/running-a-backup-while-continua-ci-is-running/5651/2 "2017-01-02T11:26:08Z")

</div>

Hi Phillipe,  
  
Yes, it is safe to run the backup while the Continua CI and the PostgreSQL database service are running. See [postgresql - Does running pg\_dump on live db produce consistent backups?](http://dba.stackexchange.com/questions/13742/does-running-pg-dump-on-live-db-produce-consistent-backups.)&nbsp;  
  
If you write the output of each backup to a file using _\> outfile_ then you should see error messages giving the reason for the failure.

---

<div class="post-metadata">

### Author: ![philippe.mosberger](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@philippe.mosberger](https://www.finalbuilder.com/forums/u/philippe.mosberger)
#### Post date: [January 9, 2017, 8:35am UTC](https://www.finalbuilder.com/forums/t/running-a-backup-while-continua-ci-is-running/5651/3 "2017-01-09T08:35:25Z")

</div>

Hi Dave   
  
 Over the weekend the daily backup failed again. When executing: pg\_dump.exe -h localhost -p 9001 -U postgres -F p -f C:\continua\_backup.bak ContinuaCI we encountered following error:   
  
 pg\_dump: Dumping the contents of table “builds\_repositorydata” failed: PQgetResult() failed.   
 pg\_dump: Error message from server: ERROR: missing chunk number 0 for toast value 5842186 in pg\_toast\_3595984   
 pg\_dump: The command was: COPY public.builds\_repositorydata (id, plugin, latestcachedupdate, lastchecked, lastchangesetdatetime, lastchangesetid, repositorystate, lastchangesetrevision, lastchangesetb   
 ranch) TO stdout;   
  
 Do you have any explanation?   
  
 Best regards,   
 Philippe

---

<div class="post-metadata">

### Author: ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)
#### Post date: [January 10, 2017, 2:10am UTC](https://www.finalbuilder.com/forums/t/running-a-backup-while-continua-ci-is-running/5651/4 "2017-01-10T02:10:38Z")

</div>

Hi Phillipe,  
  
There is a corrupt record in the public.builds\_repositorydata table. This could have happened due to an immediate service shutdown e.g. a server crash or powercut, or could be related to an issue with disk or memory.&nbsp;  
  
If your previous backup is up-to-date than you can restore that and get back up an running.&nbsp;  
  
Otherwise, to fix this issue you will need to run some SQL commands.   
  
First shutdown the Continua CI Server service as you will be making updates to the database. Then run the pgAdmin3.exe tool, which is in the %PROGRAM\_FILES%\VSoft Technologies\ContinuaCI\Server\PostgreSQL\bin folder.&nbsp;You can find the database connection details in %PROGRAM\_FILES%\VSoft Technologies\ContinuaCI\Server\Continua.Server.Service.exe.config under hibernate-configuration -\> session-factory -\> property name=“connection.connection\_string”.  
  
Once you are connected, select the Continua database in the Object browser, then choose the Query Tool from the Tools menu.&nbsp;  
  
Run the following command:

`REINDEX ``table` `pg_toast.pg_toast_359584;`

`REINDEX ``table` `public``.builds_repositorydata;`

  
then run the following command:  
  

`VACUUM ANALYZE ``public``.builds_repositorydata;`

  
Next run&nbsp;  
  

`SELECT` `* ``FROM` `public``.builds_repositorydata;`

  
If the error is still reported we will need to find the corrupted record.  
  
Run the following command to get the number of records in the table:  
  

`SELECT` `COUNT``() ``FROM` `public``.builds_repositorydata;`

  
Then use a binary search with the following command to narrow down to the corrupted record:  
  

`SELECT` ` ``FROM` `public``.builds_repositorydata LIMIT N1 OFFSET N2;`

  
[This blog post](https://sysblog.blogs.ilrt.org/2009/09/24/fixing-corrupted-data-in-postgresql-databases/) describes how to do this. &nbsp;  
  
Once you have found the affected row and field, note down the id of the row (which we will refer to as N) and check the corresponding row of the public.builds\_repository table.&nbsp;  
  

`SELECT` `* ``FROM` `public``.builds_repository ``WHERE` `repodataid = N;`

  
This will allow you to determine whether this is an important repository. If the Archived flag is set the true (t) then the data in the corrupted field can be safely discarded. You can run relevant update statement below to reset the field e.g.  
  

`UPDATE` `public``.builds_repositorydata ``SET` `latestcachedupdate = ``‘2017-01-10 00:00:00’` `WHERE` `Id = N;`

`UPDATE` `public``.builds_repositorydata ``SET` `lastchecked = ``‘2017-01-10 00:00:00’` `WHERE` `Id = N;`

`UPDATE` `public``.builds_repositorydata ``SET` `lastchangesetdatetime = ``NULL` `WHERE` `Id = N;`

`UPDATE` `public``.builds_repositorydata ``SET` `lastchangesetid = -1 ``WHERE` `Id = N;`

`UPDATE` `public``.builds_repositorydata ``SET` `repositorystate = ``‘{}’` `WHERE` `Id = N;`

`UPDATE` `public``.builds_repositorydata ``SET` `lastchangesetrevision = ``NULL` `WHERE` `Id = N;`

`UPDATE` `public``.builds_repositorydata ``SET` `lastchangesetbranch = ``NULL` `WHERE` `Id = N;`

`UPDATE` `public``.builds_repositorydata ``SET` `plugin = ``null` `WHERE` `Id = N;`

  
If the repository is not archived then it will be OK to reset all fields except for the plugin field. You will just need to reset the repository in the Administration section of Continua CI after starting up the service.   
If you need to reset the plugin field then the repository data is lost and you will need to archive the repository using the following command and then recreate it manually in Continua CI.  
  

`UPDATE` `public``.builds_repository ``SET` `archived = ``true` `WHERE` `repodataid = N`

  

Please let us know how you get on with this.

---

<div class="post-metadata">

### Author: ![philippe.mosberger](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@philippe.mosberger](https://www.finalbuilder.com/forums/u/philippe.mosberger)
#### Post date: [January 11, 2017, 11:00am UTC](https://www.finalbuilder.com/forums/t/running-a-backup-while-continua-ci-is-running/5651/5 "2017-01-11T11:00:57Z")

</div>

Hi Dave   
  
 I have narrowed down the corrupted field and updated/reset it. If everything is fine is not yet clear however the original error is resolved, I can run now pg\_dump again. However I am puzzled why there has been a db-error at the first place.   
  
 Best regards,   
 Philippe

---

<div class="post-metadata">

### Author: ![philippe.mosberger](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@philippe.mosberger](https://www.finalbuilder.com/forums/u/philippe.mosberger)
#### Post date: [January 11, 2017, 2:10am UTC](https://www.finalbuilder.com/forums/t/running-a-backup-while-continua-ci-is-running/5651/6 "2017-01-11T02:10:30Z")

</div>

Hi Dave   
  
 As mentioned in my previous post db-dump worked however db-restore now failed. There was some error message about double entries.   
  
 I removed all double entries in the public.builds\_repositorydata and retried it. At the moment it seems to work.   
  
 BR Philippe

---

<div class="post-metadata">

### Author: ![philippe.mosberger](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@philippe.mosberger](https://www.finalbuilder.com/forums/u/philippe.mosberger)
#### Post date: [January 16, 2017, 9:50am UTC](https://www.finalbuilder.com/forums/t/running-a-backup-while-continua-ci-is-running/5651/7 "2017-01-16T09:50:20Z")

</div>

Hi Dave   
  
 Again we have issues with the database:   
  
 [code]Message: More than one row with the given identifier was found: 31, for class: Continua.Modules.Builds.Repositories.RepositoryData[/code]   
  
 Every time the error is somehow related to double entries in the RepositoryData database.   
  
 I would like to send you the screenshot, database export and event log. Can you please let me know an e-mail where I can send the confidential data to?   
  
 Best regards,   
 Philippe

---

<div class="post-metadata">

### Author: ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)
#### Post date: [January 17, 2017, 12:03pm UTC](https://www.finalbuilder.com/forums/t/running-a-backup-while-continua-ci-is-running/5651/8 "2017-01-17T12:03:20Z")

</div>

Hi Philippe,  
  
If you send these to [support@finalbuilder.com](mailto:support@finalbuilder.com), it will go directly to me. If the files are large then you can also request ftp upload details via this email address.
