Ejemplo n.º 1
0
 def __init__(self, logs, config, app, incr):
     super(IncrementalBackup, self).__init__(logs, config, app)
     try:
         duration = parse_duration(incr)
         self.timestamp = timestamp(now() - duration)
     except ValueError:
         self.timestamp = timestamp(parse_datetime(incr))
Ejemplo n.º 2
0
 def __init__(self, logs, config, app, incr):
     super(IncrementalBackup, self).__init__(logs, config, app)
     try:
         duration = parse_duration(incr)
         self.timestamp = timestamp(now() - duration)
     except ValueError:
         self.timestamp = timestamp(parse_datetime(incr))
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)