用法:
backup(target, *, pages=- 1, progress=None, name='main', sleep=0.25)
此方法對 SQLite 數據庫進行備份,即使它正在被其他客戶端訪問,或者同時被同一連接訪問。副本將被寫入強製參數
target
,該參數必須是另一個Connection
實例。默認情況下,或者當
pages
為0
或負整數時,一步複製整個數據庫;否則,該方法一次執行最多pages
頁的循環複製。如果指定了
progress
,則它必須是None
,或者是一個可調用對象,在每次迭代時將使用三個整數參數執行,分別是最後一次迭代的status
,仍待處理的頁數remaining
複製和total
頁數。name
參數指定將被複製的數據庫名稱:它必須是包含默認值"main"
的字符串,以指示主數據庫;"temp"
表示臨時數據庫;或在附加數據庫的ATTACH DATABASE
語句中的AS
關鍵字之後指定的名稱。sleep
參數指定在連續嘗試備份剩餘頁麵之間休眠的秒數,可以指定為整數或浮點值。示例 1,將現有數據庫複製到另一個:
import sqlite3 def progress(status, remaining, total): print(f'Copied {total-remaining} of {total} pages...') con = sqlite3.connect('existing_db.db') bck = sqlite3.connect('backup.db') with bck: con.backup(bck, pages=1, progress=progress) bck.close() con.close()
示例 2,將現有數據庫複製到臨時副本中:
import sqlite3 source = sqlite3.connect('existing_db.db') dest = sqlite3.connect(':memory:') source.backup(dest)
3.7 版中的新函數。
相關用法
- Python sqlite3.Connection.text_factory用法及代碼示例
- Python sqlite3.Connection.enable_load_extension用法及代碼示例
- Python sqlite3.Connection.iterdump用法及代碼示例
- Python sqlite3.Connection.create_collation用法及代碼示例
- Python sqlite3.Connection.row_factory用法及代碼示例
- Python sqlite3.Connection.create_function用法及代碼示例
- Python sqlite3.Connection.create_aggregate用法及代碼示例
- Python sqlite3.Cursor.executescript用法及代碼示例
- Python sqlite3.Cursor.connection用法及代碼示例
- Python sqlite3.Cursor.executemany用法及代碼示例
- Python sqlite3.threadsafety用法及代碼示例
- Python sqlite3.complete_statement用法及代碼示例
- Python sqlite3.connect用法及代碼示例
- Python math sqrt()用法及代碼示例
- Python sklearn.cluster.MiniBatchKMeans用法及代碼示例
- Python scipy.ndimage.binary_opening用法及代碼示例
- Python scipy.signal.windows.tukey用法及代碼示例
- Python scipy.stats.mood用法及代碼示例
- Python str.isidentifier用法及代碼示例
- Python sklearn.metrics.fbeta_score用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 sqlite3.Connection.backup。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。