Skip to content

execute commands before and after backup #36

Description

@wehrstedt

Add a possibility to run a command before and after the backup process. As a concrete example, let's assume that you wan't to backup a nextcloud instance:

version: '2'

volumes:
  nextcloud:
  nextcloud_data:
  db:

services:
  db:
    image: mariadb
    restart: always
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_PASSWORD=root
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    labels:
      restic-compose-backup.mariadb: true
      # run occ maintenance:mode --on as user www-data in container nextcloud before backup
      restic-compose-backup.before-backup.priority: 1
      restic-compose-backup.before-backup.command: ./occ maintenance:mode --on
      restic-compose-backup.before-backup.user: www-data
      restic-compose-backup.before-backup.service-name: nextcloud

  nextcloud:
    image: nextcloud
    restart: always
    links:
      - db
    volumes:
      - nextcloud:/var/www/html
      - nextcloud_data:/var/lib/nextcloud
    environment:
      - MYSQL_PASSWORD=root
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=db
      - NEXTCLOUD_DATA_DIR=/var/lib/nextcloud
      - NEXTCLOUD_TRUSTED_DOMAINS="www.fuubar.com"
    labels:
      restic-compose-backup.volumes: true
      # run occ maintenance:mode --on as user www-data in container nextcloud after backup
      restic-compose-backup.before-backup.priority: 2
      restic-compose-backup.after-backup.command: ./occ maintenance:mode --off
      restic-compose-backup.after-backup.user: www-data
      restic-compose-backup.after-backup.service-name: nextcloud

This example will first start backup the database (priority=1). Before the backup starts, it will execute occ maintenance:mode --on as user www-data in container nextcloud. After that, the volumes of the nextcloud-container will be processed (priority=2) and after that disables the maintenance mode.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions