Skip to content

adding automatic backup to docker #13624

@sbOogway

Description

@sbOogway

Description

hello, id like to implement a backup restore system into docker. it should work similarly to the following bash script.

backup() {
  BACKUP_NAME=$1
  COMPOSE_PATH=$2

  pushd $COMPOSE_PATH > /dev/null || exit
    docker compose config --images | xargs docker save -o images.tar
    docker compose down > /dev/null 2>&1
    tar -cpzf $BACKUP_NAME.tar.gz .
    docker compose up -d > /dev/null 2>&1

  popd > /dev/null

}

restore() {
    BACKUP_NAME=$1
    RESTORE_PATH=$2

    mkdir -p $RESTORE_PATH

    pushd $RESTORE_PATH > /dev/null || exit

        tar -xpzf $BACKUP_NAME.tar.gz 

        docker load -i images.tar

        docker compose up -d > /dev/null 2>&1

    popd > /dev/null
}

i think right now docker lacks a built in backup system and it may be beneficial to have one.
the syntax should be docker compose backup <stack-name> and docker compose restore <tar.gz>.

edge cases to consider

there are some case where further considerations need to be made like for bind volumes and named volumes. also when a stack is built using multiple compose files it can be problematic. further planning need to be made

i tried to generate with ai some oneliners and a basic go implementation but it is sloppy and not clean. https://github.com/sbOogway/compose-backup if u want to take a look.

let me know if u think this can be useful and if i can be part of the effort to implement.

thanks

mattia papaccioli

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions