I made a minor adjustment to my setup configuration and mounted the volume for my backups locally, as opposed to the Docker-Compose.yml recommended on Github. This allows me to run the docker compose down -v
command worry-free. If you’re following the standard configuration from Github, make sure to secure the latest backup of the database and files from the respective Docker volume before executing this command.
You can usually find your backups at this path:
/var/lib/docker/volumes/zammad_zammad-backup/_data/backup/
After securing your latest backups, you can proceed with the following actions:
- First, you shut down all containers and delete all data:
docker compose down -v
- Then, you recreate the containers and stop them:
docker compose up -d
docker compose down
- Now, extract the database backup:
gzip -dk /path/of/your/backup/xxxxxxxxxx_zammad_db.psql.gz
mv /path/of/your/backup/xxxxxxxxxx_zammad_db.psql /var/lib/docker/volumes/zammad_postgresql-data/_data/backup_db.psql
- Start the database next:
docker compose up -d zammad-postgresql
docker compose exec -it zammad-postgresql bash
- First, check if you can access the database:
psql -U zammad -d zammad_production
If successful, enter \q
to close the connection to the database.
- Now, you delete the database and create a new one with the same name using the following command:
dropdb zammad_production -U zammad
createdb zammad_production -U zammad
- Now, you can re-import your backup. Since you’ve copied it into the PostgreSQL volumes, you can access it while inside the container:
psql zammad_production < /var/lib/postgresql/data/backup.psql -U zammad
- Finally, you can exit the container and shut down all containers.
exit
In the next step of our guide, we will deal with the old files generated by docker compose up
. These will be deleted to make room for the files from your backup:
# Delete all old files in the specified directory
rm -rf /var/lib/docker/volumes/zammad_zammad-var/_data/*
Now we extract your files from the backup:
# Navigate to your backup directory
cd /path/of/your/backup/
# Extract the files from the tar.gz backup
tar xzvf xxxxxxxxxx_zammad_files.tar.gz
After successfully executing this command, you need to copy the extracted data into the correct container:
# Moves the extracted files to the right container
mv opt/zammad/var/* /var/lib/docker/volumes/zammad_zammad-var/_data/
Now all containers can be started again:
# Navigate back to your Docker Compose directory
cd /to-your-docker-compose-files/
# Starts all Docker containers
docker compose up -d
Note: If something doesn’t work properly, it’s worth checking the Nginx logs. Depending on how the data was copied, there might be ownership issues. Therefore, in Nginx, check /opt/zammad/var/
and its contents with ls -al
to see if it is owned by the user zammad
. If it is owned by root
, use chown -R zammad:zammad /opt/zammad/var
and restart.
The next step is to regenerate the search index:
# Performs the regeneration of the search index
docker compose exec -it zammad-railsserver rake searchindex:rebuild
If the command runs without errors, everything is fine. However, if you receive the following message:
Elasticsearch is not configured.
it is very likely that the autocomplete search in the UI no longer works. The Elasticsearch configuration documentation might not immediately help here, as the commands do not work straightforwardly under Docker Compose. Therefore, the following steps are necessary for it to work in your environment:
First, you connect to the Rails server container:
# Connects you to the Rails server container
docker exec -u 0 -it zammad-railsserver bash
As the container does not contain an editor, you install one. I recommend nano
:
# Updates package lists for upgrades and new installations
apt update
# Installs the text editor nano
apt install nano
# Opens the database configuration file with nano
nano config/database.yml
The following values should be entered or added under production
:
production:
adapter: postgresql
database: zammad_production
pool: 50
timeout: 5000
encoding: utf8
username: zammad
password: zammad
host: zammad-postgresql
port: 5432
Save your changes and disconnect with exit
.
Now you can set the correct link for Elasticsearch:
# Sets the Elasticsearch link in the Zammad settings
docker compose exec -it zammad-railsserver rails r "Setting.set('es_url', 'http://zammad-elasticsearch:9200')"
Now you can execute the actual command that is still needed:
# Initiates the process of rebuilding the search index
docker compose exec -it zammad-railsserver rake zammad:searchindex:rebuild
Remember that these commands are executed in a certain context. It might be necessary to adapt them to your specific environment. Always make sure to create backups of your data and keep them safe before making significant changes to your infrastructure.