def backup_keyspace(self, ks_backup): dest_path = os.path.join(self.args.meta_dir, ks_backup.backup_path) file_util.ensure_dir(os.path.dirname(dest_path)) with open(dest_path, "w") as f: f.write(json.dumps(ks_backup.serialise())) return
def restore_file(self, backup_file, dest_prefix): src_path = os.path.join(self.args.backup_base, backup_file.backup_path) dest_path = os.path.join(dest_prefix, backup_file.restore_path) file_util.ensure_dir(os.path.dirname(dest_path)) self.log.debug("Restoring file %s to %s", src_path, dest_path) with endpoints.TransferTiming(self.log, src_path, backup_file.component.stat.size): shutil.copy(src_path, dest_path) return dest_path
def validate_args(cls, args): if os.path.isfile(args.survey_path): return if os.path.exists(args.survey_path): raise argparse.ArgumentError("--survey-path", "Path exists and is not a file.") file_util.ensure_dir(os.path.dirname(args.survey_path)) file_util.ensure_dir(args.meta_dir) return
def backup_file(self, backup_file): """Writes the meta data and upates the survey log.""" msg = self.FILE_OP_PATTERN.format(time=dt_util.now_iso(), action="stored", src_path=backup_file.file_path, dest_path=backup_file.backup_path, bytes=backup_file.component.stat.size) self.log_file.write(msg) self.log_file.flush() dest_path = os.path.join(self.args.meta_dir, backup_file.backup_path) file_util.ensure_dir(os.path.dirname(dest_path)) with open(dest_path, "w") as f: f.write(json.dumps(backup_file.serialise())) return relative_dest_path
def backup_file(self, backup_file): dest_path = os.path.join(self.args.backup_base, backup_file.backup_path) file_util.ensure_dir(os.path.dirname(dest_path)) # Store the actual file with endpoints.TransferTiming(self.log, dest_path, backup_file.component.stat.size): shutil.copy(backup_file.file_path, dest_path) # Store the meta data dest_meta_path = dest_path + self._META_SUFFIX with open(dest_meta_path, "w") as f: f.write(json.dumps(backup_file.serialise())) return dest_path
def _should_restore(self): """Determines if the :attr:`backup_file` should be restored. """ dest_path = os.path.join(self.args.data_dir, self.backup_file.restore_path) if not os.path.exists(dest_path): # no file, lets restore return RestoreResult(should_restore=True, restore_reason="No File", restore_path=dest_path, source_path=self.backup_file.backup_path) if self.args.no_checksum: # exsisting file and no checksum, do not restore return RestoreResult( should_restore=True, restore_reason="Existing file (Not checksummed)", restore_path=dest_path, source_path=self.backup_file.backup_path) existing_md5 = file_util.file_md5(dest_path) if existing_md5 == self.backup_file.md5: return RestoreResult(should_restore=False, restore_reason="Existing file (Checksummed)", restore_path=dest_path, source_path=self.backup_file.backup_path) # move the current file to # $data_dir/../cassback-corrupt/keyspace/$file_name _, file_name = os.path.split(dest_path) corrupt_path = os.path.join(*(self.args.data_dir, "..", "cassback-corrupt", self.backup_file.component.keyspace, file_name)) file_util.ensure_dir(os.path.dirname(corrupt_path)) self.log.info("Moving existing corrupt file %s to %s", dest_path, corrupt_path) shutil.move(dest_path, corrupt_path) return RestoreResult(should_restore=True, restore_reason="Existing file corrupt", restore_path=dest_path, corrupt_path=corrupt_path, source_path=self.backup_file.backup_path)
def restore_file(self, backup_file, dest_prefix): """ """ key_name = backup_file.backup_path fqn = self._fqn(key_name) dest_path = os.path.join(dest_prefix, backup_file.restore_path) file_util.ensure_dir(os.path.dirname(dest_path)) self.log.debug("Starting to restore from %s:%s to %s", self.args.bucket_name, fqn, dest_path) key = self.bucket.get_key(fqn) if key is None: raise EnvironmentError(errno.ENOENT, fqn) timing = endpoints.TransferTiming(self.log, fqn, backup_file.component.stat.size) key.get_contents_to_filename(dest_path, cb=timing.progress, num_cb=timing.num_callbacks) return dest_path
def backup_file(self, backup_file): """Writes the meta data and upates the survey log.""" msg = self.FILE_OP_PATTERN.format( time=dt_util.now_iso(), action="stored", src_path=backup_file.file_path, dest_path=backup_file.backup_path, bytes=backup_file.component.stat.size) self.log_file.write(msg) self.log_file.flush() dest_path = os.path.join(self.args.meta_dir, backup_file.backup_path) file_util.ensure_dir(os.path.dirname(dest_path)) with open(dest_path, "w") as f: f.write(json.dumps(backup_file.serialise())) return relative_dest_path
def _should_restore(self): """Determines if the :attr:`backup_file` should be restored. """ dest_path = os.path.join(self.args.data_dir, self.backup_file.restore_path) if not os.path.exists(dest_path): # no file, lets restore return RestoreResult(should_restore=True, restore_reason="No File", restore_path=dest_path, source_path=self.backup_file.backup_path) if self.args.no_checksum: # exsisting file and no checksum, do not restore return RestoreResult(should_restore=True, restore_reason="Existing file (Not checksummed)", restore_path=dest_path, source_path=self.backup_file.backup_path) existing_md5 = file_util.file_md5(dest_path) if existing_md5 == self.backup_file.md5: return RestoreResult(should_restore=False, restore_reason="Existing file (Checksummed)", restore_path=dest_path, source_path=self.backup_file.backup_path) # move the current file to # $data_dir/../cassback-corrupt/keyspace/$file_name _, file_name = os.path.split(dest_path) corrupt_path = os.path.join(*(self.args.data_dir, "..", "cassback-corrupt", self.backup_file.component.keyspace, file_name)) file_util.ensure_dir(os.path.dirname(corrupt_path)) self.log.info("Moving existing corrupt file %s to %s", dest_path, corrupt_path) shutil.move(dest_path, corrupt_path) return RestoreResult(should_restore=True, restore_reason="Existing file corrupt", restore_path=dest_path, corrupt_path=corrupt_path, source_path=self.backup_file.backup_path)
def restore_file(self, backup_file, dest_prefix): fqn = self._fqn(backup_file.backup_path) dest_path = os.path.join(dest_prefix, backup_file.restore_path) file_util.ensure_dir(os.path.dirname(dest_path)) self.log.debug("Starting to restore from %s:%s to %s", self.args.bucket_name, fqn, dest_path) timing = endpoints.TransferTiming(self.log, fqn, backup_file.component.stat.size) try: self.bucket.download_file(fqn, backup_file.file_path, ExtraArgs=self.sse_options, Callback=timing.progress, Config=self.transfer_config) except botocore.exceptions.ClientError as e: if e.response['Error']['Code'] == "404": raise EnvironmentError(errno.ENOENT, fqn) raise return dest_path