Back to index

obnam  1.1
Public Member Functions | Public Attributes
obnamlib.plugins.verify_plugin.VerifyPlugin Class Reference
Inheritance diagram for obnamlib.plugins.verify_plugin.VerifyPlugin:
Inheritance graph
[legend]
Collaboration diagram for obnamlib.plugins.verify_plugin.VerifyPlugin:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def enable
def verify
def log_fail
def verify_metadata
def verify_regular_file
def verify_chunks
def walk

Public Attributes

 repo
 fs
 failed

Detailed Description

Definition at line 37 of file verify_plugin.py.


Member Function Documentation

Definition at line 39 of file verify_plugin.py.

00039 
00040     def enable(self):
00041         self.app.add_subcommand('verify', self.verify,
00042                                 arg_synopsis='[FILE]...')
00043         self.app.settings.integer(['verify-randomly'],
00044                                   'verify N files randomly from the backup '
00045                                     '(default is zero, meaning everything)',
00046                                   metavar='N')

Here is the call graph for this function:

Definition at line 132 of file verify_plugin.py.

00132 
00133     def log_fail(self, e):
00134         msg = 'verify failure: %s: %s' % (e.filename, e.reason)
00135         logging.error(msg)
00136         if self.app.settings['quiet']:
00137             sys.stderr.write('%s\n' % msg)
00138         else:
00139             self.app.ts.notify(msg)
00140         self.failed = True

Verify that live data and backed up data match.

Definition at line 47 of file verify_plugin.py.

00047 
00048     def verify(self, args):
00049         '''Verify that live data and backed up data match.'''
00050         self.app.settings.require('repository')
00051         self.app.settings.require('client-name')
00052         self.app.settings.require('generation')
00053 
00054         logging.debug('verifying generation %s' % 
00055                         self.app.settings['generation'])
00056         if not args:
00057             self.app.settings.require('root')
00058             args = self.app.settings['root']
00059         if not args:
00060             logging.debug('no roots/args given, so verifying everything')
00061             args = ['/']
00062         logging.debug('verifying what: %s' % repr(args))
00063 
00064         self.repo = self.app.open_repository()
00065         self.repo.open_client(self.app.settings['client-name'])
00066         self.fs = self.app.fsf.new(args[0])
00067         self.fs.connect()
00068         t = urlparse.urlparse(args[0])
00069         root_url = urlparse.urlunparse((t[0], t[1], '/', t[3], t[4], t[5]))
00070         logging.debug('t: %s' % repr(t))
00071         logging.debug('root_url: %s' % repr(root_url))
00072         self.fs.reinit(root_url)
00073 
00074         self.failed = False
00075         gen = self.repo.genspec(self.app.settings['generation'])
00076 
00077         self.app.ts['done'] = 0
00078         self.app.ts['total'] = 0
00079         self.app.ts['filename'] = ''
00080         if not self.app.settings['quiet']:
00081             self.app.ts.format(
00082                 'verifying file %Counter(filename)/%Integer(total) '
00083                 '%PercentDone(done,total): '
00084                 '%Pathname(filename)')
00085 
00086         num_randomly = self.app.settings['verify-randomly']
00087         if num_randomly == 0:
00088             self.app.ts['total'] = \
00089                 self.repo.client.get_generation_file_count(gen)
00090             for filename, metadata in self.walk(gen, args):
00091                 self.app.ts['filename'] = filename
00092                 try:
00093                     self.verify_metadata(gen, filename, metadata)
00094                 except Fail, e:
00095                     self.log_fail(e)
00096                 else:
00097                     if metadata.isfile():
00098                         try:
00099                             self.verify_regular_file(gen, filename, metadata)
00100                         except Fail, e:
00101                             self.log_fail(e)
00102                 self.app.ts['done'] += 1
00103         else:
00104             logging.debug('verifying %d files randomly' % num_randomly)
00105             self.app.ts['total'] = num_randomly
00106             self.app.ts.notify('finding all files to choose randomly')
00107             filenames = [filename
00108                          for filename, metadata in self.walk(gen, args)
00109                          if metadata.isfile()]
00110             chosen = []
00111             for i in range(min(num_randomly, len(filenames))):
00112                 filename = random.choice(filenames)
00113                 filenames.remove(filename)
00114                 chosen.append(filename)
00115             for filename in chosen:
00116                 self.app.ts['filename'] = filename
00117                 metadata = self.repo.get_metadata(gen, filename)
00118                 try:
00119                     self.verify_metadata(gen, filename, metadata)
00120                     self.verify_regular_file(gen, filename, metadata)            
00121                 except Fail, e:
00122                     self.log_fail(e)
00123                 self.app.ts['done'] += 1
00124 
00125         self.fs.close()
00126         self.repo.fs.close()
00127         self.app.ts.finish()
00128 
00129         if self.failed:
00130             sys.exit(1)
00131         print "Verify did not find problems."

Here is the caller graph for this function:

def obnamlib.plugins.verify_plugin.VerifyPlugin.verify_chunks (   self,
  f,
  chunkids 
)

Definition at line 163 of file verify_plugin.py.

00163 
00164     def verify_chunks(self, f, chunkids):
00165         for chunkid in chunkids:
00166             backed_up = self.repo.get_chunk(chunkid)
00167             live_data = f.read(len(backed_up))
00168             if backed_up != live_data:
00169                 return False
00170         return True

Here is the caller graph for this function:

def obnamlib.plugins.verify_plugin.VerifyPlugin.verify_metadata (   self,
  gen,
  filename,
  backed_up 
)

Definition at line 141 of file verify_plugin.py.

00141 
00142     def verify_metadata(self, gen, filename, backed_up):
00143         try:
00144             live_data = obnamlib.read_metadata(self.fs, filename)
00145         except OSError, e:
00146             raise Fail(filename, 'missing or inaccessible: %s' % e.strerror)
00147         for field in obnamlib.metadata_verify_fields:
00148             v1 = getattr(backed_up, field)
00149             v2 = getattr(live_data, field)
00150             if v1 != v2:
00151                 raise Fail(filename, 
00152                             'metadata change: %s (%s vs %s)' % (field, v1, v2))

def obnamlib.plugins.verify_plugin.VerifyPlugin.verify_regular_file (   self,
  gen,
  filename,
  metadata 
)

Definition at line 153 of file verify_plugin.py.

00153 
00154     def verify_regular_file(self, gen, filename, metadata):
00155         logging.debug('verifying regular %s' % filename)
00156         f = self.fs.open(filename, 'r')
00157 
00158         chunkids = self.repo.get_file_chunks(gen, filename)
00159         if not self.verify_chunks(f, chunkids):
00160             raise Fail(filename, 'data changed')
00161 
00162         f.close()

Here is the call graph for this function:

def obnamlib.plugins.verify_plugin.VerifyPlugin.walk (   self,
  gen,
  args 
)
Iterate over each pathname specified by arguments.

This is a generator.

Definition at line 171 of file verify_plugin.py.

00171 
00172     def walk(self, gen, args):
00173         '''Iterate over each pathname specified by arguments.
00174         
00175         This is a generator.
00176         
00177         '''
00178         
00179         for arg in args:
00180             scheme, netloc, path, query, fragment = urlparse.urlsplit(arg)
00181             arg = os.path.normpath(path)
00182             for x in self.repo.walk(gen, arg):
00183                 yield x
00184 

Here is the caller graph for this function:


Member Data Documentation

Definition at line 73 of file verify_plugin.py.

Definition at line 65 of file verify_plugin.py.

Definition at line 63 of file verify_plugin.py.


The documentation for this class was generated from the following file: