Back to index

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

List of all members.

Public Member Functions

def enable
def write_ok
def configure_ttystatus
def restore
def restore_something
def restore_dir
def restore_hardlink
def restore_symlink
def restore_first_link
def restore_regular_file
def restore_chunks
def verify_chunk_checksum
def restore_fifo
def restore_socket

Public Attributes

 repo
 fs
 hardlinks
 errors

Detailed Description

Definition at line 54 of file restore_plugin.py.


Member Function Documentation

Definition at line 75 of file restore_plugin.py.

00075 
00076     def configure_ttystatus(self):
00077         self.app.ts['current'] = ''
00078         self.app.ts['total'] = 0
00079         self.app.ts['current-bytes'] = 0
00080         self.app.ts['total-bytes'] = 0
00081         
00082         self.app.ts.format('%RemainingTime(current-bytes,total-bytes) '
00083                            '%Counter(current) files '
00084                            '%ByteSize(current-bytes) '
00085                            '(%PercentDone(current-bytes,total-bytes)) '
00086                            '%ByteSpeed(current-bytes) '
00087                            '%Pathname(current)')

Definition at line 63 of file restore_plugin.py.

00063 
00064     def enable(self):
00065         self.app.add_subcommand('restore', self.restore, 
00066                                 arg_synopsis='[FILE]...')
00067         self.app.settings.string(['to'], 'where to restore')
00068         self.app.settings.string(['generation'], 
00069                                 'which generation to restore',
00070                                  default='latest')

Here is the call graph for this function:

Restore some or all files from a generation.

Definition at line 88 of file restore_plugin.py.

00088 
00089     def restore(self, args):
00090         '''Restore some or all files from a generation.'''
00091         self.app.settings.require('repository')
00092         self.app.settings.require('client-name')
00093         self.app.settings.require('generation')
00094         self.app.settings.require('to')
00095 
00096         logging.debug('restoring generation %s' % 
00097                         self.app.settings['generation'])
00098         logging.debug('restoring to %s' % self.app.settings['to'])
00099     
00100         logging.debug('restoring what: %s' % repr(args))
00101         if not args:
00102             logging.debug('no args given, so restoring everything')
00103             args = ['/']
00104     
00105         self.repo = self.app.open_repository()
00106         self.repo.open_client(self.app.settings['client-name'])
00107         if self.write_ok:
00108             self.fs = self.app.fsf.new(self.app.settings['to'], create=True)
00109             self.fs.connect()
00110         else:
00111             self.fs = None # this will trigger error if we try to really write
00112 
00113         self.hardlinks = Hardlinks()
00114         
00115         self.errors = False
00116         
00117         gen = self.repo.genspec(self.app.settings['generation'])
00118 
00119         self.configure_ttystatus()
00120         self.app.ts['total'] = self.repo.client.get_generation_file_count(gen)
00121         self.app.ts['total-bytes'] = self.repo.client.get_generation_data(gen)
00122 
00123         self.app.dump_memory_profile('at beginning after setup')
00124 
00125         for arg in args:
00126             self.restore_something(gen, arg)
00127             self.app.dump_memory_profile('at restoring %s' % repr(arg))
00128 
00129         self.repo.fs.close()
00130         if self.write_ok:
00131             self.fs.close()
00132         
00133         self.app.ts.finish()
00134                 
00135         if self.errors:
00136             raise obnamlib.Error('There were errors when restoring')

Here is the caller graph for this function:

def obnamlib.plugins.restore_plugin.RestorePlugin.restore_chunks (   self,
  f,
  chunkids,
  checksummer 
)

Definition at line 219 of file restore_plugin.py.

00219 
00220     def restore_chunks(self, f, chunkids, checksummer):
00221         zeroes = ''
00222         hole_at_end = False
00223         for chunkid in chunkids:
00224             data = self.repo.get_chunk(chunkid)
00225             self.verify_chunk_checksum(data, chunkid)
00226             checksummer.update(data)
00227             if len(data) != len(zeroes):
00228                 zeroes = '\0' * len(data)
00229             if data == zeroes:
00230                 f.seek(len(data), 1)
00231                 hole_at_end = True
00232             else:
00233                 f.write(data)
00234                 hole_at_end = False
00235             self.app.ts['current-bytes'] += len(data)
00236         if hole_at_end:
00237             pos = f.tell()
00238             if pos > 0:
00239                 f.seek(-1, 1)
00240                 f.write('\0')

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.plugins.restore_plugin.RestorePlugin.restore_dir (   self,
  gen,
  root,
  metadata 
)

Definition at line 162 of file restore_plugin.py.

00162 
00163     def restore_dir(self, gen, root, metadata):
00164         logging.debug('restoring dir %s' % root)
00165         if self.write_ok:
00166             if not self.fs.exists('./' + root):
00167                 self.fs.mkdir('./' + root)
00168         self.app.dump_memory_profile('after recursing through %s' % repr(root))

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.plugins.restore_plugin.RestorePlugin.restore_fifo (   self,
  gen,
  filename,
  metadata 
)

Definition at line 252 of file restore_plugin.py.

00252 
00253     def restore_fifo(self, gen, filename, metadata):
00254         logging.debug('restoring fifo %s' % filename)
00255         if self.write_ok:
00256             self.fs.mknod('./' + filename, metadata.st_mode)

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.plugins.restore_plugin.RestorePlugin.restore_first_link (   self,
  gen,
  filename,
  metadata 
)

Definition at line 178 of file restore_plugin.py.

00178 
00179     def restore_first_link(self, gen, filename, metadata):
00180         if stat.S_ISREG(metadata.st_mode):
00181             self.restore_regular_file(gen, filename, metadata)
00182         elif stat.S_ISFIFO(metadata.st_mode):
00183             self.restore_fifo(gen, filename, metadata)
00184         elif stat.S_ISSOCK(metadata.st_mode):
00185             self.restore_socket(gen, filename, metadata)
00186         else:
00187             msg = ('Unknown file type: %s (%o)' % 
00188                    (filename, metadata.st_mode))
00189             logging.error(msg)
00190             self.app.ts.notify(msg)
        

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.plugins.restore_plugin.RestorePlugin.restore_hardlink (   self,
  filename,
  link,
  metadata 
)

Definition at line 169 of file restore_plugin.py.

00169 
00170     def restore_hardlink(self, filename, link, metadata):
00171         logging.debug('restoring hardlink %s to %s' % (filename, link))
00172         if self.write_ok:
00173             self.fs.link('./' + link, './' + filename)
00174             self.hardlinks.forget(metadata)
        

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.plugins.restore_plugin.RestorePlugin.restore_regular_file (   self,
  gen,
  filename,
  metadata 
)

Definition at line 191 of file restore_plugin.py.

00191 
00192     def restore_regular_file(self, gen, filename, metadata):
00193         logging.debug('restoring regular %s' % filename)
00194         if self.write_ok:
00195             f = self.fs.open('./' + filename, 'wb')
00196             summer = self.repo.new_checksummer()
00197 
00198             try:
00199                 contents = self.repo.get_file_data(gen, filename)
00200                 if contents is None:
00201                     chunkids = self.repo.get_file_chunks(gen, filename)
00202                     self.restore_chunks(f, chunkids, summer)
00203                 else:
00204                     f.write(contents)
00205                     summer.update(contents)
00206             except obnamlib.MissingFilterError, e:
00207                 msg = 'Missing filter error during restore: %s' % filename
00208                 logging.error(msg)
00209                 self.app.ts.notify(msg)
00210                 self.errors = True
00211             f.close()
00212 
00213             correct_checksum = metadata.md5
00214             if summer.digest() != correct_checksum:
00215                 msg = 'File checksum restore error: %s' % filename
00216                 logging.error(msg)
00217                 self.app.ts.notify(msg)
00218                 self.errors = True

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.plugins.restore_plugin.RestorePlugin.restore_socket (   self,
  gen,
  filename,
  metadata 
)

Definition at line 257 of file restore_plugin.py.

00257 
00258     def restore_socket(self, gen, filename, metadata):
00259         logging.debug('restoring socket %s' % filename)
00260         if self.write_ok:
00261             self.fs.mknod('./' + filename, metadata.st_mode)
00262 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 137 of file restore_plugin.py.

00137 
00138     def restore_something(self, gen, root):
00139         for pathname, metadata in self.repo.walk(gen, root, depth_first=True):
00140             self.app.ts['current'] = pathname
00141             dirname = os.path.dirname(pathname)
00142             if self.write_ok and not self.fs.exists('./' + dirname):
00143                 self.fs.makedirs('./' + dirname)
00144     
00145             set_metadata = True
00146             if metadata.isdir():
00147                 self.restore_dir(gen, pathname, metadata)
00148             elif metadata.islink():
00149                 self.restore_symlink(gen, pathname, metadata)
00150             elif metadata.st_nlink > 1:
00151                 link = self.hardlinks.filename(metadata)
00152                 if link:
00153                     self.restore_hardlink(pathname, link, metadata)
00154                     set_metadata = False
00155                 else:
00156                     self.hardlinks.add(pathname, metadata)
00157                     self.restore_first_link(gen, pathname, metadata)
00158             else:
00159                 self.restore_first_link(gen, pathname, metadata)
00160             if set_metadata and self.write_ok:
00161                 obnamlib.set_metadata(self.fs, './' + pathname, metadata)

Here is the call graph for this function:

def obnamlib.plugins.restore_plugin.RestorePlugin.restore_symlink (   self,
  gen,
  filename,
  metadata 
)

Definition at line 175 of file restore_plugin.py.

00175 
00176     def restore_symlink(self, gen, filename, metadata):
00177         logging.debug('restoring symlink %s' % filename)

Here is the caller graph for this function:

Definition at line 241 of file restore_plugin.py.

00241 
00242     def verify_chunk_checksum(self, data, chunkid):
00243         checksum = self.repo.checksum(data)
00244         try:
00245             wanted = self.repo.chunklist.get_checksum(chunkid)
00246         except KeyError:
00247             # Chunk might not be in the tree, but that does not
00248             # mean it is invalid. We'll assume it is valid.
00249             return
00250         if checksum != wanted:
00251             raise obnamlib.Error('chunk %s checksum error' % chunkid)

Here is the caller graph for this function:

Definition at line 72 of file restore_plugin.py.

00072 
00073     def write_ok(self):
00074         return not self.app.settings['dry-run']

Here is the caller graph for this function:


Member Data Documentation

Definition at line 114 of file restore_plugin.py.

Definition at line 107 of file restore_plugin.py.

Definition at line 112 of file restore_plugin.py.

Definition at line 104 of file restore_plugin.py.


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