GIF89a=( �' 7IAXKgNgYvYx\%wh&h}t�h%�s%x�}9�R��&�0%� (�.��5�SD��&�a)�x5��;ͣ*ȡ&ղ)ׯ7׵<ѻ4�3�H֧KͯT��Y�aq��q��F� !� ' !� NETSCAPE2.0 , =( ��pH,�Ȥr�l:xШtJ�Z�جv��z��xL.:��z�n���|N�����~�������& !�0`9R�}��"�"a:S�~x��������g���E�������R���E����B�� ��ȸ��D���"�Ů� �H��L��D٫D�B�����D���T���H �G��A R�ڐ |�� ٭&��E8�S�kG�A�px�a��� R2XB��E8I���6X�:vT)�~��q�賥��"F~%x� � 4#Z�0O|-4Bs�X:= Q� Sal��yXJ`GȦ|s h��K3l7�B|�$'7Jީܪ0!��D�n=�P� ����0`�R�lj����v>���5 �.69�ϸd�����nlv�9��f{���Pbx �l5}�p� ��� �3a���I�O����!ܾ���i��9��#��)p�a ޽ �{�)vm��%D~ 6f��s}Œ�D�W E�`!� �&L8x� �ܝ{)x`X/>�}m��R�*|`D�=�_ ^�5 !_&'a�O�7�c��`DCx`�¥�9�Y�F���`?��"� �n@`�} lď��@4>�d S �v�xN��"@~d��=�g�s~G��� ���ud &p8Q�)ƫlXD����A~H�ySun�j���k*D�LH�] ��C"J��Xb~ʪwSt}6K,��q�S:9ت:���l�@�`�� �.۬�t9�S�[:��=`9N����{¿�A !R�:���6��x�0�_ �;������^���#����!����U���;0L1�����p% A��U̬ݵ��%�S��!���~`�G���� ���=4�np�3���������u�u�ٮ|%2�I��r�#0��J``8�@S@5� ���^`8E�]�.�S���7 � �0�j S�D� z���i�S�����!���l��w9*�D�I�nEX��� &A�Go�Qf��F��;���}�J����F5��Q|���X��T��y���]� o ��C=��:���PB@ D׽S�(>�C�x}`��xJЬ�۠��p+eE0`�}`A �/NE�� �9@��� H�7�!%B0`�l*��!8 2�%� �:�1�0E��ux%nP1�!�C)�P81l�ɸF#Ƭ{����B0>�� �b�`��O3��()yRpb��E.ZD8�H@% �Rx+%���c� ���f��b�d�`F�"8�XH"��-�|1�6iI, 2�$+](A*j� QT�o0.�U�`�R�}`�SN����yae�����b��o~ S)�y�@��3 �tT�0�&�+~L�f"�-|�~��>!�v��~�\Q1)}@�}h#aP72�"�$ !� " , =( &7IAXG]KgNgYvYxR"k\%w]'}h}t�h%�g+�s%r.m3ax3�x�}9��&��+�!7�0%� (�.�SD��&��;�"&ײ)׻4��6�K� �@pH,�Ȥr�l:xШtJ�Z�جv��z��xL.:��z�n���|N�����~�������& !�0`9R�}��"�"a:S�~x��������g �� E �� �������E �´��C���ǶR��D��"Ʒ�ʱH��M��GڬD�B����D��T����G���C�C� l&�~:'�tU�6ɹ#��)�'�.6�&��Ȼ K(8p0N�?!�2"��NIJX>R��OM '��2�*x�>#n� �@<[:�I�f ��T���Cdb��[�}E�5MBo��@�`@��tW-3 �x�B���jI�&E�9[T&$��ﯧ&"s��ȳ����dc�UUρ#���ldj?����`\}���u|3'�R]�6 �S#�!�FKL�*N E���`$�:e�YD�q�.�촁�s \-�jA 9�����-��M[�x(�s��x�|���p��}k�T�DpE@W� ��]k`1� ���Yb ��0l��*n0��"~zBd�~u�7�0Bl��0-�x~|U�U0 �h�*HS�|��e"#"?vp�i`e6^�+q��`m8 #V�� ��VS|`��"m"сSn|@:U���~`pb�G�ED����2F�I�? >�x� R� ��%~jx��<�a�9ij�2�D��&: Z`�]w���:�6��B�7eFJ|�ҧ�,���FǮcS�ʶ+B�,�ܺN���>PAD�HD��~���n��}�#�� Q��S���2�X�{�k�lQ�2�����w�|2� h9��G�,m���3��6-��E�L��I�³*K���q�`DwV�QXS��peS��� qܧTS����R�u �<�a�*At�lmE� � ��N[P1�ۦ��$��@`��Dpy�yXvCAy�B`}D� 0QwG#� �a[^�� $���Ǧ{L�"[��K�g�;�S~��GX.�goT.��ư��x���?1z��x~:�g�|�L� ��S`��0S]P�^p F<""�?!,�!N4&P� ����:T�@h�9%t��:�-~�I<`�9p I&.)^ 40D#p@�j4�ج:�01��rܼF2oW�#Z ;$Q q  �K��Nl#29 !F@�Bh�ᏬL!XF�LHKh�.�hE&J�G��<"WN!�����Y@� >R~19J"�2,/ &.GXB%�R�9B6�W]���W�I�$��9�RE8Y� ��"�A5�Q.axB�&ة�J�! �t)K%tS-�JF b�NMxL��)�R��"���6O!TH�H� 0 !� ) , =( &AXKgNgYvYxR"k\%wh&h}h%�g+�s%r.x3�x�}9��&��+�R,�!7�0%� (�.��5��&�a)��;�"&ף*Ȳ)ׯ7׻4�3��6�H֧KͻH�T��Y��q��h� ��pH,�Ȥr�l:xШtJ�Z�جv��z��xL.:��z�n���|N�����~�������& !�0`9R�}��"�"a:S�~x��������g �� E$����� � ����$E$��"��D� � ������R��C��� E ��H�M��G�D� �B��ϾD��a��`1r��Ӑ�� �o~�zU!L�C'�yW�UGt����ll�0���uG�)A�s[��x� �xO%��X2�  P�n:R/��aHae+�Dm?# ǣ6�8�J�x�Di�M���j���5oQ7�- <! *�l��R2r/a!l)d� A"�E���� &� ;��c �%����b��pe~C"B���H�eF2��`8qb�t_`ur`e� w�u3��Pv�h""�`�Íx�LĹ��3� �~ֺ�:���MDfJ� �۵�W�%�S�X �؁)�@��:E��w�u�Sxb8y\m�zS��Zb�E�L��w!y(>�"w�=�|��s�d �C�W)H�cC$�L �7r.�\{)@�`@ �X�$PD `aaG:���O�72E�amn]�"Rc�x�R� &dR8`g��i�xLR!�P &d����T���i�|�_ � Qi�#�`g:��:noM� :V �)p����W&a=�e�k� j���1߲s�x�W�jal|0��B0�, \j۴:6���C ��W��|��9���zĸV {�;��n��V�m�I��.��PN� ����C��+��By�ѾHŸ:��� 7�Y�FTk�SaoaY$D�S���29R�kt� ��f� ��:��Sp�3�I��DZ� �9���g��u�*3)O��[_hv ,���Et x�BH� �[��64M@�S�M7d�l�ܶ5-��U܍��z�R3Ԭ3~ ��P��5�g: ���kN�&0�j4���#{��3S�2�K�'ợl���2K{� {۶?~m𸧠�I�nE�='����^���_�=��~�#O���'���o..�Y�n��CSO��a��K��o,���b�����{�C�� "�{�K ��w��Ozdը�:$ ���v�] A#� ���a�z)Rx׿ƥ�d``�w-�y�f�K!����|��P��=�`�(f��'Pa ��BJa%��f�%`�}F����6>��`G"�}�=�!o`�^FP�ةQ�C���`(�}\�ݮ ��$<��n@dĠE#��U�I�!� #l��9`k���'Rr��Z�NB�MF �[�+9���-�wj���8�r� ,V�h"�|�S=�G_��"E� 0i*%̲��da0mVk�):;&6p>�jK ��# �D�:�c?:R Ӭf��I-�"�<�="��7�3S��c2RW ,�8(T"P0F¡Jh�" ; 403WebShell
403Webshell
Server IP : 173.249.157.85  /  Your IP : 18.191.89.16
Web Server : Apache
System : Linux server.frogzhost.com 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020 x86_64
User : econtech ( 1005)
PHP Version : 7.3.33
Disable Function : NONE
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/Acronis/BackupAndRecovery/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/Acronis/BackupAndRecovery/post_mount.py
#!/usr/sbin/acropsh

import re
import os
import stat
import subprocess
import sys
from optparse import OptionParser
import time
import signal
from collections import defaultdict
import zlib
import abc

# path-name: //var/lib/Acronis/mount/{crc32(arch)-timestamp}_{cont_id}_{pit}_{index}

VERBOSE = True
ACRONIS_DIR = "/var/lib/Acronis"
MOUNT_DIR_DEFAULT = "/var/lib/Acronis/mount"
IOSTAMP_DIR = "/var/lib/Acronis/IOStamp"
DEV_DIR = "/dev"
TI_MNT_NONE = "none"
CONTAINER_ID_NONE = "0"
FS_NONE = "none"
FS_XFS = "xfs"
FS_EXT3 = "ext3"
FS_EXT4 = "ext4"
FS_FAT = "vfat"
FS_NTFS = "ntfs"
MOUNT_OPT_NOATIME = "noatime"
MOUNT_OPT_NOUUID = "nouuid"
MOUNT_OPT_NOINIT_ITABLE = "noinit_itable"
MOUNT_DIR = os.getenv("ACRONIS_MOUNT_DIR", MOUNT_DIR_DEFAULT)
DOES_JOURNALING = os.getenv("ACRONIS_MOUNT_JOURNALING", False)


def log(arg):
    global VERBOSE
    if VERBOSE:
        print(arg)


def outprint(arg):
    print(arg)


class MntDevMgr(object):
    """ Mount Device Manager """
    __metaclass__ = abc.ABCMeta

    def __init__(self, options):
        self.archive = options.archive
        self.pit = options.pit
        self.index = options.index
        self.device = options.device
        self.fstype = options.fstype

    @staticmethod
    def extract_name(device):
        """ Extract device name from '/dev/xxx' -> 'xxx' """
        if not device:
            return device
        return device.split("/")[-1]

    @staticmethod
    def execute(cmd):
        log("Executing: " + cmd)
        p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = p.communicate()
        p.wait()
        out = stdout.splitlines()
        err = stderr.splitlines()
        log("ret={0}".format(p.returncode)) 
        log("out={0}".format(out))
        log("err={0}".format(err))
        return p.returncode, out, err

    @staticmethod
    def build_mount_folder(arch, cid, pit, index):
        return "{0}/{1}-{2}_{3}_{4}_{5}".format(MOUNT_DIR, format(zlib.crc32(arch.encode()) % (1 << 32), 'x'), int(time.time() * 1000), cid, pit, index)

    @staticmethod
    def print_device(device):
        outprint("DEVICE:{0}".format(device))

    @staticmethod
    def print_mount_dir(mount_dir):
        outprint("MNTDIR:{0}".format(mount_dir))

    @staticmethod
    def dev_timestamp(device, timestamp_type):
        try:
            if timestamp_type == "ctime":
                return int(os.stat(device).st_ctime)
            with open("{0}/{1}".format(IOSTAMP_DIR, MntDevMgr.extract_name(device))) as f:
                s_stamp = f.read().replace('\n', '')
                return int(s_stamp)
        except Exception as ex:
            print("Error {0}".format(ex))
        return None

    @staticmethod
    def get_idle(stamp):
        if stamp is None:
            raise ValueError("Timestamp is 'None'")
        t = int(time.time())
        return max(0, t - stamp)

    @staticmethod
    def dev_idle_time(device, timestamp_type):
        stamp = MntDevMgr.dev_timestamp(device, timestamp_type)
        return MntDevMgr.get_idle(stamp)

    @staticmethod
    def get_max_timestamp(devices, timestamp_type):
        return max([0] + [MntDevMgr.dev_timestamp(dev["dev"], timestamp_type) for dev in devices])

    @staticmethod
    def dev2obj(elem):
        mount_point = elem[1]
        components = MntDevMgr.extract_name(mount_point).split("_")
        cid = CONTAINER_ID_NONE
        pit = "0"
        if len(components) > 1 and len(components[1]) > 0:
            cid = components[1]
        if len(components) > 2 and len(components[2]) > 0:
            pit = components[2]
        arch = ""
        fstype = ""
        majmin = ""
        pid = ""
        index = ""
        if len(elem) >= 6:
            arch = elem[2]
            fstype = elem[3]
            majmin = elem[4]
            pid = elem[5]
            index = elem[6]
        return {
                    'dev': elem[0],
                    'mpoint': elem[1],
                    'arch': arch,
                    'fstype': fstype,
                    'majmin': majmin,
                    'pid': pid,
                    'index': index,
                    'cid': cid,
                    'pit': pit
                }

    @staticmethod
    def get_devices(key):
        devices = []
        ret, out, _ = MntDevMgr.execute("trueimagemnt {0}".format(key))
        if ret != 0:
            raise SystemError("Error code: {0}".format(ret))
        for elem in out:
            components = elem.decode().split(" ")
            devices.append(MntDevMgr.dev2obj(components))
        return devices

    @staticmethod
    def get_used_devices():
        return MntDevMgr.get_devices("--list")

    @staticmethod
    def get_orphaned_devices():
        return MntDevMgr.get_devices("--list-orphanes")

    @staticmethod
    def stop_service(pid):
        MntDevMgr.execute("trueimagemnt --stop {0}".format(pid))

    @staticmethod
    def daemon_status(pid):
        try:
            with open("/proc/{0}/cmdline".format(pid)) as f:
                cmdline = f.read()
                if "TrueImageMountDemonBin" in cmdline:
                    return True
        except Exception as ex:
            print("Error {0}".format(ex))
        return False

    @staticmethod
    def get_devices_groupped_by_pid():
        devices = MntDevMgr.get_used_devices()
        pids = defaultdict(list)
        for dev in devices:
            pids[dev['pid']].append(dev)
        return dict(pids)

    @staticmethod
    def status_str(b):
        return "On" if b else "Off"

    @abc.abstractmethod
    def get_mount_folder(self):
        pass

    @abc.abstractmethod
    def mount_prepare(self, folder):
        pass

    @abc.abstractmethod
    def umount_done(self, folder):
        pass

    @abc.abstractmethod
    def create_folder(self, folder):
        pass

    @abc.abstractmethod
    def mount_to_folder(self, folder):
        pass

    @abc.abstractmethod
    def remove_folder(self, folder):
        pass

    @abc.abstractmethod
    def umount_from_folder(self, folder):
        pass

    @abc.abstractmethod
    def check_folder_is_mount(self, folder):
        pass

    @abc.abstractmethod
    def check_folder_is_busy(self, folder):
        pass

    def equal_dev(self, dev):
        return self.pit == dev['pit']

    def get_mount_options(self):
        opts = [MOUNT_OPT_NOATIME]
        if self.fstype == FS_XFS:
            opts.append(MOUNT_OPT_NOUUID)
        if self.fstype == FS_EXT4:
            opts.append(MOUNT_OPT_NOINIT_ITABLE)
        return opts

    def get_mount_options_with_key(self):
        opts = self.get_mount_options()
        return "-o " + ",".join(opts) if opts else ""

    def journal_if_needed(self):
        if self.fstype not in [FS_EXT3, FS_EXT4]:
            return
        # check if journaling was enabled
        _, out, _ = self.execute("tune2fs -l {0}".format(self.device))
        if "has_journal" not in out:
            return
        # does the journaling
        self.execute("e2fsck -p -E journal_only {0}".format(self.device))
        # switch journaling off
        self.execute("tune2fs -O ^has_journal {0}".format(self.device))

    def mount(self):
        self.print_device(self.device)
        log("mounting device {0}".format(self.device))
        if self.fstype in [FS_NONE, FS_FAT, FS_NTFS]:
            log("skipped mounting a device with '{0}' file system".format(self.fstype))
            return
        if DOES_JOURNALING:
            self.journal_if_needed()
        folder = self.get_mount_folder()
        self.mount_prepare(folder)
        if self.mount_to_folder(folder):
            self.print_mount_dir(folder)
        else:
            self.remove_folder(folder)

    def umount_device(self, dev):
        if self.umount_from_folder(dev['mpoint']):
            self.umount_done(dev['mpoint'])
            return True
        return False

    def umount_device_with_check(self, dev):
        if self.check_device_is_mount(dev):
           return self.umount_device(dev)
        return True

    def check_devices_is_umount(self, devices, silent=True):
        for dev in devices:
            if self.check_device_is_mount(dev, silent):
                return False
        return True

    def check_device_is_mount(self, dev, silent=True):
        folder = dev['mpoint']
        if self.check_folder_is_mount(folder):
            if not silent:
                self.print_mount_dir(folder)
            return True
        return False

    def check_device_is_busy(self, dev):
        if not self.check_device_is_mount(dev):
            return False
        return self.check_folder_is_busy(dev['mpoint'])

    def status(self):
        devices = MntDevMgr.get_used_devices()
        for dev in devices:
            if self.pit is None or self.equal_dev(dev):
                self.print_device(dev['dev'])
                self.check_device_is_mount(dev, False)


class HostMntDevMgr(MntDevMgr):
    def __init__(self, options):
        super(HostMntDevMgr, self).__init__(options)

    def get_mount_folder(self):
        return self.build_mount_folder(self.archive, CONTAINER_ID_NONE, self.pit, self.index)

    def mount_prepare(self, folder):
        if os.environ.get('ACRONIS_ENABLE_FSCK_BEFORE_MOUNT', 0) == '1':
            self.execute("fsck -y {0}".format(self.device))
        self.create_folder(folder)

        if MOUNT_DIR == MOUNT_DIR_DEFAULT:
            log("Reset 751 for {0}".format(ACRONIS_DIR))
            self.execute("chmod 751 {0}".format(ACRONIS_DIR))
        else:
            log("Reset 751 for {0}".format(MOUNT_DIR))
            self.execute("chmod 751 {0}".format(MOUNT_DIR))

    def umount_done(self, folder):
        self.remove_folder(folder)

    def create_folder(self, folder):
        self.execute("mkdir -p {0}".format(folder))

    def mount_to_folder(self, folder):
        ret, _, _ = self.execute("mount {0} {1} {2}".format(self.get_mount_options_with_key(), self.device, folder))
        return ret == 0

    def remove_folder(self, folder):
        self.execute("rm -rf {0}".format(folder))

    def umount_from_folder(self, folder):
        self.execute("umount {0}".format(folder))
        return not self.check_folder_is_mount(folder)

    def check_folder_is_mount(self, folder):
        ret, _, _ = self.execute("mountpoint {0}".format(folder))
        return ret == 0

    def check_folder_is_busy(self, folder):
        ret, _, _ = self.execute("fuser -vm {0}".format(folder))
        return ret == 0


class VzCtMntDevMgr(MntDevMgr):
    def __init__(self, options, cont_id):
        super(VzCtMntDevMgr, self).__init__(options)
        self.cont_id = cont_id if cont_id != CONTAINER_ID_NONE else options.cont_id

    def get_mount_folder(self):
        return self.build_mount_folder(self.archive, self.cont_id, self.pit, self.index)

    def mount_prepare(self, folder):
        self.create_folder(folder)
        log("Reset 751 for {0}".format(MOUNT_DIR))
        self.execute("vzctl exec {0} chmod 751 {1}".format(self.cont_id, MOUNT_DIR))

    def umount_done(self, folder):
        self.remove_folder(folder)

    def create_folder(self, folder):
        self.execute("mkdir -p {0}".format(folder))
        self.execute("vzctl exec {0} mkdir -p {1}".format(self.cont_id, folder))

    def mount_to_folder(self, folder):
        if not self._check_folder_is_mount_host(folder):
            self.execute("mount {0} {1} {2}".format(self.get_mount_options_with_key(), self.device, folder))
        # Virtuozzo 7.5
        ret, _, _ = self.execute("vzctl set {0} --save --bindmount_add {1}:{2}".format(self.cont_id, folder, folder))
        if ret != 0:
            # Fallback for VZ < 7.5
            ret_bind, _, _ = self.execute("mount -o bind {0} /vz/root/{1}/{2}".format(folder, self.cont_id, folder))
            return ret_bind == 0
        return True

    def remove_folder(self, folder):
        self.execute("rm -rf {0}".format(folder))
        self.execute("vzctl exec {0} rm -rf {1}".format(self.cont_id, folder))

    def umount_from_folder(self, folder):
        # Virtuozzo 7.5
        ret, _, _ = self.execute("vzctl set {0} --save --bindmount_del {1}".format(self.cont_id, folder))

        check_mount_cont = False
        if ret != 0:
            # Fallback for VZ < 7.5
            self.execute("umount /vz/root/{0}/{1}".format(self.cont_id, folder))
            check_mount_cont = self.check_folder_is_mount(folder)

        check_mount_host = self._check_folder_is_mount_host(folder)
        if check_mount_host:
            self.execute("umount {0}".format(folder))
            check_mount_host = self._check_folder_is_mount_host(folder)
        return not check_mount_cont and not check_mount_host

    def _check_folder_is_mount_host(self, folder):
        ret, _, _ = self.execute("mountpoint {0}".format(folder))
        return ret == 0

    def check_folder_is_mount(self, folder):
        ret, _, _ = self.execute("vzctl exec {0} mountpoint {1}".format(self.cont_id, folder))
        return ret == 0

    def check_folder_is_busy(self, folder):
        ret, _, _ = self.execute("vzctl exec {0} fuser -vm {1}".format(self.cont_id, folder))
        return ret == 0

    def equal_dev(self, dev):
        return self.cont_id == dev['cid'] and self.pit == dev['pit']


def create_mount_manager(cont_id, options):
    if cont_id == CONTAINER_ID_NONE:
        mount_manager = HostMntDevMgr(options)
    else:
        mount_manager = VzCtMntDevMgr(options, cont_id)
    return mount_manager


def umount_devices(options, devices):
    for dev in devices:
        if dev['mpoint'] == TI_MNT_NONE:
            continue
        mount_manager = create_mount_manager(dev["cid"], options)
        if not mount_manager.umount_device_with_check(dev):
            log("Can't umount folder {0} in container {1}: filesystem is busy".format(dev['mpoint'], dev['cid']))
            return False
    return True


def purge_devices_by_attr(options, value, attr):
    pids = MntDevMgr.get_devices_groupped_by_pid()
    for pid, devices in pids.items():
        mount_manager = None
        for dev in devices:
            if dev[attr] == value:
                mount_manager = create_mount_manager(dev["cid"], options)
                if dev['mpoint'] == TI_MNT_NONE:
                    continue
                log("purge dev={0}".format(dev['dev']))
                mount_manager.umount_device_with_check(dev)
        if mount_manager and mount_manager.check_devices_is_umount(devices):
            mount_manager.stop_service(pid)


def purge_devices_by_name(options):
    purge_devices_by_attr(options, options.device, "dev")

def purge_devices_by_names_list(options):
    pids = MntDevMgr.get_devices_groupped_by_pid()

    purge_devices = options.purge_devices.split(",")
    for pid, devices in pids.items():
        mount_manager = None
        for dev in devices:
            if dev["dev"] in purge_devices:
                mount_manager = create_mount_manager(dev["cid"], options)
                if dev['mpoint'] == TI_MNT_NONE:
                    continue
                log("purge dev={0}".format(dev['dev']))
                mount_manager.umount_device_with_check(dev)
        if mount_manager and mount_manager.check_devices_is_umount(devices):
            mount_manager.stop_service(pid)


def purge_devices_by_pit(options):
    purge_devices_by_attr(options, options.pit, "pit")


def need_umount_devices(options, devices):
    if options.exclusions:
        exclusions = options.exclusions.split(",")
        for dev in devices:
            if dev["pit"] in exclusions:
                log("skipping umount for dev={0} device is in exclusions list".format(dev))
                return False

    if options.exclude_device:
        exclude_devices = options.exclude_device.split(",")
        for dev in devices:
            if dev["dev"] in exclude_devices:
                log("skipping umount for dev={0} device is in exclusions list".format(dev))
                return False
    if options.timeout == 0:
        return True
    max_timestamps = MntDevMgr.get_max_timestamp(devices, options.timestamp_type)
    idle = MntDevMgr.get_idle(max_timestamps)
    return idle >= options.timeout


def purge_all_devices(options):
    cleanup_orphaned_devices(options)
    pids = MntDevMgr.get_devices_groupped_by_pid()
    for pid, devices in pids.items():
        if need_umount_devices(options, devices):
            if umount_devices(options, devices):
                MntDevMgr.stop_service(pid)


def info_all_devices(options):
    devices = MntDevMgr.get_used_devices()
    for dev in devices:
        mount_manager = create_mount_manager(dev["cid"], options)
        device = dev['dev']
        pid = dev['pid']
        outprint("Daemon: {0}".format(pid))
        s = mount_manager.daemon_status(pid)
        outprint("Status: {0}".format(mount_manager.status_str(s)))
        if s:
            outprint("Device: {0}".format(device))
            outprint("Idle: {0}".format(mount_manager.dev_idle_time(device, options.timestamp_type)))
            outprint("Busy: {0}".format(mount_manager.check_device_is_busy(dev)))


def cleanup_orphaned_devices(options):
    devices = MntDevMgr.get_orphaned_devices()
    for dev in devices:
        mount_manager = create_mount_manager(dev["cid"], options)
        mount_manager.umount_device(dev)


def main():
    global VERBOSE

    parser = OptionParser()
    parser.add_option("-I", "--info",            action="store_true", dest="info",           help="print info",           default=False)
    parser.add_option("-u", "--purge",           action="store_true", dest="purge",          help="purge devices",        default=False)
    parser.add_option("-z", "--purge-devices",   action="store",      dest="purge_devices",  help="purge passed devices", default=None)
    parser.add_option("-s", "--status",          action="store_true", dest="status",         help="status of mount",      default=False)
    parser.add_option("-i", "--cont_id",         action="store",      dest="cont_id",        help="container id",         default=CONTAINER_ID_NONE,  type="string",   metavar="CONT_ID")
    parser.add_option("-p", "--pit",             action="store",      dest="pit",            help="point in time",        default=None,               type="string",   metavar="PIT")
    parser.add_option("-d", "--device",          action="store",      dest="device",         help="device",               default=None,               type="string",   metavar="DEVICE")
    parser.add_option("-t", "--timeout",         action="store",      dest="timeout",        help="timeout",              default=0,                  type="int",      metavar="TIMEOUT")
    parser.add_option("-T", "--timestamp-type",  action="store",      dest="timestamp_type", help="timestamp type",       default="io",               type="string",   metavar="TIMESTAMP_TYPE")
    parser.add_option("-e", "--exclusions",      action="store",      dest="exclusions",     help="exclusions",           default=None)
    parser.add_option("-l", "--exclude_device",  action="store",      dest="exclude_device", help="devices to exclude",   default=None)
    parser.add_option("-v", "--verbose",         action="store_true", dest="verbose",        help="verbose output",       default=True)
    parser.add_option("-f", "--fstype",          action="store",      dest="fstype",         help="type of file system",  default=None)  
    parser.add_option("-a", "--archive",         action="store",      dest="archive",        help="archive",              default=None,               type="string")
    parser.add_option("-x", "--index",           action="store",      dest="index",          help="index of volume",      default=None,               type="string")
    parser.add_option("-c", "--cleanup",         action="store_true", dest="cleanup",        help="cleanup devices",      default=False)

    options, args = parser.parse_args()

    VERBOSE = options.verbose
    if options.info:
        VERBOSE = False

    log("status: {0}".format(options.status))
    log("purge: {0}".format(options.purge))
    log("cont_id: {0}".format(options.cont_id))
    log("pit: {0}".format(options.pit))
    log("device: {0}".format(options.device))
    log("timeout: {0}".format(options.timeout))
    log("timestamp type: {0}".format(options.timestamp_type))
    log("exclusions: {0}".format(options.exclusions))
    log("exclude_device: {0}".format(options.exclude_device))
    log("fstype: {0}".format(options.fstype))
    log("cleanup: {0}".format(options.cleanup))
    log("purge-devices: {0}".format(options.purge_devices))

    try:
        if options.purge:
            if options.pit:
                purge_devices_by_pit(options)
                return
            if options.device:
                purge_devices_by_name(options)
                return
            if options.purge_devices:
                purge_devices_by_names_list(options)
                return
            purge_all_devices(options)
            return

        if options.cleanup:
            cleanup_orphaned_devices(options)
            return

        if options.info:
            info_all_devices(options)
            return

        mount_manager = create_mount_manager(options.cont_id, options)
        if options.status:
            mount_manager.status()
            return

        mount_manager.mount()
    except Exception as ex:
        sys.exit(ex)


if __name__ == "__main__":
    # execute only if run as a script
    main()

Youez - 2016 - github.com/yon3zu
LinuXploit