zulip / docker-zulip

Container configurations, images, and examples for Zulip.
https://zulip.com/
Apache License 2.0
550 stars 227 forks source link

Can't backup Zulip the way it is documented #423

Open roomcays opened 6 months ago

roomcays commented 6 months ago

The official documentation currently says:

The Zulip server has a built-in backup tool:

# As the zulip user
/home/zulip/deployments/current/manage.py backup
# Or as root
su zulip -c '/home/zulip/deployments/current/manage.py backup'

Unfortunately, this does not work with docker-containerized 7.5 version due to two errors:

  1. FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/postgresql/14/bin/pg_dump'
  2. broken symlinks to uploads and settings/zulip-secrets.conf in final .tar.gz file

This can be fixed by some small edits of /home/zulip/deployments/current/zerver/management/commands/backup.py:

--- backup.py
+++ backup.py
@@ -69,7 +69,7 @@

             if not options["skip_db"]:
                 pg_dump_command = [
-                    f"/usr/lib/postgresql/{major_pg_version}/bin/pg_dump",
+                    f"/usr/bin/pg_dump",
                     "--format=directory",
                     "--file=" + os.path.join(tmp, "zulip-backup", "database"),
                     "--username=" + settings.DATABASES["default"]["USER"],
@@ -129,7 +129,7 @@
                     [
                         "tar",
                         f"--directory={tmp}",
-                        "-cPzf",
+                        "-cPhzf",
                         tarball_path,
                         *transform_args,
                         "--",

The first is to be discussed and may take the form of $(which pg_dump) instead of fixed path, BUT the {major_pg_version} will be then lost. This, however, may not be the issue of docker-packaged deployment (I'm not sure about it).

The second one is adding --dereference switch to tar command:

       -h, --dereference
             Follow symlinks; archive and dump the files they point to.

Which IMO should not have negative implications.

Whole thing might be discussed with Zulip's upstream team so the docker and "native" versions of backup.py could be the same.

navjotjsingh commented 4 months ago

Use this command instead.

docker exec -it zulip bash /sbin/entrypoint.sh app:help

You will get the following response.

Available commands:
> app:help     - Show this help menu and exit
> app:version  - Container Zulip server version
> app:managepy - Run Zulip's manage.py script (defaults to "shell")
> app:backup   - Create backups of Zulip instances
> app:restore  - Restore backups of Zulip instances
> app:certs    - Create self-signed certificates
> app:run      - Run the Zulip server
> [COMMAND]    - Run given command with arguments in shell

Then use this to backup. docker exec -it zulip bash /sbin/entrypoint.sh app:backup

It will ask for your PostgreSQL password. Worked for me.

This needs to be documented.