arch = "i386" else: logging.critical( "Only x86 is supported;" " ask on chat.zulip.org if you want another architecture.") # Note: It's probably actually not hard to add additional # architectures. sys.exit(1) # Ideally we wouldn't need to install a dependency here, before we # know the OS version. 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_os_release() vendor = distro_info['ID'] os_version = distro_info['VERSION_ID'] family = distro_info['DISTRIB_FAMILY'] if not (vendor in SUPPORTED_PLATFORMS and os_version in SUPPORTED_PLATFORMS[vendor]): logging.critical("Unsupported platform: {} {}".format(vendor, os_version)) if vendor == 'ubuntu' and os_version == '14.04': print() print( "Ubuntu Trusty reached end-of-life upstream and is no longer a supported platform for Zulip" ) if os.path.exists('/home/vagrant'): print( "To upgrade, run `vagrant destroy`, and then recreate the Vagrant guest.\n" )
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( "{ID} {VERSION_ID}".format(**parse_os_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']: pg_dump_command = [ "pg_dump", "--format=directory", "--file", os.path.join(tmp, "zulip-backup", "database"), "--host", settings.DATABASES["default"]["HOST"], "--port", settings.DATABASES["default"]["PORT"], "--username", settings.DATABASES["default"]["USER"], "--dbname", settings.DATABASES["default"]["NAME"], "--no-password", ] os.environ["PGPASSWORD"] = settings.DATABASES["default"][ "PASSWORD"] run( pg_dump_command, 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