On Tue, 2005-09-06 at 11:09 -0400, John Duprey wrote: > I'd like to copy a database that may or may not be in use. Doing a > filesystem copy will not ensure a stable copy. Can I use the sqlite3 CLI and > some SQL to do this such that I can wrap it up into a script or do I need to > write my own program, that gets a lock and re-creates the DB in a new file? > I'd like to avoid dumping the database and importing it into a new. My DB is > 400M and growing so I'd like to avoid dumping such a large amount of data. > What I'd like is a safe binary copy. >
I suggest this approach: 1. Open the database file using sqlite3_open() 2. Run sqlite3_exec("BEGIN IMMEDIATE"); 3. Make a copy of the raw database file using whatever high-speed file copy mechanism is at hand. 4. sqlite3_close(); The BEGIN IMMEDIATE operation in step 2 will acquire a read-lock on the database file which will insure that no other process modifies the file during step 3. But it is also only a read-lock so other processes can continue to read the database while you are copying it. Step 4 releases the file lock. -- D. Richard Hipp <[EMAIL PROTECTED]>