How do I repair a corrupt database?

2Do uses the industry standard, SQLite embedded database to store your data. SQLite is lightweight, fast and can perform automatic recovery of failed or incomplete transactions under normal circumstances. In the rare event of a power-failure, sudden reboot or some other hardware related failure whilst in the middle of performing background sync, there is a slim chance of the database becoming corrupt, such that automatic recovery is no longer possible. This is more likely to occur on a Desktop / Laptop rather than an iPhone / Tablet. For phones and tablets, the easiest method of recovery, provided you have synced your data to the cloud, is to Reset your database from Settings > Advanced and setup sync to recover directly from the cloud.

Signs of a corrupt database are usually: search not working, sync not working or tasks not saving / deleting properly. Recovering from database failure is straightforward, albeit a manual process. The following instructions will help you self-diagnose a corrupt database and help you recover and repair your valued data. It should be noted here that 2Do creates automatic backups on a timely fashion (accessible from inside Preferences > Backups) for safe-keeping, however the following steps are there to help in case there isn’t a more recent backup to recover from.

  1. Spotlight for Terminal.app and launch it on your Mac
  2. Navigate to the db storage location by entering: cd ~/Library/Group\ Containers/EKT6323JY3.com.guidedways/
  3. Enter the following command and hit return: sqlite3 2do.db

The prompt should now display sqlite> to indicate you’re in the SQLite shell. To verify that you’re truly suffering from database corruption, enter the following command into the shell:

sqlite> PRAGMA integrity_check;

If the response is anything other than ok, the database is integrity checks have failed and needs to be repaired.

We need to now dump the data into an external file and re-create the database manually. Simply enter the following commands into the SQLite shell:

  1. sqlite> .mode insert
  2. sqlite> .output dump_all.sql
  3. sqlite> .dump
  4. sqlite> .exit

Now that we have the dump, let’s import it. You should now be out of the SQLite shell and back to the Terminal prompt. Execute the following statements:

  1. mv 2do.db 2do.orig.db
  2. sqlite3 2do.db < dump_all.sql
  3. sqlite3 2do.db

The first line above will move the original database out of the way. The second line will create a new one in place, using the dump we just exported. The last line should take us back into the SQLite shell in order to check if everything’s okay. Run the integrity check one more time and we should see OK as the response this time:

sqlite3> PRAGMA integrity_check;

That’s it, you’re done repairing the database. Re-launch 2Do to get back to getting things done.
Attached Files
There are no attachments for this article.
Related Articles
How do I use the search feature to look for tags, actions, and other stuff?
Viewed 81,946.00 times since Fri, Apr 9, 2010
Pricing of 2Do on iOS and Mac
Viewed 33,714.00 times since Sat, Sep 20, 2014
Dropbox is showing me a 509 error during sync
Viewed 6,696.00 times since Mon, Sep 25, 2017
Where can I find help / manual for the Mac app?
Viewed 11,359.00 times since Sun, Oct 14, 2012
2Do won’t minimize from full screen mode on Yosemite
Viewed 6,529.00 times since Tue, Oct 21, 2014