コード例 #1
0
ファイル: job.py プロジェクト: FedericoCeratto/freezer
    def execute(self):
        try:
            (out, err) = utils.create_subprocess('sync')
            if err:
                logging.error('Error while sync exec: {0}'.format(err))
        except Exception as error:
            logging.error('Error while sync exec: {0}'.format(error))
        self.conf.storage.prepare()

        if self.conf.mode == 'fs':
            backup.backup(self.conf, self.storage, self.engine)
        elif self.conf.mode == 'mongo':
            backup.backup_mode_mongo(self.conf)
        elif self.conf.mode == 'mysql':
            backup.backup_mode_mysql(self.conf)
        elif self.conf.mode == 'sqlserver':
            backup.backup_mode_sql_server(self.conf)
        else:
            raise ValueError('Please provide a valid backup mode')
コード例 #2
0
ファイル: job.py プロジェクト: stannie42/freezer
    def execute(self):
        containers = swift.check_container_existance(self.conf)

        if containers['main_container'] is not True:
            swift.create_containers(self.conf)

        if self.conf.no_incremental:
            if self.conf.max_backup_level or \
               self.conf.always_backup_level:
                raise Exception(
                    'no-incremental option is not compatible '
                    'with backup level options')
            manifest_meta_dict = {}
        else:
            # Get the object list of the remote containers
            # and store it in self.conf.remote_obj_list
            self.conf = swift.get_container_content(self.conf)

            # Check if a backup exist in swift with same name.
            # If not, set backup level to 0
            manifest_meta_dict =\
                utils.check_backup_and_tar_meta_existence(self.conf)

        (self.conf, manifest_meta_dict) = utils.set_backup_level(
            self.conf, manifest_meta_dict)

        self.conf.manifest_meta_dict = manifest_meta_dict

        if self.conf.mode == 'fs':
            backup.backup_mode_fs(
                self.conf, self.start_time.timestamp, manifest_meta_dict)
        elif self.conf.mode == 'mongo':
            backup.backup_mode_mongo(
                self.conf, self.start_time.timestamp, manifest_meta_dict)
        elif self.conf.mode == 'mysql':
            backup.backup_mode_mysql(
                self.conf, self.start_time.timestamp, manifest_meta_dict)
        elif self.conf.mode == 'sqlserver':
            backup.backup_mode_sql_server(
                self.conf, self.time_stamp, manifest_meta_dict)
        else:
            raise ValueError('Please provide a valid backup mode')
コード例 #3
0
ファイル: job.py プロジェクト: stannie42/freezer
    def execute(self):
        containers = swift.check_container_existance(self.conf)

        if containers['main_container'] is not True:
            swift.create_containers(self.conf)

        if self.conf.no_incremental:
            if self.conf.max_backup_level or \
               self.conf.always_backup_level:
                raise Exception('no-incremental option is not compatible '
                                'with backup level options')
            manifest_meta_dict = {}
        else:
            # Get the object list of the remote containers
            # and store it in self.conf.remote_obj_list
            self.conf = swift.get_container_content(self.conf)

            # Check if a backup exist in swift with same name.
            # If not, set backup level to 0
            manifest_meta_dict =\
                utils.check_backup_and_tar_meta_existence(self.conf)

        (self.conf,
         manifest_meta_dict) = utils.set_backup_level(self.conf,
                                                      manifest_meta_dict)

        self.conf.manifest_meta_dict = manifest_meta_dict

        if self.conf.mode == 'fs':
            backup.backup_mode_fs(self.conf, self.start_time.timestamp,
                                  manifest_meta_dict)
        elif self.conf.mode == 'mongo':
            backup.backup_mode_mongo(self.conf, self.start_time.timestamp,
                                     manifest_meta_dict)
        elif self.conf.mode == 'mysql':
            backup.backup_mode_mysql(self.conf, self.start_time.timestamp,
                                     manifest_meta_dict)
        elif self.conf.mode == 'sqlserver':
            backup.backup_mode_sql_server(self.conf, self.time_stamp,
                                          manifest_meta_dict)
        else:
            raise ValueError('Please provide a valid backup mode')
コード例 #4
0
ファイル: test_backup.py プロジェクト: frescof/freezer
    def test_backup_mode_mongo(self, monkeypatch, tmpdir):

        # Class and other settings initialization
        test_meta = dict()
        backup_opt = BackupOpt1()
        backup_opt.__dict__['storage'] = local.LocalStorage(tmpdir.strpath)

        fakemongo = FakeMongoDB()
        backup_opt.mode = 'mongo'
        fakeos = Os()
        fakere = FakeRe()
        fakeswiftclient = FakeSwiftClient()
        #fakeopen = FakeOpen()
        fakelvm = Lvm()
        fakemultiprocessing = FakeMultiProcessing()
        fakemultiprocessingqueue = fakemultiprocessing.Queue()
        fakemultiprocessingpipe = fakemultiprocessing.Pipe()
        fakemultiprocessinginit = fakemultiprocessing.__init__()

        monkeypatch.setattr(
            multiprocessing, 'Queue', fakemultiprocessingqueue)
        monkeypatch.setattr(
            multiprocessing, 'Pipe', fakemultiprocessingpipe)
        monkeypatch.setattr(
            multiprocessing, 'Process', fakemultiprocessing.Process)
        monkeypatch.setattr(
            multiprocessing, '__init__', fakemultiprocessinginit)
        monkeypatch.setattr(freezer.lvm, 'lvm_eval', fakelvm.lvm_eval)
        monkeypatch.setattr(pymongo, 'MongoClient', fakemongo)
        monkeypatch.setattr(os.path, 'exists', fakeos.exists)
        monkeypatch.setattr(re, 'search', fakere.search)
        monkeypatch.setattr(swiftclient, 'client', fakeswiftclient.client)
        #monkeypatch.setattr(__builtin__, 'open', fakeopen.open)

        assert backup_mode_mongo(backup_opt) is None

        fakemongo2 = FakeMongoDB2()
        monkeypatch.setattr(pymongo, 'MongoClient', fakemongo2)
        assert backup_mode_mongo(backup_opt) is True
コード例 #5
0
    def test_backup_mode_mongo(self, monkeypatch):

        # Class and other settings initialization
        test_meta = dict()
        backup_opt = BackupOpt1()
        fakemongo = FakeMongoDB()
        backup_opt.mode = 'mongo'
        fakeos = Os()
        fakere = FakeRe()
        fakeswiftclient = FakeSwiftClient()
        #fakeopen = FakeOpen()
        fakelvm = Lvm()
        fakemultiprocessing = FakeMultiProcessing()
        fakemultiprocessingqueue = fakemultiprocessing.Queue()
        fakemultiprocessingpipe = fakemultiprocessing.Pipe()
        fakemultiprocessinginit = fakemultiprocessing.__init__()

        monkeypatch.setattr(
            multiprocessing, 'Queue', fakemultiprocessingqueue)
        monkeypatch.setattr(
            multiprocessing, 'Pipe', fakemultiprocessingpipe)
        monkeypatch.setattr(
            multiprocessing, 'Process', fakemultiprocessing.Process)
        monkeypatch.setattr(
            multiprocessing, '__init__', fakemultiprocessinginit)
        monkeypatch.setattr(freezer.lvm, 'lvm_eval', fakelvm.lvm_eval)
        monkeypatch.setattr(pymongo, 'MongoClient', fakemongo)
        monkeypatch.setattr(os.path, 'exists', fakeos.exists)
        monkeypatch.setattr(re, 'search', fakere.search)
        monkeypatch.setattr(swiftclient, 'client', fakeswiftclient.client)
        #monkeypatch.setattr(__builtin__, 'open', fakeopen.open)

        assert backup_mode_mongo(
            backup_opt, 123456789, test_meta) is None

        fakemongo2 = FakeMongoDB2()
        monkeypatch.setattr(pymongo, 'MongoClient', fakemongo2)
        assert backup_mode_mongo(
            backup_opt, 123456789, test_meta) is True
コード例 #6
0
ファイル: main.py プロジェクト: berez23/freezer
def freezer_main(backup_args):
    '''
    Program Main Execution. This main function is a wrapper for most
    of the other functions. By calling main() the program execution start
    and the respective actions are taken. If you want only use the single
    function is probably better to not import main()
    '''

    # Computing execution start datetime and Timestamp
    (time_stamp, today_start) = start_time()
    # Add timestamp to the arguments namespace
    backup_args.__dict__['time_stamp'] = time_stamp

    # Initialize the swift connector and store it in the same dict passed
    # as argument under the dict.sw_connector namespace. This is helpful
    # so the swift client object doesn't need to be initialized every time
    backup_args = get_client(backup_args)

    # Get the list of the containers
    backup_args = get_containers_list(backup_args)

    if show_containers(backup_args):
        elapsed_time(today_start)
        return True

    # Check if the provided container already exists in swift.
    # If it doesn't exist a new one will be created along with the segments
    # container as container_segments
    backup_args = check_container_existance(backup_args)

    # Get the object list of the remote containers and store id in the
    # same dict passes as argument under the dict.remote_obj_list namespace
    backup_args = get_container_content(backup_args)

    if show_objects(backup_args):
        elapsed_time(today_start)
        return True

    # Check if a backup exist in swift with same name. If not, set
    # backup level to 0
    manifest_meta_dict = check_backup_existance(backup_args)

    # Set the right backup level for incremental backup
    (backup_args,
     manifest_meta_dict) = set_backup_level(backup_args, manifest_meta_dict)

    backup_args.manifest_meta_dict = manifest_meta_dict
    # File system backup mode selected
    if backup_args.mode == 'fs':
        # If any of the restore options was specified, then a data restore
        # will be executed
        if validate_any_args([
                backup_args.restore_from_date, backup_args.restore_from_host,
                backup_args.restore_abs_path
        ]):
            logging.info('[*] Executing FS restore...')
            restore_fs(backup_args)
        else:
            backup_mode_fs(backup_args, time_stamp, manifest_meta_dict)
    elif backup_args.mode == 'mongo':
        backup_mode_mongo(backup_args, time_stamp, manifest_meta_dict)
    elif backup_args.mode == 'mysql':
        backup_mode_mysql(backup_args, time_stamp, manifest_meta_dict)
    else:
        logging.critical('[*] Error: Please provide a valid backup mode')
        raise ValueError

    remove_obj_older_than(backup_args)

    # Elapsed time:
    elapsed_time(today_start)
コード例 #7
0
ファイル: main.py プロジェクト: cere23/freezer
def freezer_main(backup_args):
    '''
    Program Main Execution. This main function is a wrapper for most
    of the other functions. By calling main() the program execution start
    and the respective actions are taken. If you want only use the single
    function is probably better to not import main()
    '''

    # Computing execution start datetime and Timestamp
    (time_stamp, today_start) = start_time()
    # Add timestamp to the arguments namespace
    backup_args.__dict__['time_stamp'] = time_stamp

    # Initialize the swift connector and store it in the same dict passed
    # as argument under the dict.sw_connector namespace. This is helpful
    # so the swift client object doesn't need to be initialized every time
    backup_args = get_client(backup_args)

    # Get the list of the containers
    backup_args = get_containers_list(backup_args)

    if show_containers(backup_args):
        elapsed_time(today_start)
        return True

    # Check if the provided container already exists in swift.
    # If it doesn't exist a new one will be created along with the segments
    # container as container_segments
    backup_args = check_container_existance(backup_args)

    # Get the object list of the remote containers and store id in the
    # same dict passes as argument under the dict.remote_obj_list namespace
    backup_args = get_container_content(backup_args)

    if show_objects(backup_args):
        elapsed_time(today_start)
        return True

    # Check if a backup exist in swift with same name. If not, set
    # backup level to 0
    manifest_meta_dict = check_backup_existance(backup_args)

    # Set the right backup level for incremental backup
    (backup_args, manifest_meta_dict) = set_backup_level(
        backup_args, manifest_meta_dict)

    backup_args.manifest_meta_dict = manifest_meta_dict
    # File system backup mode selected
    if backup_args.mode == 'fs':
        # If any of the restore options was specified, then a data restore
        # will be executed
        if validate_any_args([
            backup_args.restore_from_date, backup_args.restore_from_host,
                backup_args.restore_abs_path]):
            logging.info('[*] Executing FS restore...')
            restore_fs(backup_args)
        else:
            backup_mode_fs(backup_args, time_stamp, manifest_meta_dict)
    elif backup_args.mode == 'mongo':
        backup_mode_mongo(backup_args, time_stamp, manifest_meta_dict)
    elif backup_args.mode == 'mysql':
        backup_mode_mysql(backup_args, time_stamp, manifest_meta_dict)
    else:
        logging.critical('[*] Error: Please provide a valid backup mode')
        raise ValueError

    remove_obj_older_than(backup_args)

    # Elapsed time:
    elapsed_time(today_start)