"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Tardis/TardisDB.py" between
Tardis-1.1.5.tar.gz and Tardis-1.2.1.tar.gz

About: Tardis is a system for making encrypted, incremental backups of filesystems.

TardisDB.py  (Tardis-1.1.5):TardisDB.py  (Tardis-1.2.1)
skipping to change at line 41 skipping to change at line 41
import sqlite3 import sqlite3
import logging import logging
import os import os
import os.path import os.path
import time import time
import sys import sys
import uuid import uuid
import srp import srp
import functools import functools
import importlib import importlib
import gzip
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
import Tardis import Tardis
import Tardis.ConnIdLogAdapter as ConnIdLogAdapter import Tardis.ConnIdLogAdapter as ConnIdLogAdapter
import Tardis.Rotator as Rotator import Tardis.Rotator as Rotator
# Exception classes # Exception classes
class AuthenticationException(Exception): class AuthenticationException(Exception):
pass pass
skipping to change at line 68 skipping to change at line 69
# Utility functions # Utility functions
def authenticate(func): def authenticate(func):
@functools.wraps(func) @functools.wraps(func)
def doit(self, *args, **kwargs): def doit(self, *args, **kwargs):
if self._isAuthenticated(): if self._isAuthenticated():
return func(self, *args, **kwargs) return func(self, *args, **kwargs)
else: else:
raise NotAuthenticated("Not authenticated to database.") raise NotAuthenticated("Not authenticated to database.")
return doit return doit
# Be sure to end all these lists with a space.
_fileInfoFields = "Name AS name, Inode AS inode, Device AS device, Dir AS dir, Link AS link, " \ _fileInfoFields = "Name AS name, Inode AS inode, Device AS device, Dir AS dir, Link AS link, " \
"Parent AS parent, ParentDev AS parentdev, C1.Size AS size, " \ "Parent AS parent, ParentDev AS parentdev, C1.Size AS size, " \
"MTime AS mtime, CTime AS ctime, ATime AS atime, Mode AS mode , UID AS uid, GID AS gid, NLinks AS nlinks, " \ "MTime AS mtime, CTime AS ctime, ATime AS atime, Mode AS mode , UID AS uid, GID AS gid, NLinks AS nlinks, " \
"FirstSet AS firstset, LastSet AS lastset, C1.Checksum AS che cksum, C1.ChainLength AS chainlength, " \ "FirstSet AS firstset, LastSet AS lastset, C1.Checksum AS che cksum, C1.ChainLength AS chainlength, " \
"C2.Checksum AS xattrs, C3.Checksum AS acl " "C2.Checksum AS xattrs, C3.Checksum AS acl "
_fileInfoJoin = "FROM Files " \ _fileInfoJoin = "FROM Files " \
"JOIN Names ON Files.NameId = Names.NameId " \ "JOIN Names ON Files.NameId = Names.NameId " \
"LEFT OUTER JOIN Checksums AS C1 ON Files.ChecksumId = C1.Che cksumId " \ "LEFT OUTER JOIN Checksums AS C1 ON Files.ChecksumId = C1.Che cksumId " \
"LEFT OUTER JOIN Checksums AS C2 ON Files.XattrId = C2.Checks umId " \ "LEFT OUTER JOIN Checksums AS C2 ON Files.XattrId = C2.Checks umId " \
"LEFT OUTER JOIN Checksums AS C3 ON Files.AclId = C3.Checksum Id " "LEFT OUTER JOIN Checksums AS C3 ON Files.AclId = C3.Checksum Id "
_backupSetInfoFields = "BackupSet AS backupset, StartTime AS starttime, EndTime AS endtime, ClientTime AS clienttime, " \ _backupSetInfoFields = "BackupSet AS backupset, StartTime AS starttime, EndTime AS endtime, ClientTime AS clienttime, " \
"Priority AS priority, Completed AS completed, Session AS session, Name AS name, " \ "Priority AS priority, Completed AS completed, Session AS session, Name AS name, " \
"ClientVersion AS clientversion, ClientIP AS clientip, Se rverVersion AS serverversion, Full AS full, " \ "ClientVersion AS clientversion, ClientIP AS clientip, Se rverVersion AS serverversion, Full AS full, " \
"FilesFull AS filesfull, FilesDelta AS filesdelta, BytesR "FilesFull AS filesfull, FilesDelta AS filesdelta, BytesR
eceived AS bytesreceived, Checksum AS commandline " eceived AS bytesreceived, Checksum AS commandline, "\
"Exception AS exception, ErrorMsg AS errormsg "
_backupSetInfoJoin = "FROM Backups LEFT OUTER JOIN Checksums ON Checksums.Checks umID = Backups.CmdLineId " _backupSetInfoJoin = "FROM Backups LEFT OUTER JOIN Checksums ON Checksums.Checks umID = Backups.CmdLineId "
_checksumInfoFields = "Checksum AS checksum, ChecksumID AS checksumid, Basis AS basis, Encrypted AS encrypted, " \ _checksumInfoFields = "Checksum AS checksum, ChecksumID AS checksumid, Basis AS basis, Encrypted AS encrypted, " \
"Size AS size, DeltaSize AS deltasize, DiskSize AS disksiz e, IsFile AS isfile, Compressed AS compressed, ChainLength AS chainlength " "Size AS size, DeltaSize AS deltasize, DiskSize AS disksiz e, IsFile AS isfile, Compressed AS compressed, ChainLength AS chainlength "
_schemaVersion = 17 _schemaVersion = 18
def _addFields(x, y): def _addFields(x, y):
""" Add fields to the end of a dict """ """ Add fields to the end of a dict """
return dict(list(y.items()) + x) return dict(list(y.items()) + x)
def _splitpath(path): def _splitpath(path):
""" Split a path into chunks, recursively """ """ Split a path into chunks, recursively """
(head, tail) = os.path.split(path) (head, tail) = os.path.split(path)
return _splitpath(head) + [ tail ] if head and head != path else [ head or t ail ] return _splitpath(head) + [ tail ] if head and head != path else [ head or t ail ]
skipping to change at line 257 skipping to change at line 261
self.clientId = self.getConfigValue('ClientID') self.clientId = self.getConfigValue('ClientID')
self.logger.debug("Last Backup Set: %s %d ", self.prevBackupName, self.p revBackupSet) self.logger.debug("Last Backup Set: %s %d ", self.prevBackupName, self.p revBackupSet)
self.conn.commit() self.conn.commit()
self.conn.execute("PRAGMA synchronous=false") self.conn.execute("PRAGMA synchronous=false")
self.conn.execute("PRAGMA foreignkeys=true") self.conn.execute("PRAGMA foreignkeys=true")
if self.journalName: if self.journalName:
self.journal = open(self.journalName, 'a') if self.journalName.endswith('.gz'):
self.journal = gzip.open(self.journalName, 'at')
else:
self.journal = open(self.journalName, 'a')
# Make sure the permissions are set the way we want, if that's specified . # Make sure the permissions are set the way we want, if that's specified .
if self.user != -1 or self.group != -1: if self.user != -1 or self.group != -1:
os.chown(self.dbName, self.user, self.group) os.chown(self.dbName, self.user, self.group)
def _bset(self, current): def _bset(self, current):
""" Determine the backupset we're being asked about. """ Determine the backupset we're being asked about.
True == current, False = previous, otherwise a number is returned True == current, False = previous, otherwise a number is returned
""" """
if type(current) is bool: if type(current) is bool:
skipping to change at line 691 skipping to change at line 698
for f in files: for f in files:
c = self.cursor.execute("SELECT NameId FROM Names WHERE Name = :name ", f) c = self.cursor.execute("SELECT NameId FROM Names WHERE Name = :name ", f)
row = c.fetchone() row = c.fetchone()
if row: if row:
f["nameid"] = row[0] f["nameid"] = row[0]
else: else:
self.cursor.execute("INSERT INTO Names (Name) VALUES (:name)", f ) self.cursor.execute("INSERT INTO Names (Name) VALUES (:name)", f )
f["nameid"] = self.cursor.lastrowid f["nameid"] = self.cursor.lastrowid
@authenticate @authenticate
def insertChecksumFile(self, checksum, encrypted=False, size=0, basis=None, deltasize=None, compressed='None', disksize=None, current=True, isFile=True): def insertChecksum(self, checksum, encrypted=False, size=0, basis=None, delt asize=None, compressed='None', disksize=None, current=True, isFile=True):
self.logger.debug("Inserting checksum file: %s -- %d bytes, Compressed % s", checksum, size, str(compressed)) self.logger.debug("Inserting checksum file: %s -- %d bytes, Compressed % s", checksum, size, str(compressed))
added = self._bset(current) added = self._bset(current)
def _xstr(x): def _xstr(x):
return x if x is not None else '' return x if x is not None else ''
if self.journal: if self.journal:
self.journal.write("{}:{}:{}:{}\n".format(checksum, _xstr(basis), in t(encrypted), compressed)) self.journal.write("{}:{}:{}:{}\n".format(checksum, _xstr(basis), in t(encrypted), compressed))
if basis is None: if basis is None:
chainlength = 0 chainlength = 0
skipping to change at line 1024 skipping to change at line 1031
self.delConfigValue('FilenameKey') self.delConfigValue('FilenameKey')
if contentKey: if contentKey:
self.setConfigValue('ContentKey', contentKey) self.setConfigValue('ContentKey', contentKey)
else: else:
self.delConfigValue('ContentKey') self.delConfigValue('ContentKey')
if backup: if backup:
# Attempt to save the keys away # Attempt to save the keys away
backupName = self.dbName + ".keys" backupName = self.dbName + ".keys"
r = Rotator.Rotator(rotations=0) r = Rotator.Rotator(rotations=0)
r.backup(backupName) r.backup(backupName)
Util.saveKeys(backupName, self.clientId, filenameKey, contentKey ) Util.saveKeys(backupName, self.clientId, filenameKey, contentKey , salt, vkey)
self.commit() self.commit()
if backup: if backup:
r.rotate(backupName) r.rotate(backupName)
return True return True
except Exception as e: except Exception as e:
self.logger.error("Setkeys failed: %s", e) self.logger.error("Setkeys failed: %s", e)
self.logger.exception(e) self.logger.exception(e)
return False return False
@authenticate @authenticate
skipping to change at line 1181 skipping to change at line 1188
@authenticate @authenticate
def commit(self): def commit(self):
self.conn.commit() self.conn.commit()
@authenticate @authenticate
def setClientEndTime(self): def setClientEndTime(self):
if self.currBackupSet: if self.currBackupSet:
self.conn.execute("UPDATE Backups SET ClientEndTime = :now WHERE Bac kupSet = :backup", self.conn.execute("UPDATE Backups SET ClientEndTime = :now WHERE Bac kupSet = :backup",
{ "now": time.time(), "backup": self.currBackupSet }) { "now": time.time(), "backup": self.currBackupSet })
@authenticate
def setFailure(self, ex):
if self.currBackupSet:
self.conn.execute("UPDATE Backups SET Exception = :ex, ErrorMsg = :m
sg WHERE BackupSet = :backup",
{ "ex": type(ex).__name__, "msg": str(ex), "backup
": self.currBackupSet})
def close(self, completeBackup=False): def close(self, completeBackup=False):
#self.logger.debug("Closing DB: %s", self.dbName) #self.logger.debug("Closing DB: %s", self.dbName)
# Apparently logger will get shut down if we're executing in __del__, so leave the debugging message out # Apparently logger will get shut down if we're executing in __del__, so leave the debugging message out
if self.currBackupSet: if self.currBackupSet:
self.conn.execute("UPDATE Backups SET EndTime = :now WHERE BackupSet = :backup", self.conn.execute("UPDATE Backups SET EndTime = :now WHERE BackupSet = :backup",
{ "now": time.time(), "backup": self.currBackupSet }) { "now": time.time(), "backup": self.currBackupSet })
self.conn.commit() self.conn.commit()
self.conn.close() self.conn.close()
self.conn = None self.conn = None
 End of changes. 8 change blocks. 
6 lines changed or deleted 21 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)