A backup object encapsulates copying one database to another. You
Connection.backup() on the destination database to get the
backup object. Call
step() to copy some pages
repeatedly dealing with errors as appropriate. Finally
finish() cleans up committing or rolling back and
Here is an example usage using the with statement to ensure
finish() is called:
# copies source.main into db with db.backup("main", source, "main") as b: while not b.done: b.step(100) print b.remaining, b.pagecount, "\r",
If you are not using with then you’ll need to ensure
finish() is called:
# copies source.main into db b=db.backup("main", source, "main") try: while not b.done: b.step(100) print b.remaining, b.pagecount, "\r", finally: b.finish()
The database is copied page by page. This means that there is not a round trip via SQL. All pages are copied including free ones.
The destination database is locked during the copy. You will get a
ThreadingViolationError if you attempt to use it.
__enter__() → self¶
__exit__() → False¶
Does the same thing as
finish(). This extra api is provided to give the same api as other APSW objects such as
Cursor.close(). It is safe to call this method multiple times.
force – If true then any exceptions are ignored.
Completes the copy process. If all pages have been copied then the transaction is committed on the destination database, otherwise it is rolled back. This method must be called for your backup to take effect. The backup object will always be finished even if there is an exception. It is safe to call this method multiple times.
step([npages=All]) → bool¶
Copies npages pages from the source to destination database. The source database is locked during the copy so using smaller values allows other access to the source database. The destination database is always locked until the backup object is
npages – How many pages to copy. If the parameter is omitted or negative then all remaining pages are copied. The default page size is 1024 bytes (1kb) which can be changed before database creation using a pragma.
True if this copied the last remaining outstanding pages, else false. This is the same value as