コード例 #1
0
 def get_rel_path(path, root_path=ROOT_MOUNT):
     if not root_path:
         raise Error("You must specify root path or return pw!")
     relpath = os.path.relpath(path, root_path)
     relative_path = '/' + ('' if relpath == '.' else relpath)
     print("REL PATH %s , %s, %s" % (root_path, relpath, relative_path))
     return relative_path
コード例 #2
0
def get_all_quota_info(custom_path="/home"):
    command = [get_util("repquota"), "-v", "-c", "-u", custom_path]
    p = SubprocessRunner(command=command)
    p.run()

    out, err, returncode = p.wait(extended_return=True)

    if returncode not in [0, 1]:
        raise Error("Failed to get repquota info: %s %s %s" % (out, err, returncode))

    out_lines = out.split("\n")
    return_array = {}

    for line in out_lines:
        _fields = line.split()
        if len(_fields) > 1 and (_fields[1] == '--' or _fields[1] == '-+'):
            try:
                return_array[_fields[0]] = {
                    "BlockUsed": _fields[2].replace("*", ""),
                    "BlockSoft": _fields[3],
                    "BlockHard": _fields[4],
                    "FileUsed": _fields[5].replace("*", ""),
                    "FileSoft": _fields[6],
                    "FileHard": _fields[7]}
            except:
                pass

    return return_array
コード例 #3
0
def get_user_quota_info(login, custom_path="/home"):
    command = [get_util("quota"), "--hide-device", "--show-mntpoint", "-v", "-l", "-w", "-u", login]
    p = SubprocessRunner(command=command)
    p.run()

    out, err, returncode = p.wait(extended_return=True)

    if returncode not in [0, 1]:
        raise Error("Failed to get quota info: %s %s %s" % (out, err, returncode))

    out_lines = out.split("\n")

    fields = ['', '0', '0', '0', '0', '0', '0']
    mntpoint = find_mount_point(custom_path)

    for line in out_lines:
        _fields = line.split()

        if len(_fields) > 0 and _fields[0] == mntpoint:
            fields = _fields
            break

    return {
        "BlockUsed": fields[1].replace("*", ""),
        "BlockSoft": fields[2],
        "BlockHard": fields[3],
        "FileUsed": fields[4].replace("*", ""),
        "FileSoft": fields[5],
        "FileHard": fields[6]
    }
コード例 #4
0
ファイル: rsync.py プロジェクト: porutchik/domain_statistic
    def set_params_rsync_backup(self,
                                delete=True,
                                hardlinks_to=None,
                                log_format=None,
                                custom_options=[]):
        """
        Получаем команду для бекапа на удаленные сервера
        :type hardlinks_to: str|unicode|None
        :type log_format: str|unicode|None
        :type custom_options: list
        :return:
        """
        if type(custom_options) is not list:
            raise Error("custom_options must be a list")

        self.set_options(self.RSYNC_BACKUP_ARGUMENTS)

        if delete:
            self.set_option("delete")

        if log_format is not None:
            self.set_option("log-file-format", log_format)

        if hardlinks_to is not None:
            self.set_option("link-dest", hardlinks_to)

        self.set_options(self.RSYNC_BACKUP_EXCLUDE)

        if os.path.isfile("/etc/backup/exclude"):
            self.set_option("exclude-from", "/etc/backup/exclude")

        self.set_options(custom_options)
コード例 #5
0
ファイル: rsync.py プロジェクト: porutchik/domain_statistic
    def parse_stats(output):
        try:
            number_of_files = int(
                re.search('Number of files: (\d+)', output,
                          re.MULTILINE).group(1))
            total_file_size = int(
                re.search('Total file size: (\d+)', output,
                          re.MULTILINE).group(1))
            total_bytes_sent = int(
                re.search('Total bytes sent: (\d+)', output,
                          re.MULTILINE).group(1))

            return (number_of_files, total_file_size, total_bytes_sent)
        except:
            raise Error('Can`t parsing rsync output')
コード例 #6
0
ファイル: rsync.py プロジェクト: porutchik/domain_statistic
    def set_params_make_hardlink(self, hardlinks_to, custom_options):
        """
        Устанавливаем параметры для локального бекапа, c использованием хардлинков
        :type hardlinks_to: str|unicode
        :type custom_options: list
        :return:
        """

        if type(custom_options) is not list:
            raise Error("custom_options must be a list")

        self.set_options(self.HARDLINK_ARGUMENTS)
        self.set_options(["stats", "no-human-readable", "delete"])
        self.set_options(custom_options)
        if hardlinks_to is not None:
            self.set_option("link-dest", hardlinks_to)
コード例 #7
0
 def async_check_operation(op_status_id):
     operation = OperationStatus.load(op_status_id)
     logger.info("Operation id='%s' status is '%s'" %
                 (str(status_id), operation.status))
     if operation.status != OperationStatus.STATUS_WAIT:
         raise Error("Operation status is not wait - aborting")