コード例 #1
0
ファイル: dar.py プロジェクト: jayme-github/Dardrive
    def recover_from_dmd(self, path, tmp_path, when=None):
        '''Perform a dar_manager recovery'''
        if isinstance(path, list):
            path = " ".join(path)

        args = {'dar_manager': self.cf.dar_manager_bin, 'dmd_file': self.dmd,
                'path': path, 'tmp_path': tmp_path}
        tpl = "%(dar_manager)s -B %(dmd_file)s "

        tpl += ' -e "-Q -w -R %(tmp_path)s '
        if self.cf.encryption:
            command_file = mk_dar_crypt_file(self.cf.encryption)
            self.logger.debug('Creating encryption command file %s' %
                              command_file)
            tpl += '-B %s ' % command_file

        if not is_admin():
            tpl += ' --comparison-field=ignore-owner '

        #Close the -e quote.
        tpl += ' " '

        if when:
            tpl += "-w %(when)s "
            args['when'] = when

        tpl += "-Q -r %(path)s "

        self.logger.debug(tpl)
        rval = self.run_command(tpl, args)
        if self.cf.encryption and os.path.exists(command_file):
            self.logger.debug('Deleting encryption command file %s' %
                              command_file)
            os.unlink(command_file)
        return rval
コード例 #2
0
ファイル: dar.py プロジェクト: jayme-github/Dardrive
    def mk_bkp_args(self, basename):
        if self.newcatalog.type == self.Full:
            tpl = commands['full_bck']
        else:
            tpl = commands['inc_bck']
            #check for reference catalog's presence
            refcatalog = os.path.join(
                self.cf.catalog_store,
                self.Job.name,
                self.refbasename.id)
            if len(glob.glob("%s.*.dar" % refcatalog)) > 0:
                self.args.update({'refcatalog': refcatalog})
            else:
                raise RefCatalogError(
                    "Can't find the reference catalog: (%s)" % refcatalog)

        self.logger.debug(self.cf.compr)

        if self.cf.compr:
            tpl += bakup_extra['compr']
            tpl += bakup_extra['compr_min']
            tpl += bakup_extra['compr_exempt']
        if self.cf.slice:
            tpl += bakup_extra['slice']
        if self.cf.encryption:
            command_file = mk_dar_crypt_file(self.cf.encryption)
            self.logger.debug('Creating encryption command file %s' %
                              command_file)
            self.args['encryption'] = command_file
            tpl += bakup_extra['encryption']
            self.newcatalog.enc = True
        if self.cf.same_fs:
            tpl += bakup_extra['same_fs']
        if self.cf.exclude_regex:
            tpl += bakup_extra['exclude_regex']
        if self.cf.exclude_file:
            tpl += bakup_extra['exclude_file']

        #par_local MUST come after par template, as dar "-E" commands are
        #executed in the order they appear on the command line
        if self.cf.redundancy:
            tpl += bakup_extra['par']
            if self.cf.par_local:
                tpl += bakup_extra['par_local']

        #If par & par_local are True, dump the backup to local_store,
        #as a "-E" dar command will move the basename to the archive_storage
        if self.cf.redundancy and self.cf.par_local:
            mkdir(self.cf.local_store, self.section)
            self.args.update({'basename': os.path.join(
                self.cf.local_store, self.Job.name, basename)})
        else:
            self.args.update({'basename': os.path.join(
                self.cf.archive_store, self.Job.name, basename)})

        self.args.update({'catalog': os.path.join(
            self.cf.catalog_store,
            self.Job.name, basename)})
        return tpl
コード例 #3
0
ファイル: dar.py プロジェクト: jayme-github/Dardrive
                                 Catalog.job == self.Job,
                                 Catalog.type == self.Full
                                 )).order_by(Catalog.date.desc()).first()
            childs = getchilds(last)
        else:
            try:
                last = q.filter_by(id=catalog).one()
                childs = getancestors(last)
            except NoResultFound, e:
                raise RecoverError("% s is not a valid jobid." % catalog)

        if not is_admin():
            tpl += "-O ignore-owner "

        if self.cf.encryption:
            command_file = mk_dar_crypt_file(self.cf.encryption)
            self.logger.debug('Creating encryption command file %s' %
                              command_file)
            tpl += '-B %s ' % command_file

        args = {'dar_bin': self.cf.dar_bin, 'recover_path': rpath}

        #If catalog was given, we need to sort the list.
        all_archives = sorted([last] + childs, key=lambda x: x.date)
        self.logger.debug("Restoring from: %s" % all_archives)
        _err = False
        for arch in all_archives:
            stdout.write("Recovering %s archive id: %s..\n" %
                         (arch.type.name, arch.id))

            args['archive_path'] = os.path.join(