aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/sqlite.cpp
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2020-05-26 20:53:48 -0400
committerAndrew Chow <achow101-github@achow101.com>2020-10-14 11:28:18 -0400
commitac5c1617e7f4273daf24c24da1f6bc5ef5ab2d2b (patch)
treeb4dbcde20f00fb7731cdfe54578f2566552cfe64 /src/wallet/sqlite.cpp
parentf6f9cd6a64842ef23777312f2465e826ca04b886 (diff)
downloadbitcoin-ac5c1617e7f4273daf24c24da1f6bc5ef5ab2d2b.tar.xz
Implement SQLiteDatabase::Backup
Diffstat (limited to 'src/wallet/sqlite.cpp')
-rw-r--r--src/wallet/sqlite.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/wallet/sqlite.cpp b/src/wallet/sqlite.cpp
index d684eef87e..8ad82743ab 100644
--- a/src/wallet/sqlite.cpp
+++ b/src/wallet/sqlite.cpp
@@ -186,7 +186,29 @@ bool SQLiteDatabase::Rewrite(const char* skip)
bool SQLiteDatabase::Backup(const std::string& dest) const
{
- return false;
+ sqlite3* db_copy;
+ int res = sqlite3_open(dest.c_str(), &db_copy);
+ if (res != SQLITE_OK) {
+ sqlite3_close(db_copy);
+ return false;
+ }
+ sqlite3_backup* backup = sqlite3_backup_init(db_copy, "main", m_db, "main");
+ if (!backup) {
+ LogPrintf("%s: Unable to begin backup: %s\n", __func__, sqlite3_errmsg(m_db));
+ sqlite3_close(db_copy);
+ return false;
+ }
+ // Specifying -1 will copy all of the pages
+ res = sqlite3_backup_step(backup, -1);
+ if (res != SQLITE_DONE) {
+ LogPrintf("%s: Unable to backup: %s\n", __func__, sqlite3_errstr(res));
+ sqlite3_backup_finish(backup);
+ sqlite3_close(db_copy);
+ return false;
+ }
+ res = sqlite3_backup_finish(backup);
+ sqlite3_close(db_copy);
+ return res == SQLITE_OK;
}
void SQLiteDatabase::Close()