Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/archiver/copier.py
Show All 10 Lines | class ArchiverCopier(): | ||||
""" This archiver copy some files into a remote objstorage | """ This archiver copy some files into a remote objstorage | ||||
in order to get a backup. | in order to get a backup. | ||||
Attributes: | Attributes: | ||||
content_ids: A list of sha1's that represents the content this copier | content_ids: A list of sha1's that represents the content this copier | ||||
has to archive. | has to archive. | ||||
server (RemoteArchive): The remote object storage that is used to | server (RemoteArchive): The remote object storage that is used to | ||||
backup content. | backup content. | ||||
master_storage (Storage): The master storage that contains the data | master_objstorage (ObjStorage): The master storage that contains the | ||||
the copier needs to archive. | data the copier needs to archive. | ||||
""" | """ | ||||
def __init__(self, destination, content, master_storage): | def __init__(self, destination, content, master_objstorage): | ||||
""" Create a Copier for the archiver | """ Create a Copier for the archiver | ||||
Args: | Args: | ||||
destination: A tuple (archive_name, archive_url) that represents a | destination: A tuple (archive_name, archive_url) that represents a | ||||
remote object storage as in the 'archive' table. | remote object storage as in the 'archive' table. | ||||
content: A list of sha1 that represents the content this copier | content: A list of sha1 that represents the content this copier | ||||
have to archive. | have to archive. | ||||
master_storage (Storage): The master storage of the system that | master_storage (Storage): The master storage of the system that | ||||
contains the data to archive. | contains the data to archive. | ||||
""" | """ | ||||
_name, self.url = destination | _name, self.url = destination | ||||
self.content_ids = content | self.content_ids = content | ||||
self.server = RemoteObjStorage(self.url) | self.server = RemoteObjStorage(self.url) | ||||
self.master_storage = master_storage | self.master_objstorage = master_objstorage | ||||
def run(self): | def run(self): | ||||
""" Do the copy on the backup storage. | """ Do the copy on the backup storage. | ||||
Run the archiver copier in order to copy the required content | Run the archiver copier in order to copy the required content | ||||
into the current destination. | into the current destination. | ||||
The content which corresponds to the sha1 in self.content_ids | The content which corresponds to the sha1 in self.content_ids | ||||
will be fetched from the master_storage and then copied into | will be fetched from the master_storage and then copied into | ||||
the backup object storage. | the backup object storage. | ||||
Returns: | Returns: | ||||
A boolean that indicates if the whole content have been copied. | A boolean that indicates if the whole content have been copied. | ||||
""" | """ | ||||
self.content_ids = list(map(lambda x: hashutil.hex_to_hash(x[2:]), | self.content_ids = map(lambda x: hashutil.hex_to_hash(x[2:]), | ||||
self.content_ids)) | self.content_ids) | ||||
contents = self.master_storage.content_get(self.content_ids) | |||||
try: | try: | ||||
for content in contents: | for content_id in self.content_ids: | ||||
content_data = content['data'] | content = self.master_objstorage.get(content_id) | ||||
self.server.content_add(content_data) | self.server.content_add(content, content_id) | ||||
except: | except: | ||||
return False | return False | ||||
return True | return True |