Skip to content

Commit

Permalink
Merge branch 'release/0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
bbtbir committed Mar 18, 2024
2 parents 06f46ce + 35f7be7 commit ce1205b
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 21 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Docker Image CI

on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
92 changes: 92 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Docker Image Publish

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
release:
types: [published]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: docker.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}


jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1
with:
cosign-release: 'v2.1.1'

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ For using the cleanup feature attach the same `/backup` volume in the `bbtsoftwa
| 0.2.0 | Release [0.2.0](https://github.com/bbtsoftware/docker-mssql-backup/releases/tag/0.2.0) | ![Size](https://shields.beevelop.com/docker/image/image-size/bbtsoftwareag/mssql-backup/0.2.0.svg?style=flat-square) |
| 0.3.0 | Release [0.3.0](https://github.com/bbtsoftware/docker-mssql-backup/releases/tag/0.3.0) | ![Size](https://shields.beevelop.com/docker/image/image-size/bbtsoftwareag/mssql-backup/0.3.0.svg?style=flat-square) |
| 0.4.0 | Release [0.4.0](https://github.com/bbtsoftware/docker-mssql-backup/releases/tag/0.4.0) | ![Size](https://shields.beevelop.com/docker/image/image-size/bbtsoftwareag/mssql-backup/0.4.0.svg?style=flat-square) |
| 0.5.0 | Release [0.5.0](https://github.com/bbtsoftware/docker-mssql-backup/releases/tag/0.5.0) | ![Size](https://shields.beevelop.com/docker/image/image-size/bbtsoftwareag/mssql-backup/0.5.0.svg?style=flat-square) |

### Configuration

Expand Down
31 changes: 10 additions & 21 deletions backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ echo "Backup started at $(date "+%Y-%m-%d %H:%M:%S")"

CURRENT_DATE=$(date +%Y%m%d%H%M)

# Intermediate working backup directory
WORKDIR="/backup/$CURRENT_DATE"

# Target backup directory
TARGETDIR="/backup"

Expand All @@ -22,8 +19,10 @@ REMOTEDIR="/remote"
for CURRENT_DB in $DB_NAMES
do

BACKUPNAME=$CURRENT_DATE.$CURRENT_DB

# backup database files
BAK_FILENAME=$WORKDIR/$CURRENT_DATE.$CURRENT_DB.bak
BAK_FILENAME=$TARGETDIR/$BACKUPNAME.bak

echo "Backup database $CURRENT_DB to $BAK_FILENAME on $DB_SERVER..."
if /opt/mssql-tools/bin/sqlcmd -S "$DB_SERVER" -U "$DB_USER" -P "$DB_PASSWORD" -b -Q "BACKUP DATABASE [$CURRENT_DB] TO DISK = N'$BAK_FILENAME' WITH NOFORMAT, NOINIT, NAME = '$CURRENT_DB-full', SKIP, NOUNLOAD, STATS = 10"
Expand All @@ -36,7 +35,7 @@ do

# backup log files
if [ "$SKIP_BACKUP_LOG" = false ]; then
TRN_FILENAME=$WORKDIR/$CURRENT_DATE.$CURRENT_DB.trn
TRN_FILENAME=$TARGETDIR/$BACKUPNAME.trn

echo "Backup log of $CURRENT_DB to $TRN_FILENAME on $DB_SERVER..."
if /opt/mssql-tools/bin/sqlcmd -S "$DB_SERVER" -U "$DB_USER" -P "$DB_PASSWORD" -b -Q "BACKUP LOG [$CURRENT_DB] TO DISK = N'$TRN_FILENAME' WITH NOFORMAT, NOINIT, NAME = '$CURRENT_DB-log', SKIP, NOUNLOAD, STATS = 10"
Expand All @@ -47,20 +46,21 @@ do
rm -rf "$TRN_FILENAME"
fi
else
$TRN_FILENAME=""
echo "Backup of log skipped."
fi

if [ "$PACK" = "tar" ] || [ "$PACK" = "zip" ]; then
# compress backup files into tar.gz or zip file
echo ""
echo "Compress backup files"
FILES=$(find $WORKDIR -type f \( -name \*\.bak -o -name \*\.trn \))
FILES=$(find $TARGETDIR -maxdepth 1 -type f \( -name "$BACKUPNAME.bak" -o -name "$BACKUPNAME.trn" \) )
if [ "$PACK" = "tar" ]; then
ARCHIVE_FILENAME="$WORKDIR/$CURRENT_DATE.$CURRENT_DB.tar.gz"
ARCHIVE_FILENAME="$TARGETDIR/$BACKUPNAME.tar.gz"
tar cfvz "$ARCHIVE_FILENAME" $FILES
retval=$?
elif [ "$PACK" = "zip" ]; then
ARCHIVE_FILENAME="$WORKDIR/$CURRENT_DATE.$CURRENT_DB.zip"
ARCHIVE_FILENAME="$TARGETDIR/$BACKUPNAME.zip"
if [ "$ZIP_PASSWORD" ]; then
zip --password "$ZIP_PASSWORD" "$ARCHIVE_FILENAME" $FILES
retval=$?
Expand All @@ -73,35 +73,24 @@ do
echo "Packing up results to $ARCHIVE_FILENAME"
if [ $retval -eq 0 ]; then
echo "Successfully packed backup into $ARCHIVE_FILENAME"
cp "$ARCHIVE_FILENAME" "$TARGETDIR"
else
echo "Failed creating $ARCHIVE_FILENAME"
fi

rm -rf $FILES
else
# Move files from intermediate work to target directory
echo "Copy backup files to target directory"
find $WORKDIR -type f -name "*.$CURRENT_DB.bak" -exec cp {} $TARGETDIR \;
find $WORKDIR -type f -name "*.$CURRENT_DB.trn" -exec cp {} $TARGETDIR \;
fi

# Push to remote directory
if [ "$PUSH_REMOTE_MODE" = "move" ] || [ "$PUSH_REMOTE_MODE" = "copy" ]; then
echo "Push backup to remote directory"
find $WORKDIR -type f -name "*.$CURRENT_DB.*" -exec cp {} $REMOTEDIR \;
find $TARGETDIR -maxdepth 1 -type f -name "$BACKUPNAME.*" -exec cp {} $REMOTEDIR \;

if [ "$PUSH_REMOTE_MODE" = "move" ]; then
echo "Cleanup target directory"
find $TARGETDIR -type f -name "*.$CURRENT_DB.*" -exec rm {} \;
find $TARGETDIR -maxdepth 1 -type f -name "$BACKUPNAME.*" -exec rm {} \;
fi
fi

# Cleanup intermediate directory
echo "Cleanup intermediate directory"
find $WORKDIR -type f -name "*.$CURRENT_DB.*" -exec rm {} \;
rm -rf $WORKDIR

# Cleanup old backup files in target directory
if [ "$BACKUP_CLEANUP" = true ]; then
echo ""
Expand Down

0 comments on commit ce1205b

Please sign in to comment.