コード例 #1
0
ファイル: tools.py プロジェクト: buhman/python-lunrclient
    def clone(self, id=None, src=None, backup=None, size=None):
        """
        This runs a clone job outside of the storage api,
        which is useful for performance testing backup restores
        (Example: storage tools clone volume-clone
          --backup volume-backup --src volume-original)
        """
        # Set basic Logging
        logging.basicConfig()
        # Get the lunr logger
        log = logger.get_logger()
        # Output Debug level info
        log.logger.setLevel(logging.DEBUG)
        # Load the local storage configuration
        conf = LunrConfig.from_storage_conf()
        # Init the volume helper
        volume = VolumeHelper(conf)

        # Attempt to figure out the original volume size
        size = size or str(volume.get(src)['size'] / 1073741824)
        # Size is in gigs
        if not re.match('G', size):
            size = size + 'G'
        # Create a tag to apply to the lvm volume
        tag = encode_tag(source_volume_id=src, backup_id=backup)
        # Create the volume
        execute('lvcreate', volume.volume_group,
                name=id, size=size, addtag=tag)
        # Get info for the newly created volume
        new = volume.get(id)

        with self.timeit():
            print("Starting Backup")
            # Restore volume from the backup
            volume.clone(new, src, backup)
コード例 #2
0
ファイル: tools.py プロジェクト: buhman/python-lunrclient
 def __init__(self):
     # Give our sub command a name
     self._name = 'tools'
     # Create a volume helper with our local storage config
     self.volume = VolumeHelper(LunrConfig.from_storage_conf())
     # let the base class setup methods in our class
     SubCommand.__init__(self)
     self.total = defaultdict(float)
コード例 #3
0
 def __init__(self):
     # Give our sub command a name
     self._name = 'tools'
     # Create a volume helper with our local storage config
     self.volume = VolumeHelper(LunrConfig.from_storage_conf())
     # let the base class setup methods in our class
     SubCommand.__init__(self)
     self.total = defaultdict(float)
コード例 #4
0
ファイル: test_config.py プロジェクト: rackerlabs/lunr
 def test_from_storage_conf(self):
     conf_str = dedent("""
         [DEFAULT]
         foo = bar
         """)
     with temp_disk_file(conf_str) as file:
         with patch(LunrConfig, 'lunr_storage_config', file):
             conf = LunrConfig.from_storage_conf()
             self.assertEquals(conf.lunr_storage_config, file)
             self.assertEquals(conf.string('default', '__file__', ''),
                               conf.lunr_storage_config)
             self.assertEquals(conf.string('default', 'foo', ''), 'bar')
コード例 #5
0
ファイル: test_config.py プロジェクト: pombredanne/lunr
 def test_from_storage_conf(self):
     conf_str = dedent(
         """
         [DEFAULT]
         foo = bar
         """
     )
     with temp_disk_file(conf_str) as file:
         with patch(LunrConfig, 'lunr_storage_config', file):
             conf = LunrConfig.from_storage_conf()
             self.assertEquals(conf.lunr_storage_config, file)
             self.assertEquals(conf.string('default', '__file__', ''),
                               conf.lunr_storage_config)
             self.assertEquals(conf.string('default', 'foo', ''), 'bar')
コード例 #6
0
ファイル: tools.py プロジェクト: buhman/python-lunrclient
    def backup(self, id=None, src=None, timestamp=None):
        """
        This runs a backup job outside of the storage api,
        which is useful for performance testing backups
        """
        # Set basic Logging
        logging.basicConfig()
        # Get the lunr logger
        log = logger.get_logger()
        # Output Debug level info
        log.logger.setLevel(logging.DEBUG)
        # Load the local storage configuration
        conf = LunrConfig.from_storage_conf()
        # If no time provided, use current time
        timestamp = timestamp or time()
        # Init our helpers
        volume = VolumeHelper(conf)
        backup = BackupHelper(conf)

        try:
            # Create the snapshot
            snapshot = volume.create_snapshot(src, id, timestamp)

            # For testing non-snapshot speeds
            #snapshot = volume.get(src)
            #snapshot['backup_id'] = id
            #snapshot['origin'] = src
            #snapshot['timestamp'] = 1338410885.0
            #del snapshot['volume']

            print("Created snap-shot: ", pprint(snapshot))

            with self.timeit(snapshot['size']):
                # Backup the snapshot
                print("Starting Backup")
                backup.save(snapshot, id)

        finally:
            # Delete the snapshot if it was created
            if 'snapshot' in locals():
                self._remove_volume(snapshot['path'])
コード例 #7
0
    def backup(self, id=None, src=None, timestamp=None):
        """
        This runs a backup job outside of the storage api,
        which is useful for performance testing backups
        """
        # Set basic Logging
        logging.basicConfig()
        # Get the lunr logger
        log = logger.get_logger()
        # Output Debug level info
        log.logger.setLevel(logging.DEBUG)
        # Load the local storage configuration
        conf = LunrConfig.from_storage_conf()
        # If no time provided, use current time
        timestamp = timestamp or time()
        # Init our helpers
        volume = VolumeHelper(conf)
        backup = BackupHelper(conf)

        try:
            # Create the snapshot
            snapshot = volume.create_snapshot(src, id, timestamp)

            # For testing non-snapshot speeds
            #snapshot = volume.get(src)
            #snapshot['backup_id'] = id
            #snapshot['origin'] = src
            #snapshot['timestamp'] = 1338410885.0
            #del snapshot['volume']

            print("Created snap-shot: ", pprint(snapshot))

            with self.timeit(snapshot['size']):
                # Backup the snapshot
                print("Starting Backup")
                backup.save(snapshot, id)

        finally:
            # Delete the snapshot if it was created
            if 'snapshot' in locals():
                self._remove_volume(snapshot['path'])
コード例 #8
0
    def clone(self, id=None, src=None, backup=None, size=None):
        """
        This runs a clone job outside of the storage api,
        which is useful for performance testing backup restores
        (Example: storage tools clone volume-clone
          --backup volume-backup --src volume-original)
        """
        # Set basic Logging
        logging.basicConfig()
        # Get the lunr logger
        log = logger.get_logger()
        # Output Debug level info
        log.logger.setLevel(logging.DEBUG)
        # Load the local storage configuration
        conf = LunrConfig.from_storage_conf()
        # Init the volume helper
        volume = VolumeHelper(conf)

        # Attempt to figure out the original volume size
        size = size or str(volume.get(src)['size'] / 1073741824)
        # Size is in gigs
        if not re.match('G', size):
            size = size + 'G'
        # Create a tag to apply to the lvm volume
        tag = encode_tag(source_volume_id=src, backup_id=backup)
        # Create the volume
        execute('lvcreate',
                volume.volume_group,
                name=id,
                size=size,
                addtag=tag)
        # Get info for the newly created volume
        new = volume.get(id)

        with self.timeit():
            print("Starting Backup")
            # Restore volume from the backup
            volume.clone(new, src, backup)