Skip to content

Instantly share code, notes, and snippets.

@jbasinger
Last active September 21, 2020 16:34
Show Gist options
  • Save jbasinger/58b7c4af6adf6d64c620abbf76449149 to your computer and use it in GitHub Desktop.
Save jbasinger/58b7c4af6adf6d64c620abbf76449149 to your computer and use it in GitHub Desktop.

Revisions

  1. jbasinger revised this gist Sep 21, 2020. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions docker-compose-tools.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    version: "3.8"
    services:

    tools:
    hostname: tools
    container_name: tools
    build:
    context: ./tools
    volumes:
    - "/Volumes/dev:/code"
    stdin_open: true
    tty: true
  2. jbasinger revised this gist Sep 21, 2020. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    FROM ubuntu:latest
    ENV TERM xterm-256color
    WORKDIR /root
    RUN apt-get update \
    && apt-get install -y \
    ripgrep \
    jq \
    zsh \
    curl \
    git
    RUN sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    RUN git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
    COPY . /root
    WORKDIR /code
    ENTRYPOINT ["/bin/zsh"]
  3. jbasinger revised this gist Sep 21, 2020. 2 changed files with 55 additions and 0 deletions.
    40 changes: 40 additions & 0 deletions restore-all.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #!/bin/bash

    CONTAINER="ms_db"
    PASS="mysecretpassword!"

    BAKS=$(ls -r backup/*.bak)

    for BAK in $BAKS
    do
    echo "Restoring backup: $BAK"

    # echo "RESTORE FILELISTONLY FROM DISK = '/$BAK'"

    VOLS=$(docker exec -it $CONTAINER /opt/mssql-tools/bin/sqlcmd \
    -S localhost -U SA -P $PASS \
    -Q "RESTORE FILELISTONLY FROM DISK = '/$BAK'" \
    | tr -s ' ' | cut -d ' ' -f 1 | sed 1,2d | tail -r | sed 1,2d | tail -r)

    i=0
    SQL="RESTORE DATABASE "
    for VOL in $VOLS
    do

    if [[ $i -eq 0 ]]
    then
    SQL+="$VOL FROM DISK = '/$BAK' WITH MOVE '$VOL' TO '/var/opt/mssql/data/$VOL.mdf'"
    else
    SQL+=", MOVE '$VOL' TO '/var/opt/mssql/data/$VOL.ldf'"
    fi
    i+=1
    done

    # echo $SQL

    docker exec -it $CONTAINER /opt/mssql-tools/bin/sqlcmd \
    -S localhost -U SA -P $PASS \
    -Q "$SQL"

    done

    15 changes: 15 additions & 0 deletions run-script.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/bin/bash

    if [ -z "$1" ]
    then
    echo "Please specify a script"
    exit 1
    fi

    CONTAINER="ms_db"
    PASS="mysecretpassword!"
    SCRIPT=$1

    docker exec -it $CONTAINER /opt/mssql-tools/bin/sqlcmd \
    -S localhost -U SA -P $PASS \
    -i "/$SCRIPT"
  4. jbasinger revised this gist Sep 21, 2020. No changes.
  5. jbasinger created this gist Sep 21, 2020.
    24 changes: 24 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    version: "3.8"

    services:

    ms-db:
    image: mcr.microsoft.com/mssql/server:2017-latest
    container_name: ms_db
    ports:
    - "1433:1433"
    environment:
    - "ACCEPT_EULA=Y"
    - "SA_PASSWORD=mysecretpassword!"
    volumes:
    - ms_db:/var/opt/mssql
    - ./backup:/backup
    - ./scripts:/scripts
    networks:
    - database

    volumes:
    ms_db:

    networks:
    database: