Skip to content

Instantly share code, notes, and snippets.

@titom73
Created October 20, 2021 18:53
Show Gist options
  • Select an option

  • Save titom73/788676d0f33d4147010f3f9ef0cfdb68 to your computer and use it in GitHub Desktop.

Select an option

Save titom73/788676d0f33d4147010f3f9ef0cfdb68 to your computer and use it in GitHub Desktop.

Revisions

  1. titom73 renamed this gist Oct 20, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. titom73 created this gist Oct 20, 2021.
    17 changes: 17 additions & 0 deletions restore.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/bin/bash
    # This script allows you to restore a single volume from a container
    # Data in restored in volume with same backupped path
    NEW_CONTAINER_NAME=$1

    usage() {
    echo "Usage: $0 [container name]"
    exit 1
    }

    if [ -z $NEW_CONTAINER_NAME ]
    then
    echo "Error: missing container name parameter."
    usage
    fi

    sudo docker run --rm --volumes-from $NEW_CONTAINER_NAME -v $(pwd):/backup busybox tar xvf /backup/backup.tar
    24 changes: 24 additions & 0 deletions volume-backup.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/bin/bash
    # This script allows you to backup a single volume from a container
    # Data in given volume is saved in the current directory in a tar archive.
    CONTAINER_NAME=$1
    VOLUME_NAME=$2

    usage() {
    echo "Usage: $0 [container name] [volume name]"
    exit 1
    }

    if [ -z $CONTAINER_NAME ]
    then
    echo "Error: missing container name parameter."
    usage
    fi

    if [ -z $VOLUME_NAME ]
    then
    echo "Error: missing volume name parameter."
    usage
    fi

    sudo docker run --rm --volumes-from $CONTAINER_NAME -v $(pwd):/backup busybox tar cvf /backup/backup.tar $VOLUME_NAME