Exemple #1
0
]

REDHAT_VENV_DEPENDENCIES = COMMON_YUM_VENV_DEPENDENCIES + [
    "python36-devel",
    "python36-six",
    "python-virtualenv",
]

FEDORA_VENV_DEPENDENCIES = COMMON_YUM_VENV_DEPENDENCIES + [
    "python3-devel",
    "python3-pip",
    "python3-six",
    "virtualenv",  # see https://unix.stackexchange.com/questions/27877/install-virtualenv-on-fedora-16
]

codename = parse_lsb_release()["DISTRIB_CODENAME"]

if codename != "trusty":
    # Workaround for the fact that trusty has a different package name here.
    VENV_DEPENDENCIES.append("virtualenv")

THUMBOR_VENV_DEPENDENCIES = [
    "libcurl4-openssl-dev",
    "libjpeg-dev",
    "zlib1g-dev",
    "libfreetype6-dev",
    "libpng-dev",
    "gifsicle",
]

YUM_THUMBOR_VENV_DEPENDENCIES = [
Exemple #2
0
if platform.architecture()[0] == '64bit':
    arch = 'amd64'
elif platform.architecture()[0] == '32bit':
    arch = "i386"
else:
    logging.critical("Only x86 is supported;"
                     "ping [email protected] if you want another architecture.")
    sys.exit(1)

# Ideally we wouldn't need to install a dependency here, before we
# know the codename.
is_rhel_based = os.path.exists("/etc/redhat-release")
if (not is_rhel_based) and (not os.path.exists("/usr/bin/lsb_release")):
    run_as_root(["apt-get", "install", "-y", "lsb-release"])

distro_info = parse_lsb_release()
vendor = distro_info['DISTRIB_ID']
codename = distro_info['DISTRIB_CODENAME']
family = distro_info['DISTRIB_FAMILY']
if not (vendor in SUPPORTED_PLATFORMS and codename in SUPPORTED_PLATFORMS[vendor]):
    logging.critical("Unsupported platform: {} {}".format(vendor, codename))
    sys.exit(1)

POSTGRES_VERSION_MAP = {
    "stretch": "9.6",
    "trusty": "9.3",
    "xenial": "9.5",
    "bionic": "10",
    "cosmic": "10",
    "centos7": "10",
    "fedora29": "10",
Exemple #3
0
]

REDHAT_VENV_DEPENDENCIES = COMMON_YUM_VENV_DEPENDENCIES + [
    "python36-devel",
    "python36-six",
    "python-virtualenv",
]

FEDORA_VENV_DEPENDENCIES = COMMON_YUM_VENV_DEPENDENCIES + [
    "python3-devel",
    "python3-pip",
    "python3-six",
    "virtualenv",  # see https://unix.stackexchange.com/questions/27877/install-virtualenv-on-fedora-16
]

codename = parse_lsb_release()["DISTRIB_CODENAME"]

if codename != "trusty":
    # Workaround for the fact that trusty has a different package name here.
    VENV_DEPENDENCIES.append("virtualenv")

THUMBOR_VENV_DEPENDENCIES = [
    "libcurl4-openssl-dev",
    "libjpeg-dev",
    "zlib1g-dev",
    "libfreetype6-dev",
    "libpng-dev",
    "gifsicle",
]

YUM_THUMBOR_VENV_DEPENDENCIES = [
Exemple #4
0
    def handle(self, *args: Any, **options: Any) -> None:
        timestamp = timezone_now().strftime(TIMESTAMP_FORMAT)

        with tempfile.TemporaryDirectory(prefix="zulip-backup-%s-" %
                                         (timestamp, )) as tmp:
            os.mkdir(os.path.join(tmp, "zulip-backup"))
            members = []

            with open(os.path.join(tmp, "zulip-backup", "zulip-version"),
                      "w") as f:
                print(ZULIP_VERSION, file=f)
                git = try_git_describe()
                if git:
                    print(git, file=f)
            members.append("zulip-backup/zulip-version")

            with open(os.path.join(tmp, "zulip-backup", "os-version"),
                      "w") as f:
                print(
                    "{DISTRIB_ID} {DISTRIB_CODENAME}".format(
                        **parse_lsb_release()),
                    file=f,
                )
            members.append("zulip-backup/os-version")

            with open(os.path.join(tmp, "zulip-backup", "postgres-version"),
                      "w") as f:
                print(connection.pg_version, file=f)
            members.append("zulip-backup/postgres-version")

            if settings.DEVELOPMENT:
                os.symlink(
                    os.path.join(settings.DEPLOY_ROOT, "zproject"),
                    os.path.join(tmp, "zulip-backup", "zproject"),
                )
                members.append("zulip-backup/zproject/dev-secrets.conf")
            else:
                os.symlink("/etc/zulip",
                           os.path.join(tmp, "zulip-backup", "settings"))
                members.append("zulip-backup/settings")

            db_name = settings.DATABASES["default"]["NAME"]
            db_dir = os.path.join(tmp, "zulip-backup", "database")
            run(
                [
                    "pg_dump", "--format=directory", "--file", db_dir, "--",
                    db_name
                ],
                cwd=tmp,
            )
            members.append("zulip-backup/database")

            if settings.LOCAL_UPLOADS_DIR is not None and os.path.exists(
                    os.path.join(settings.DEPLOY_ROOT,
                                 settings.LOCAL_UPLOADS_DIR)):
                os.symlink(
                    os.path.join(settings.DEPLOY_ROOT,
                                 settings.LOCAL_UPLOADS_DIR),
                    os.path.join(tmp, "zulip-backup", "uploads"),
                )
                members.append("zulip-backup/uploads")

            try:
                if options["output"] is None:
                    tarball_path = tempfile.NamedTemporaryFile(
                        prefix="zulip-backup-%s-" % (timestamp, ),
                        suffix=".tar.gz",
                        delete=False,
                    ).name
                else:
                    tarball_path = options["output"]

                run(["tar", "-C", tmp, "-chzf", tarball_path, "--"] + members)
                print("Backup tarball written to %s" % (tarball_path, ))
            except BaseException:
                if options["output"] is None:
                    os.unlink(tarball_path)
                raise
Exemple #5
0
    def handle(self, *args: Any, **options: Any) -> None:
        timestamp = timezone_now().strftime(TIMESTAMP_FORMAT)
        with tempfile.TemporaryDirectory(prefix="zulip-backup-%s-" %
                                         (timestamp, )) as tmp:
            os.mkdir(os.path.join(tmp, "zulip-backup"))
            members = []
            paths = []

            with open(os.path.join(tmp, "zulip-backup", "zulip-version"),
                      "w") as f:
                print(ZULIP_VERSION, file=f)
                git = try_git_describe()
                if git:
                    print(git, file=f)
            members.append("zulip-backup/zulip-version")

            with open(os.path.join(tmp, "zulip-backup", "os-version"),
                      "w") as f:
                print(
                    "{DISTRIB_ID} {DISTRIB_CODENAME}".format(
                        **parse_lsb_release()),
                    file=f,
                )
            members.append("zulip-backup/os-version")

            with open(os.path.join(tmp, "zulip-backup", "postgres-version"),
                      "w") as f:
                print(connection.pg_version, file=f)
            members.append("zulip-backup/postgres-version")

            if settings.DEVELOPMENT:
                members.append(
                    os.path.join(settings.DEPLOY_ROOT, "zproject",
                                 "dev-secrets.conf"))
                paths.append(
                    ("zproject", os.path.join(settings.DEPLOY_ROOT,
                                              "zproject")))
            else:
                members.append("/etc/zulip")
                paths.append(("settings", "/etc/zulip"))

            if not options['skip_db']:
                db_name = settings.DATABASES["default"]["NAME"]
                db_dir = os.path.join(tmp, "zulip-backup", "database")
                run(
                    [
                        "pg_dump", "--format=directory", "--file", db_dir,
                        "--", db_name
                    ],
                    cwd=tmp,
                )
                members.append("zulip-backup/database")

            if not options[
                    'skip_uploads'] and settings.LOCAL_UPLOADS_DIR is not None and os.path.exists(
                        os.path.join(settings.DEPLOY_ROOT,
                                     settings.LOCAL_UPLOADS_DIR)):
                members.append(
                    os.path.join(settings.DEPLOY_ROOT,
                                 settings.LOCAL_UPLOADS_DIR))
                paths.append((
                    "uploads",
                    os.path.join(settings.DEPLOY_ROOT,
                                 settings.LOCAL_UPLOADS_DIR),
                ))

            assert not any("|" in name or "|" in path for name, path in paths)
            transform_args = [
                r"--transform=s|^{}(/.*)?$|zulip-backup/{}\1|x".format(
                    re.escape(path), name.replace("\\", r"\\"))
                for name, path in paths
            ]

            try:
                if options["output"] is None:
                    tarball_path = tempfile.NamedTemporaryFile(
                        prefix="zulip-backup-%s-" % (timestamp, ),
                        suffix=".tar.gz",
                        delete=False,
                    ).name
                else:
                    tarball_path = options["output"]

                run(["tar", "-C", tmp, "-cPzf", tarball_path] +
                    transform_args + ["--"] + members)
                print("Backup tarball written to %s" % (tarball_path, ))
            except BaseException:
                if options["output"] is None:
                    os.unlink(tarball_path)
                raise
Exemple #6
0
    def handle(self, *args: Any, **options: Any) -> None:
        timestamp = timezone_now().strftime(TIMESTAMP_FORMAT)

        with tempfile.TemporaryDirectory(
            prefix="zulip-backup-%s-" % (timestamp,)
        ) as tmp:
            os.mkdir(os.path.join(tmp, "zulip-backup"))
            members = []

            with open(os.path.join(tmp, "zulip-backup", "zulip-version"), "w") as f:
                print(ZULIP_VERSION, file=f)
                git = try_git_describe()
                if git:
                    print(git, file=f)
            members.append("zulip-backup/zulip-version")

            with open(os.path.join(tmp, "zulip-backup", "os-version"), "w") as f:
                print(
                    "{DISTRIB_ID} {DISTRIB_CODENAME}".format(**parse_lsb_release()),
                    file=f,
                )
            members.append("zulip-backup/os-version")

            with open(os.path.join(tmp, "zulip-backup", "postgres-version"), "w") as f:
                print(connection.pg_version, file=f)
            members.append("zulip-backup/postgres-version")

            if settings.DEVELOPMENT:
                os.symlink(
                    os.path.join(settings.DEPLOY_ROOT, "zproject"),
                    os.path.join(tmp, "zulip-backup", "zproject"),
                )
                members.append("zulip-backup/zproject/dev-secrets.conf")
            else:
                os.symlink("/etc/zulip", os.path.join(tmp, "zulip-backup", "settings"))
                members.append("zulip-backup/settings")

            db_name = settings.DATABASES["default"]["NAME"]
            db_dir = os.path.join(tmp, "zulip-backup", "database")
            run(
                ["pg_dump", "--format=directory", "--file", db_dir, "--", db_name],
                cwd=tmp,
            )
            members.append("zulip-backup/database")

            if settings.LOCAL_UPLOADS_DIR is not None and os.path.exists(
                os.path.join(settings.DEPLOY_ROOT, settings.LOCAL_UPLOADS_DIR)
            ):
                os.symlink(
                    os.path.join(settings.DEPLOY_ROOT, settings.LOCAL_UPLOADS_DIR),
                    os.path.join(tmp, "zulip-backup", "uploads"),
                )
                members.append("zulip-backup/uploads")

            try:
                if options["output"] is None:
                    tarball_path = tempfile.NamedTemporaryFile(
                        prefix="zulip-backup-%s-" % (timestamp,),
                        suffix=".tar.gz",
                        delete=False,
                    ).name
                else:
                    tarball_path = options["output"]

                run(["tar", "-C", tmp, "-chzf", tarball_path, "--"] + members)
                print("Backup tarball written to %s" % (tarball_path,))
            except BaseException:
                if options["output"] is None:
                    os.unlink(tarball_path)
                raise