Jump to content

SQLite partial backup - how to copy db schema


Iczer
 Share

Recommended Posts

I need to make partial backup of sqlite db, but to do it db/table schema is needed. To create universal function, I cannot reuse db creation query. So how I can get it from main db?

$sQuery = "CREATE TABLE IF NOT EXISTS SRDB " & $sSqlBuild_Table & ";"

Or maybe there a another method to do partial backup?

Link to comment
Share on other sites

select * from sqlite_master returns all the DDL statements you need.

You may need to first extract the rows having type = 'table', then 'index' then 'trigger' then 'view', then ...
After that you may have to reorder CREATE TABLE statements so that foreign keys work in the correct order.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Why would you want to make a partial backup? :)

And of WHAT exactly would this be a partial backup? Of all the data in certain tables, or of only data inserted during the current session?

Alternatively to the backup, make a full copy and delete what you don't need?

... ? 

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

Making first a backup of a 7.8Tb DB then dropping 7.725Tb of unneeded data in the copy, then performing a vacuum is pretty inefficient.

It's possible to get and filter DDL statements from the source DB as shown above and create only the tables/indices/triggers/views needed in the copy, then copy corresponding rows. In this case, one can use regular open of source and ATTACH the target, name it tgt for instance. Then insert into tgt.table_A select * from table_A; will do. Repeat and rince for all wanted tables.

Otherwise several third-party SQLite DB managers allow copying tables from one DB to another one. I personnally use SQLite Expert Pro (payware) whenever I need to perform such task. All required accompanying DDL statements (tables, indices and triggers) are automagically managed.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...