Esempio n. 1
0
    def remove_file(self, relative_path, dry_run=False):

        path = os.path.join(self.args.meta_dir, relative_path)
        restore_file = self.read_backup_file(relative_path)

        if dry_run:
            return path

        # If no size do not add to the survey,
        # it's probably not a file with meta data.
        # e.g. we are deleting a manifest
        if size is not None:
            msg = self.FILE_OP_PATTERN.format(
                time=dt_util.now_iso(),
                action="removed",
                src_path=relative_path,
                dest_path="na",
                bytes=restore_file.component.stat.size)

            self.log_file.write(msg)
            self.log_file.flush()

        os.remove(path)
        file_util.maybe_remove_dirs(os.path.dirname(path))
        return relative_path
Esempio n. 2
0
 def restore_file(self, backup_file, dest_prefix):
     
     dest_path = os.path.join(dest_prefix, backup_file.restore_path)
     msg = self.FILE_OP_PATTERN.format(time=dt_util.now_iso(), 
         action="restored", src_path=backup_file, 
         dest_path=dest_path, 
         bytes=backup_file.component.stat.size)
     self.log_file.write(msg)
     self.log_file.flush()
     return
Esempio n. 3
0
    def restore_file(self, backup_file, dest_prefix):

        dest_path = os.path.join(dest_prefix, backup_file.restore_path)
        msg = self.FILE_OP_PATTERN.format(
            time=dt_util.now_iso(),
            action="restored",
            src_path=backup_file,
            dest_path=dest_path,
            bytes=backup_file.component.stat.size)
        self.log_file.write(msg)
        self.log_file.flush()
        return
Esempio n. 4
0
 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
Esempio n. 5
0
    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
Esempio n. 6
0
 def remove_file(self, relative_path, dry_run=False):
     
     path = os.path.join(self.args.meta_dir, relative_path)
     restore_file = self.read_backup_file(relative_path)
     
     if dry_run:
         return path
         
     # If no size do not add to the survey, 
     # it's probably not a file with meta data.
     # e.g. we are deleting a manifest
     if size is not None:
         msg = self.FILE_OP_PATTERN.format(time=dt_util.now_iso(), 
             action="removed", src_path=relative_path, 
             dest_path="na", 
             bytes=restore_file.component.stat.size)
         
         self.log_file.write(msg)
         self.log_file.flush()
     
     os.remove(path)
     file_util.maybe_remove_dirs(os.path.dirname(path))
     return relative_path