예제 #1
0
파일: backup.py 프로젝트: ESA-MInv/minv
def restore(in_path):
    """ Restore a previously backupped ZIP.
    """
    with closing(ZipFile(in_path)) as in_zip:
        manifest = json.loads(in_zip.read("manifest.json"))
        names = in_zip.namelist()

        if manifest["logs"]:
            # restore logs
            for name in names:
                extract = False
                # extract the file if it does not exist in the filesystem, or the
                # filesystem version is older
                if name.startswith("logs/"):
                    if exists(join("/var/log/minv", basename(name))):
                        ts = timestamp(datetime(*in_zip.getinfo(name).date_time))
                        if ts > getmtime(join("/var/log/minv", basename(name))):
                            extract = True
                    else:
                        extract = True

                if extract:
                    _restore_file(
                        in_zip, name, join("/var/log/minv", basename(name))
                    )

        if manifest["config"]:
            # restore the global configuration if it is stored in the backup
            if "config/minv.conf" in names:
                errors = check_global_configuration(
                    GlobalReader.from_fileobject(in_zip.open("config/minv.conf"))
                )
                if not errors:
                    backup_config("/etc/minv/minv.conf")
                    _restore_file(
                        in_zip, "config/minv.conf", "/etc/minv/minv.conf"
                    )
                    logger.info("Restored global configuration.")
                else:
                    logger.warn(
                        "Could not restore global configuration due to errors:"
                        "\n%s" % ("\n".join(errors))
                    )

            # restore all the collections included
            for name in names:
                if name.startswith("config/collections/") \
                        and name.endswith("collection.conf"):
                    try:
                        mission, file_type = name.split("/")[2:4]
                    except:
                        logger.error(
                            "Invalid collection configuration path '%s'" % name
                        )
                    else:
                        _restore_collection(in_zip, mission, file_type)
예제 #2
0
파일: backup.py 프로젝트: ESA-MInv/minv
def restore(in_path):
    """ Restore a previously backupped ZIP.
    """
    with closing(ZipFile(in_path)) as in_zip:
        manifest = json.loads(in_zip.read("manifest.json"))
        names = in_zip.namelist()

        if manifest["logs"]:
            # restore logs
            for name in names:
                extract = False
                # extract the file if it does not exist in the filesystem, or the
                # filesystem version is older
                if name.startswith("logs/"):
                    if exists(join("/var/log/minv", basename(name))):
                        ts = timestamp(
                            datetime(*in_zip.getinfo(name).date_time))
                        if ts > getmtime(join("/var/log/minv",
                                              basename(name))):
                            extract = True
                    else:
                        extract = True

                if extract:
                    _restore_file(in_zip, name,
                                  join("/var/log/minv", basename(name)))

        if manifest["config"]:
            # restore the global configuration if it is stored in the backup
            if "config/minv.conf" in names:
                errors = check_global_configuration(
                    GlobalReader.from_fileobject(
                        in_zip.open("config/minv.conf")))
                if not errors:
                    backup_config("/etc/minv/minv.conf")
                    _restore_file(in_zip, "config/minv.conf",
                                  "/etc/minv/minv.conf")
                    logger.info("Restored global configuration.")
                else:
                    logger.warn(
                        "Could not restore global configuration due to errors:"
                        "\n%s" % ("\n".join(errors)))

            # restore all the collections included
            for name in names:
                if name.startswith("config/collections/") \
                        and name.endswith("collection.conf"):
                    try:
                        mission, file_type = name.split("/")[2:4]
                    except:
                        logger.error(
                            "Invalid collection configuration path '%s'" %
                            name)
                    else:
                        _restore_collection(in_zip, mission, file_type)
예제 #3
0
파일: config.py 프로젝트: ESA-MInv/minv
    def _check_errors(self, path, old_path, collection):
        # check for errors
        if collection:
            reader = CollectionConfigurationReader(path)
            errors = check_collection_configuration(reader)
        else:
            reader = GlobalReader(path)
            errors = check_global_configuration(reader)

        if errors:
            self.error("Configuration contains errors:\n   - %s" %
                       ("\n   - ".join(errors)))
        return errors