Logo Search packages:      
Sourcecode: obnam version File versions  Download package

fsck_plugin.py

# Copyright (C) 2010  Lars Wirzenius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import logging
import os

import obnamlib


00023 class FsckPlugin(obnamlib.ObnamPlugin):

    def enable(self):
        self.app.add_subcommand('fsck', self.fsck)
        
00028     def fsck(self, args):
        '''Verify internal consistency of backup repository.'''
        self.app.settings.require('repository')
        logging.debug('fsck on %s' % self.app.settings['repository'])
        self.repo = self.app.open_repository()
        self.check_root()
        self.repo.fs.close()

00036     def check_root(self):
        '''Check the root node.'''
        logging.debug('Checking root node')
        self.app.hooks.call('status', 'Checking root node')
        for client in self.repo.list_clients():
            self.check_client(client)
    
00043     def check_client(self, client_name):
        '''Check a client.'''
        logging.debug('Checking client %s' % client_name)
        self.app.hooks.call('status', 'Checking client %s' % client_name)
        self.repo.open_client(client_name)
        for genid in self.repo.list_generations():
            self.check_generation(genid)

00051     def check_generation(self, genid):
        '''Check a generation.'''
        logging.debug('Checking generation %s' % genid)
        self.app.hooks.call('status', 'Checking generation %s' % genid)
        self.check_dir(genid, '/')

00057     def check_dir(self, genid, dirname):
        '''Check a directory.'''
        logging.debug('Checking directory %s' % dirname)
        self.app.hooks.call('status', 'Checking dir %s' % dirname)
        self.repo.get_metadata(genid, dirname)
        for basename in self.repo.listdir(genid, dirname):
            pathname = os.path.join(dirname, basename)
            metadata = self.repo.get_metadata(genid, pathname)
            if metadata.isdir():
                self.check_dir(genid, pathname)
            else:
                self.check_file(genid, pathname)
                
00070     def check_file(self, genid, filename):
        '''Check a non-directory.'''
        logging.debug('Checking file %s' % filename)
        self.app.hooks.call('status', 'Checking file %s' % filename)
        metadata = self.repo.get_metadata(genid, filename)
        if metadata.isfile():
            for chunkid in self.repo.get_file_chunks(genid, filename):
                self.check_chunk(chunkid)

00079     def check_chunk(self, chunkid):
        '''Check a chunk.'''
        logging.debug('Checking chunk %s' % chunkid)
        self.repo.chunk_exists(chunkid)


Generated by  Doxygen 1.6.0   Back to index