Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to restore the zammad backup? #68

Closed
macnibblet opened this issue Mar 29, 2018 · 12 comments
Closed

How to restore the zammad backup? #68

macnibblet opened this issue Mar 29, 2018 · 12 comments

Comments

@macnibblet
Copy link

I cannot find any documentation on how to restore a backup made

@monotek
Copy link
Member

monotek commented Mar 29, 2018

Because there is none...

Just copy files and import DB manually in the containers.

@macnibblet
Copy link
Author

I have spent a few hours trying to restore from a none docker-compose backup without any luck. Any chance you could walk me through it?

@lbausch
Copy link

lbausch commented Mar 31, 2018

@macnibblet
Make sure you have your files and your SQL dump ready.

Files should go into /var/lib/docker/volumes/zammaddockercompose_zammad-data/_data. You can check if this is the correct path by running docker inspect zammaddockercompose_zammad-railsserver_1 and see the "Mounts" section which might look like this:

"Mounts": [
            {
                "Type": "volume",
                "Name": "zammaddockercompose_zammad-data",
                "Source": "/var/lib/docker/volumes/zammaddockercompose_zammad-data/_data",
                "Destination": "/opt/zammad",
                "Driver": "local",
                "Mode": "rw",
                "RW": true,
                "Propagation": ""
            }
        ],

Copy your files there.

For SQL dump: Make sure to stop all containers except the postgresql container by running docker stop <container name>.
To access the SQL dump inside the container you need to check which mounts the container has:
docker inspect zammaddockercompose_zammad-postgresql_1 (you containers might be named differently).
In my case the volume path mounted in the container is /var/lib/docker/volumes/zammaddockercompose_postgresql-data/_data. Copy your backup there.

Next launch a shell inside the postgresql container: docker exec -it zammaddockercompose_zammad-init_1 bash. Switch to the postgres user by running su - postgres. Change the directory to /var/lib/postgresql/data and you should see your backup there. If it is a .gz file extract it using gunzip.
To get a clean restore you need to drop the existing database by running dropbdb zammad_production. Recreate it with createdb zammad_production. Finally, import the dump with psql zammad_production < dump.sql.
Once you're done exit the container, stop it and use docker-compose to start all Zammad containers.

Disclaimer: I'm by no means an Postgres guru so YMMV. :)

@macnibblet
Copy link
Author

@lbausch This worked almost flawlessly! The only problems is that the files keep getting written over each time I start it and we had replaced the OAuth.rb with a custom solution for hub from JetBrains. But I moved the account login to google OAuth instead. Thanks!

This should definitely be added to a guide somewhere or turned into a bash script

@waja
Copy link
Contributor

waja commented Apr 7, 2018

I did it this way:

  • Needed volumes in the Postgresql container:
  zammad-postgresql:
    volumes:
      - zammad-data:/opt/zammad
      - zammad-backup:/var/tmp/zammad:ro
  • Stopping services
# docker-compose stop zammad-nginx zammad-websocket zammad-railsserver zammad-memcached zammad-elasticsearch zammad-scheduler
  • Drop database content
# docker-compose exec zammad-postgresql su -c 'dropdb zammad_production' - postgres
  • Start Scheduler again (to recreate empty db)
# docker-compose start zammad-scheduler
  • Recreate empty database
# docker-compose exec zammad-scheduler bundle exec rake db:create
  • (Preparing) Restore
# docker-compose exec zammad-postgresql /bin/sh
$ cp /opt/zammad/contrib/backup/config.dist /opt/zammad/contrib/backup/config && \
  sed -i s/zammad_backup/zammad/g /opt/zammad/contrib/backup/config && \
  ln -s /usr/local/bin/psql /usr/bin/ && \
  /opt/zammad/contrib/backup/zammad_restore.sh
  • Restart whole compose stack
# docker-compose stop; docker-compose start && docker-compose logs -f

@monotek
Copy link
Member

monotek commented Apr 14, 2018

Currently we're not planning to script this in any way.
Feel free to add a pull request if you have a working solution.
Closing for now.

@monotek monotek closed this as completed Apr 14, 2018
@apiening
Copy link

# docker-compose exec zammad-postgresql su -c 'dropdb zammad_production' - postgres

I get the the following error when I try to execute this command:

dropdb: could not connect to database template1: FATAL:  role "postgres" does not exist

Any idea why this is?

@MrGeneration
Copy link
Member

Please don't recycle long solved issues for such things.
Either open a new issue on this repo or (better) use the community at https://community.zammad.org .

@linucksrox
Copy link

@MrGeneration Sorry but this is not a long solved issue. The command doesn't work, presumably because something changed in how the database container runs since the original solution was posted.

Why shut down the conversation here in favor of opening new threads? That just makes it more difficult to find an updated solution. Even if you don't support Docker, there's no need to artificially make it more difficult for the community to collaborate with each other.

I'd rather have one thread with all the information instead of multiple dead ends on the community forum as it is today.

@apiening
Copy link

@linucksrox I ended up using https://github.com/loomchild/volume-backup to backup and restore my zammad docker volumes.
I'm aware that this is not an optimal solution, but I was not able to do a successful restore based on the mechanism the zammad documentation described at this time.

@linucksrox
Copy link

Thanks @apiening! I'm currently checking out https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/zammad#backup-and-restore but if that doesn't work for me then I'll try your solution.

@mmojadad
Copy link

mmojadad commented Dec 26, 2022

@waja
Hi
First thank for your good guides.
Question : I am using Ubuntu 20.04
Issue is as following

docker-compose exec zammad-postgresql /bin/sh $ cp /opt/zammad/contrib/backup/config.dist /opt/zammad/contrib/backup/config && \ sed -i s/zammad_backup/zammad/g /opt/zammad/contrib/backup/config && \ n -s /usr/local/bin/psql /usr/bin/ && \ /opt/zammad/contrib/backup/zammad_restore.sh

/bin/sh: can't open '$': No such file or directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants