mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
prefer native sqlite3 backup (journal-aware)
This commit is contained in:
parent
03efc6a169
commit
1359213196
|
@ -929,19 +929,38 @@ class Up2k(object):
|
|||
m = "database is version {}, this copyparty only supports versions <= {}"
|
||||
raise Exception(m.format(ver, DB_VER))
|
||||
|
||||
bak = "{}.bak.{:x}.v{}".format(db_path, int(time.time()), ver)
|
||||
db = cur.connection
|
||||
cur.close()
|
||||
db.close()
|
||||
msg = "creating new DB (old is bad); backup: {}"
|
||||
if ver:
|
||||
msg = "creating new DB (too old to upgrade); backup: {}"
|
||||
|
||||
self.log(msg.format(bak))
|
||||
os.rename(fsenc(db_path), fsenc(bak))
|
||||
|
||||
cur = self._backup_db(db_path, cur, ver, msg)
|
||||
db = cur.connection
|
||||
cur.close()
|
||||
db.close()
|
||||
os.unlink(db_path)
|
||||
return self._create_db(db_path, None)
|
||||
|
||||
def _backup_db(self, db_path, cur, ver, msg):
|
||||
bak = "{}.bak.{:x}.v{}".format(db_path, int(time.time()), ver)
|
||||
self.log(msg + bak)
|
||||
try:
|
||||
c2 = sqlite3.connect(bak)
|
||||
with c2:
|
||||
cur.connection.backup(c2)
|
||||
return cur
|
||||
except:
|
||||
m = "native sqlite3 backup failed; using fallback method:\n"
|
||||
self.log(m + min_ex())
|
||||
finally:
|
||||
c2.close()
|
||||
|
||||
db = cur.connection
|
||||
cur.close()
|
||||
db.close()
|
||||
|
||||
shutil.copy2(fsenc(db_path), fsenc(bak))
|
||||
return self._orz(db_path)
|
||||
|
||||
def _read_ver(self, cur):
|
||||
for tab in ["ki", "kv"]:
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue