Ejemplo n.º 1
0
 def test_delete_with_missing_blocks(self):
     stats_path = os.path.join(self.scratch, 'stats')
     manifest = Manifest.blank(2)
     worker = Worker('foo',
                     LunrConfig({
                         'backup': {'client': 'memory'},
                         'storage': {'run_dir': self.scratch}
                     }),
                     manifest=manifest)
     conn = worker.conn
     conn.put_container('foo')
     backup = manifest.create_backup('bak1')
     backup[0] = worker.empty_block_hash
     backup[1] = 'some_random_block_that_isnt_uploaded'
     save_manifest(manifest, conn, worker.id, worker._lock_path())
     obj = conn.get_object('foo', 'manifest', newest=True)
     self.assertRaises(ClientException, conn.get_object,
                       'foo', backup[0], newest=True)
     self.assertRaises(ClientException, conn.get_object,
                       'foo', backup[1], newest=True)
     # Shouldn't blow up on 404.
     worker.delete('bak1')
     # Manifest should still be nicely deleted.
     self.assertRaises(ClientException, conn.get_object,
                       'foo', 'manifest', newest=True)
Ejemplo n.º 2
0
    def test_audit(self):
        manifest = Manifest.blank(2)
        worker = Worker('foo',
                        LunrConfig({
                            'backup': {'client': 'memory'},
                            'storage': {'run_dir': self.scratch}
                        }),
                        manifest=manifest)
        conn = worker.conn
        conn.put_container('foo')
        backup = manifest.create_backup('bak1')
        backup[0] = worker.empty_block_hash
        conn.put_object('foo', backup[0], 'zeroes')
        backup[1] = 'some_block_hash'
        conn.put_object('foo', backup[1], ' more stuff')
        save_manifest(manifest, conn, worker.id, worker._lock_path())
        # Add some non referenced blocks.
        conn.put_object('foo', 'stuff1', 'unreferenced stuff1')
        conn.put_object('foo', 'stuff2', 'unreferenced stuff2')
        conn.put_object('foo', 'stuff3', 'unreferenced stuff3')

        _headers, original_list = conn.get_container('foo')
        # Manifest, 2 blocks, 3 stuffs.
        self.assertEquals(len(original_list), 6)

        worker.audit()
        _headers, new_list = conn.get_container('foo')
        # Manifest, 2 blocks.
        self.assertEquals(len(new_list), 3)
Ejemplo n.º 3
0
    def save(self, snapshot, backup_id, cinder):
        job_stats_path = self._stats_file(snapshot['origin'])
        logger.rename('lunr.storage.helper.backup.save')
        setproctitle("lunr-save: " + backup_id)
        size = snapshot['size'] / 1024 / 1024 / 1024

        try:
            op_start = time()
            worker = Worker(snapshot['origin'],
                            conf=self.conf,
                            stats_path=job_stats_path)
        except exc.ClientException, e:
            if e.http_status != 404:
                raise
            op_start = time()
            conn = get_conn(self.conf)
            conn.put_container(snapshot['origin'])
            logger.warning("failed to retrieve manifest;"
                           " first time backup for this volume?")
            # TODO: write the block_size on the manifest at create?
            block_count, remainder = divmod(snapshot['size'], BLOCK_SIZE)
            if remainder:
                block_count += 1
            # initial backup is the only time the we need to worry about
            # creating a new manifest for the worker
            worker = Worker(snapshot['origin'],
                            conf=self.conf,
                            manifest=Manifest.blank(block_count),
                            stats_path=job_stats_path)
Ejemplo n.º 4
0
    def test_audit(self):
        manifest = Manifest.blank(2)
        worker = Worker('foo',
                        LunrConfig({
                            'backup': {
                                'client': 'memory'
                            },
                            'storage': {
                                'run_dir': self.scratch
                            }
                        }),
                        manifest=manifest)
        conn = worker.conn
        conn.put_container('foo')
        backup = manifest.create_backup('bak1')
        backup[0] = worker.empty_block_hash
        conn.put_object('foo', backup[0], 'zeroes')
        backup[1] = 'some_block_hash'
        conn.put_object('foo', backup[1], ' more stuff')
        save_manifest(manifest, conn, worker.id, worker._lock_path())
        # Add some non referenced blocks.
        conn.put_object('foo', 'stuff1', 'unreferenced stuff1')
        conn.put_object('foo', 'stuff2', 'unreferenced stuff2')
        conn.put_object('foo', 'stuff3', 'unreferenced stuff3')

        _headers, original_list = conn.get_container('foo')
        # Manifest, 2 blocks, 3 stuffs.
        self.assertEquals(len(original_list), 6)

        worker.audit()
        _headers, new_list = conn.get_container('foo')
        # Manifest, 2 blocks.
        self.assertEquals(len(new_list), 3)
Ejemplo n.º 5
0
 def test_salt_empty_blocks(self):
     vol1 = 'vol1'
     vol2 = 'vol2'
     manifest1 = Manifest()
     manifest2 = Manifest()
     conf = LunrConfig({'backup': {'client': 'memory'}})
     worker1 = Worker(vol1, conf, manifest1)
     worker2 = Worker(vol1, conf, manifest2)
     self.assert_(worker1.manifest.salt != worker2.manifest.salt)
     self.assert_(worker1.empty_block_hash != worker2.empty_block_hash)
     self.assertEquals(worker1.empty_block, worker2.empty_block)
Ejemplo n.º 6
0
    def list(self, volume):
        """
        Find all manifest in local cache, and running backups
        """
        results = {}

        # Might be a backup running for this volume not yet in the manifest
        running = self._is_a_backup_running(volume['id'])
        if running:
            results.update({running['id']: 'RUNNING'})

        try:
            manifest_file = Worker.build_lock_path(self.run_dir, volume['id'])
            manifest = read_local_manifest(manifest_file)
        except ManifestEmptyError:
            return results

        for backup_id in manifest.backups:
            if self._backup_is_running(volume['id'], backup_id):
                job = self.get(volume, backup_id)
                job['ts'] = manifest.backups.get(backup_id)
                manifest.backups[backup_id] = job

        results.update(manifest.backups)
        return results
Ejemplo n.º 7
0
Archivo: backup.py Proyecto: audip/lunr
    def list(self, volume):
        """
        Find all manifest in local cache, and running backups
        """
        results = {}

        # Might be a backup running for this volume not yet in the manifest
        running = self._is_a_backup_running(volume['id'])
        if running:
            results.update({running['id']: 'RUNNING'})

        try:
            manifest_file = Worker.build_lock_path(self.run_dir, volume['id'])
            manifest = read_local_manifest(manifest_file)
        except ManifestEmptyError:
            return results

        for backup_id in manifest.backups:
            if self._backup_is_running(volume['id'], backup_id):
                job = self.get(volume, backup_id)
                job['ts'] = manifest.backups.get(backup_id)
                manifest.backups[backup_id] = job

        results.update(manifest.backups)
        return results
Ejemplo n.º 8
0
 def audit(self, volume):
     logger.rename('lunr.storage.helper.backup.audit')
     setproctitle("lunr-audit: " + volume['id'])
     try:
         op_start = time()
         worker = Worker(volume['id'], self.conf)
     except exc.ClientException, e:
         if e.http_status != 404:
             raise
         op_start = time()
         conn = get_conn(self.conf)
         conn.put_container(volume['id'])
         logger.warning("failed to retrieve manifest;"
                        " auditing volume with no backups")
         # creating a blank manifest for the worker
         worker = Worker(volume['id'],
                         conf=self.conf,
                         manifest=Manifest.blank(0))
Ejemplo n.º 9
0
 def restore(self, dest_volume, backup_source_volume_id,
             backup_id, size, cinder):
     op_start = time()
     logger.rename('lunr.storage.helper.volume.restore')
     setproctitle("lunr-restore: " + dest_volume['id'])
     job_stats_path = self._stats_file(dest_volume['id'])
     worker = Worker(backup_source_volume_id, conf=self.conf,
                     stats_path=job_stats_path)
     try:
         worker.restore(backup_id, dest_volume['path'],
                        dest_volume['id'], cinder)
     finally:
         os.unlink(job_stats_path)
     self.update_tags(dest_volume, {})
     duration = time() - op_start
     logger.info('STAT: Restore %r from %r. '
                 'Size: %r GB Time: %r s Speed: %r MB/s' %
                 (dest_volume['id'], backup_id, size, duration,
                  size * 1024 / duration))
Ejemplo n.º 10
0
 def restore(self, dest_volume, backup_source_volume_id,
             backup_id, size, cinder):
     op_start = time()
     logger.rename('lunr.storage.helper.volume.restore')
     setproctitle("lunr-restore: " + dest_volume['id'])
     job_stats_path = self._stats_file(dest_volume['id'])
     worker = Worker(backup_source_volume_id, conf=self.conf,
                     stats_path=job_stats_path)
     try:
         worker.restore(backup_id, dest_volume['path'],
                        dest_volume['id'], cinder)
     finally:
         os.unlink(job_stats_path)
     self.update_tags(dest_volume, {})
     duration = time() - op_start
     logger.info('STAT: Restore %r from %r. '
                 'Size: %r GB Time: %r s Speed: %r MB/s' %
                 (dest_volume['id'], backup_id, size, duration,
                  size * 1024 / duration))
Ejemplo n.º 11
0
    def test_save_stats(self):
        manifest = Manifest.blank(2)
        stats_path = os.path.join(self.scratch, 'statsfile')
        worker = Worker('foo',
                        LunrConfig({
                            'backup': {'client': 'memory'},
                            'storage': {'run_dir': self.scratch}
                        }),
                        manifest=manifest,
                        stats_path=stats_path)
        conn = worker.conn
        conn.put_container('foo')

        worker.save('/dev/zero', 'backup_id', timestamp=1)

        try:
            with open(stats_path) as f:
                json.loads(f.read())
        except ValueError:
            self.fail("stats path does not contain valid json")
Ejemplo n.º 12
0
 def test_delete_with_missing_blocks(self):
     stats_path = os.path.join(self.scratch, 'stats')
     manifest = Manifest.blank(2)
     worker = Worker('foo',
                     LunrConfig({
                         'backup': {
                             'client': 'memory'
                         },
                         'storage': {
                             'run_dir': self.scratch
                         }
                     }),
                     manifest=manifest)
     conn = worker.conn
     conn.put_container('foo')
     backup = manifest.create_backup('bak1')
     backup[0] = worker.empty_block_hash
     backup[1] = 'some_random_block_that_isnt_uploaded'
     save_manifest(manifest, conn, worker.id, worker._lock_path())
     obj = conn.get_object('foo', 'manifest', newest=True)
     self.assertRaises(ClientException,
                       conn.get_object,
                       'foo',
                       backup[0],
                       newest=True)
     self.assertRaises(ClientException,
                       conn.get_object,
                       'foo',
                       backup[1],
                       newest=True)
     # Shouldn't blow up on 404.
     worker.delete('bak1')
     # Manifest should still be nicely deleted.
     self.assertRaises(ClientException,
                       conn.get_object,
                       'foo',
                       'manifest',
                       newest=True)
Ejemplo n.º 13
0
    def prune(self, volume, backup_id):
        logger.rename('lunr.storage.helper.backup.prune')
        setproctitle("lunr-prune: " + backup_id)

        try:
            op_start = time()
            worker = Worker(volume['id'], self.conf)
        except exc.ClientException, e:
            # If the manifest doesn't exist, We consider the backup deleted.
            # If anything else happens, we bail.
            if e.http_status != 404:
                raise
            logger.warning('No manifest found pruning volume: %s' %
                           volume['id'])
            return
Ejemplo n.º 14
0
    def test_save_stats(self):
        manifest = Manifest.blank(2)
        stats_path = os.path.join(self.scratch, 'statsfile')
        worker = Worker('foo',
                        LunrConfig({
                            'backup': {
                                'client': 'memory'
                            },
                            'storage': {
                                'run_dir': self.scratch
                            }
                        }),
                        manifest=manifest,
                        stats_path=stats_path)
        conn = worker.conn
        conn.put_container('foo')

        worker.save('/dev/zero', 'backup_id', timestamp=1)

        try:
            with open(stats_path) as f:
                json.loads(f.read())
        except ValueError:
            self.fail("stats path does not contain valid json")