Back to index

obnam  1.1
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
obnamlib.plugins.show_plugin.ShowPlugin Class Reference
Inheritance diagram for obnamlib.plugins.show_plugin.ShowPlugin:
Inheritance graph
[legend]
Collaboration diagram for obnamlib.plugins.show_plugin.ShowPlugin:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def enable
def open_repository
def clients
def generations
def nagios_last_backup_age
def genids
def ls
def format_time
def isdir
def show_objects
def show_item
def fields
def format
def align

Public Attributes

 repo

Static Public Attributes

tuple leftists = (2, 3, 6)
tuple min_widths = (1, 1, 1, 1, 6, 20, 1)

Private Member Functions

def _convert_time

Detailed Description

Show information about data in the backup repository.

This implements commands for listing contents of root and client
objects, or the contents of a backup generation.

Definition at line 26 of file show_plugin.py.


Member Function Documentation

def obnamlib.plugins.show_plugin.ShowPlugin._convert_time (   self,
  s,
  default_unit = 'h' 
) [private]

Definition at line 233 of file show_plugin.py.

00233 
00234     def _convert_time(self, s, default_unit='h'):
00235         m = re.match('([0-9]+)([smhdw])?$', s)
00236         if m is None: raise ValueError
00237         ticks = int(m.group(1))
00238         unit = m.group(2)
00239         if unit is None: unit = default_unit
00240 
00241         if unit == 's':
00242             None
00243         elif unit == 'm':
00244             ticks *= 60
00245         elif unit == 'h':
00246             ticks *= 60*60
00247         elif unit == 'd':
00248             ticks *= 60*60*24
00249         elif unit == 'w':
00250             ticks *= 60*60*24*7
00251         else:
00252             raise ValueError
00253         return ticks
00254 

Here is the caller graph for this function:

def obnamlib.plugins.show_plugin.ShowPlugin.align (   self,
  width,
  field,
  field_no 
)

Definition at line 227 of file show_plugin.py.

00227 
00228     def align(self, width, field, field_no):
00229         if field_no in self.leftists:
00230             return '%-*s' % (width, field)
00231         else:
00232             return '%*s' % (width, field)

Here is the caller graph for this function:

List clients using the repository.

Definition at line 71 of file show_plugin.py.

00071 
00072     def clients(self, args):
00073         '''List clients using the repository.'''
00074         self.open_repository()
00075         for client_name in self.repo.list_clients():
00076             print client_name
00077         self.repo.fs.close()
    

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 38 of file show_plugin.py.

00038 
00039     def enable(self):
00040         self.app.add_subcommand('clients', self.clients)
00041         self.app.add_subcommand('generations', self.generations)
00042         self.app.add_subcommand('genids', self.genids)
00043         self.app.add_subcommand('ls', self.ls, arg_synopsis='[GENERATION]...')
00044         self.app.add_subcommand('nagios-last-backup-age', 
00045                                 self.nagios_last_backup_age)
00046 
00047         self.app.settings.string(['warn-age'],
00048                                  'for nagios-last-backup-age: maximum age (by '
00049                                     'default in hours) for the most recent '
00050                                     'backup before status is warning. '
00051                                     'Accepts one char unit specifier '
00052                                     '(s,m,h,d for seconds, minutes, hours, '
00053                                     'and days.', 
00054                                   metavar='AGE',
00055                                   default=obnamlib.DEFAULT_NAGIOS_WARN_AGE)
00056         self.app.settings.string(['critical-age'],
00057                                  'for nagios-last-backup-age: maximum age '
00058                                     '(by default in hours) for the most '
00059                                     'recent backup before statis is critical. '
00060                                     'Accepts one char unit specifier '
00061                                     '(s,m,h,d for seconds, minutes, hours, '
00062                                     'and days.', 
00063                                   metavar='AGE',
00064                                   default=obnamlib.DEFAULT_NAGIOS_WARN_AGE)

Here is the call graph for this function:

def obnamlib.plugins.show_plugin.ShowPlugin.fields (   self,
  gen,
  full 
)

Definition at line 182 of file show_plugin.py.

00182 
00183     def fields(self, gen, full):
00184         metadata = self.repo.get_metadata(gen, full)
00185 
00186         perms = ['?'] + ['-'] * 9
00187         tab = [
00188             (stat.S_IFREG, 0, '-'),
00189             (stat.S_IFDIR, 0, 'd'),
00190             (stat.S_IFLNK, 0, 'l'),
00191             (stat.S_IFIFO, 0, 'p'),
00192             (stat.S_IRUSR, 1, 'r'),
00193             (stat.S_IWUSR, 2, 'w'),
00194             (stat.S_IXUSR, 3, 'x'),
00195             (stat.S_IRGRP, 4, 'r'),
00196             (stat.S_IWGRP, 5, 'w'),
00197             (stat.S_IXGRP, 6, 'x'),
00198             (stat.S_IROTH, 7, 'r'),
00199             (stat.S_IWOTH, 8, 'w'),
00200             (stat.S_IXOTH, 9, 'x'),
00201         ]
00202         mode = metadata.st_mode or 0
00203         for bitmap, offset, char in tab:
00204             if (mode & bitmap) == bitmap:
00205                 perms[offset] = char
00206         perms = ''.join(perms)
00207         
00208         timestamp = time.strftime('%Y-%m-%d %H:%M:%S', 
00209                                   time.gmtime(metadata.st_mtime_sec))
00210 
00211         if metadata.islink():
00212             name = '%s -> %s' % (full, metadata.target)
00213         else:
00214             name = full
00215 
00216         return (perms, 
00217                  str(metadata.st_nlink or 0), 
00218                  metadata.username or '', 
00219                  metadata.groupname or '',
00220                  str(metadata.st_size or 0), 
00221                  timestamp, 
00222                  name)

Here is the caller graph for this function:

def obnamlib.plugins.show_plugin.ShowPlugin.format (   self,
  fields 
)

Definition at line 223 of file show_plugin.py.

00223 
00224     def format(self, fields):
00225         return ' '. join(self.align(widths[i], fields[i], i)
00226                           for i in range(len(fields)))

Here is the call graph for this function:

def obnamlib.plugins.show_plugin.ShowPlugin.format_time (   self,
  timestamp 
)

Definition at line 141 of file show_plugin.py.

00141 
00142     def format_time(self, timestamp):
00143         return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp))
    

Here is the caller graph for this function:

List backup generations for client.

Definition at line 78 of file show_plugin.py.

00078 
00079     def generations(self, args):
00080         '''List backup generations for client.'''
00081         self.open_repository()
00082         for gen in self.repo.list_generations():
00083             start, end = self.repo.get_generation_times(gen)
00084             is_checkpoint = self.repo.get_is_checkpoint(gen)
00085             if is_checkpoint:
00086                 checkpoint = ' (checkpoint)'
00087             else:
00088                 checkpoint = ''
00089             sys.stdout.write('%s\t%s .. %s (%d files, %d bytes) %s\n' %
00090                              (gen, 
00091                               self.format_time(start), 
00092                               self.format_time(end),
00093                               self.repo.client.get_generation_file_count(gen),
00094                               self.repo.client.get_generation_data(gen),
00095                               checkpoint))
00096         self.repo.fs.close()

Here is the call graph for this function:

Here is the caller graph for this function:

List generation ids for client.

Definition at line 122 of file show_plugin.py.

00122 
00123     def genids(self, args):
00124         '''List generation ids for client.'''
00125         self.open_repository()
00126         for gen in self.repo.list_generations():
00127             sys.stdout.write('%s\n' % gen)
00128         self.repo.fs.close()

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.plugins.show_plugin.ShowPlugin.isdir (   self,
  gen,
  filename 
)

Definition at line 144 of file show_plugin.py.

00144 
00145     def isdir(self, gen, filename):
00146         metadata = self.repo.get_metadata(gen, filename)
00147         return metadata.isdir()
    

Here is the caller graph for this function:

def obnamlib.plugins.show_plugin.ShowPlugin.ls (   self,
  args 
)
List contents of a generation.

Definition at line 129 of file show_plugin.py.

00129 
00130     def ls(self, args):
00131         '''List contents of a generation.'''
00132         self.open_repository()
00133         for gen in args or [self.app.settings['generation']] or ["latest"]:
00134             gen = self.repo.genspec(gen)
00135             started, ended = self.repo.client.get_generation_times(gen)
00136             started = self.format_time(started)
00137             ended = self.format_time(ended)
00138             print 'Generation %s (%s - %s)' % (gen, started, ended)
00139             self.show_objects(gen, '/')
00140         self.repo.fs.close()
    

Here is the call graph for this function:

Here is the caller graph for this function:

Check if the most recent generation is recent enough.

Definition at line 97 of file show_plugin.py.

00097 
00098     def nagios_last_backup_age(self, args):
00099         '''Check if the most recent generation is recent enough.'''
00100         self.open_repository()
00101         most_recent = None
00102 
00103         warn_age = self._convert_time(self.app.settings['warn-age'])
00104         critical_age = self._convert_time(self.app.settings['critical-age'])
00105 
00106         for gen in self.repo.list_generations():
00107             start, end = self.repo.get_generation_times(gen)
00108             if most_recent is None or start > most_recent: most_recent = start
00109         self.repo.fs.close()
00110 
00111         now = self.app.time()
00112         if (now - most_recent > critical_age):
00113             print "CRITICAL: backup is old.  last backup was %s."%(
00114                 self.format_time(most_recent))
00115             sys.exit(2)
00116         elif (now - most_recent > warn_age):
00117             print "WARNING: backup is old.  last backup was %s."%(
00118                 self.format_time(most_recent))
00119             sys.exit(2)
00120         print "OK: backup is recent.  last backup was %s."%(
00121             self.format_time(most_recent))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 65 of file show_plugin.py.

00065 
00066     def open_repository(self):
00067         self.app.settings.require('repository')
00068         self.app.settings.require('client-name')
00069         self.repo = self.app.open_repository()
00070         self.repo.open_client(self.app.settings['client-name'])

Here is the caller graph for this function:

def obnamlib.plugins.show_plugin.ShowPlugin.show_item (   self,
  gen,
  filename 
)

Definition at line 161 of file show_plugin.py.

00161 
00162     def show_item(self, gen, filename):
00163         fields = self.fields(gen, filename)
00164         widths = [
00165             1, # mode
00166             5, # nlink
00167             -8, # owner
00168             -8, # group
00169             10, # size
00170             1, # mtime
00171             -1, # name
00172         ]
00173         
00174         result = []
00175         for i in range(len(fields)):
00176             if widths[i] < 0:
00177                 fmt = '%-*s'
00178             else:
00179                 fmt = '%*s'
00180             result.append(fmt % (abs(widths[i]), fields[i]))
00181         print ' '.join(result)

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.plugins.show_plugin.ShowPlugin.show_objects (   self,
  gen,
  dirname 
)

Definition at line 148 of file show_plugin.py.

00148 
00149     def show_objects(self, gen, dirname):
00150         self.show_item(gen, dirname)
00151         subdirs = []
00152         for basename in sorted(self.repo.listdir(gen, dirname)):
00153             full = os.path.join(dirname, basename)
00154             if self.isdir(gen, full):
00155                 subdirs.append(full)
00156             else:
00157                 self.show_item(gen, full)
00158 
00159         for subdir in subdirs:
00160             self.show_objects(gen, subdir)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 35 of file show_plugin.py.

tuple obnamlib.plugins.show_plugin.ShowPlugin.min_widths = (1, 1, 1, 1, 6, 20, 1) [static]

Definition at line 36 of file show_plugin.py.

Definition at line 68 of file show_plugin.py.


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