Correct way to backup and restore with containerized setup (Docker)

Hello,

I am trying to setup backup processes for our docker nextcloud installation and also practicing restore routines, but having some questions and issues.

What would be the correct way to backup Docker-style NC installation?

I know I could simply stop containers and then backup entire volumes to external storage, but I would prefer backing up only what is needed to be able to follow more of a “provision” style backup and restore. At the moment I follow these steps:

  1. Copy config.php only to backup location.
  2. Make a backup of SQL database and store that in backup location.
  3. User data is going to be stored in a separate partition together with external data sources. These folders will be backed up as is.

Currently I try to restore as follows (it is more of a clean install):

  1. Completely remove all containers.
  2. Wipe all current data in container volumes, i.e. /var/www/html including configs etc. Wipe and SQL volume data.
  3. Recreate SQL container, wait until db is initialized, and restore saved SQL *.bak backup.
  4. Start Nextcloud container (with admin user defined in env variables).

However, at the moment, I face following issues with this way:

  1. I am not able to create NC container with the same admin user as it was before since it complains that files/folder for that user is already created. I get away with this by using temporary admin user for installation and then deleting it later. Is there a better way solving this issue?
  2. NC cannot proceed with the installation when container starts up because it complains that maintenance:install method is not present. I found out that I had to change line in config.php file 'installed' => 'true' to false and creating blank file called CAN_INSTALL in config directory . This works and launches installation. Are these steps sufficient to invoke correct installation process?
  3. I still do not understand what additional steps should be done as I am not really sure what stays in that database. Do I have to install apps manually via occ in my case? Where are app installations stored? I noticed that they seem to be not restored with the SQL database. However data of some apps (like Deck) seem to be saved in SQL (I later installed app manually and decks/cards were displayed for users).
  4. If I have to install apps manually, how to know if NC installation has been finished? I found it difficult to find decent flag that indicates that NC installation in container is completed. Since Config.php line installed is changed right after installation starts, it cannot be used for this purpose.
  5. Does this approach seem viable? I really wish to have setup that would less prone to issues and would allow me to proceed with NC updates easier.

My docker compose file looks like this:

version: '3.8'

services:
  db:
    image: mariadb:10.11
    container_name: mariadb
    restart: always
    command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
    volumes:
      - ./mariadb/sql:/var/lib/mysql
    env_file:
      - ./mariadb/env-files/sql.env
    healthcheck:
      test:
        [
          "CMD",
          "/var/lib/mysql/sql_health.sh",
          "--su-mysql",
          "--connect",
          "--innodb_initialized"
        ]
      start_period: 5s
      interval: 5s
      timeout: 3s
      retries: 3
    networks:
      - nc-net

  redis:
    container_name: redis
    image: redis:alpine
    restart: always
    networks:
      - nc-net

  app:
    image: nextcloud:stable-apache
    container_name: nextcloud
    restart: always
    ports:
      - 8080:80
    depends_on:
      - redis
      - db
    volumes:
      - ./nextcloud/core-data:/var/www/html
      - ./nextcloud/config:/var/www/html/config
      - /home/nas/data/external:/var/www/data
      - /home/nas/data/user:/var/www/html/data
    env_file:
      - ./nextcloud/env-files/nc.env
    networks:
      - nc-net

networks:
    nc-net:
      name: nc-net
      driver: bridge

Thank you very much.

You need to include this volume in your backup / restore process. Among other things, it contains all your installed apps.

Do I have to install apps manually via occ in my case

If you include this volume in your backup and restore process, you will not have to trigger installation at all or do any of those manual steps you are currently doing.

P.S. Don’t overlook backing up your Compose file (and env files). :slight_smile:

1 Like

The image supports Auto-config Hooks, including a post-installation one, which I suppose could be used for this purpose.

I really wish to have setup that would less prone to issues and would allow me to proceed with NC updates easier.

Make sure you take advantage of the ease of bringing up new stacks in Docker by creating a copy of your production Compose that deploys a “staging” or “testing” version of your stack that you can test updates, new apps, and other changes on instead of in production.

2 Likes

Hey, thanks for your reply.

I have been playing around for a while with backups and provisioning.

I still ended up making a new config that prepares new fresh NC installation from scratch via OCC that meets our needs, thus avoiding restoring SQL backup at all.

But I also made a second version of script that installs and restores SQL backup as well.

You suggestions were correct and I appreciate that.

Thanks.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.