Skip to content

Commit de3c7e6

Browse files
committed
feat: initial implementation of Database Backup Utility
- Created core functionality for backing up and restoring databases (MySQL, PostgreSQL, MongoDB, SQLite). - Added configuration management using YAML files. - Implemented logging with configurable levels and formats. - Introduced command-line interface using Cobra for user commands. - Set up Docker support with a Dockerfile and docker-compose for easy deployment. - Included comprehensive documentation covering installation, usage, and troubleshooting. - Established CI/CD pipeline for automated testing and deployment. - Added example scripts and guides for common use cases.
0 parents  commit de3c7e6

35 files changed

+8364
-0
lines changed

.github/workflows/ci.yml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
mysql:
15+
image: mysql:8.0
16+
env:
17+
MYSQL_ROOT_PASSWORD: password
18+
MYSQL_DATABASE: testdb
19+
ports:
20+
- 3306:3306
21+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
22+
23+
postgres:
24+
image: postgres:15
25+
env:
26+
POSTGRES_PASSWORD: password
27+
POSTGRES_DB: testdb
28+
ports:
29+
- 5432:5432
30+
options: --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3
31+
32+
mongodb:
33+
image: mongo:7
34+
env:
35+
MONGO_INITDB_ROOT_USERNAME: admin
36+
MONGO_INITDB_ROOT_PASSWORD: password
37+
ports:
38+
- 27017:27017
39+
options: --health-cmd="mongosh --eval 'db.adminCommand(\"ping\")'" --health-interval=10s --health-timeout=5s --health-retries=3
40+
41+
steps:
42+
- uses: actions/checkout@v4
43+
44+
- name: Set up Go
45+
uses: actions/setup-go@v4
46+
with:
47+
go-version: "1.21"
48+
49+
- name: Cache Go modules
50+
uses: actions/cache@v3
51+
with:
52+
path: ~/go/pkg/mod
53+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
54+
restore-keys: |
55+
${{ runner.os }}-go-
56+
57+
- name: Install dependencies
58+
run: make deps
59+
60+
- name: Run linter
61+
uses: golangci/golangci-lint-action@v3
62+
with:
63+
version: latest
64+
65+
- name: Format check
66+
run: |
67+
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
68+
echo "The following files are not formatted:"
69+
gofmt -s -l .
70+
exit 1
71+
fi
72+
73+
- name: Run tests
74+
run: make test
75+
76+
- name: Run tests with coverage
77+
run: make test-coverage
78+
79+
- name: Upload coverage to Codecov
80+
uses: codecov/codecov-action@v3
81+
with:
82+
file: ./coverage.out
83+
flags: unittests
84+
name: codecov-umbrella
85+
86+
build:
87+
runs-on: ubuntu-latest
88+
needs: test
89+
90+
steps:
91+
- uses: actions/checkout@v4
92+
93+
- name: Set up Go
94+
uses: actions/setup-go@v4
95+
with:
96+
go-version: "1.21"
97+
98+
- name: Build
99+
run: make build-all
100+
101+
- name: Upload build artifacts
102+
uses: actions/upload-artifact@v3
103+
with:
104+
name: binaries
105+
path: build/
106+
107+
docker:
108+
runs-on: ubuntu-latest
109+
needs: test
110+
if: github.ref == 'refs/heads/main'
111+
112+
steps:
113+
- uses: actions/checkout@v4
114+
115+
- name: Set up Docker Buildx
116+
uses: docker/setup-buildx-action@v3
117+
118+
- name: Login to Docker Hub
119+
uses: docker/login-action@v3
120+
with:
121+
username: ${{ secrets.DOCKER_USERNAME }}
122+
password: ${{ secrets.DOCKER_PASSWORD }}
123+
124+
- name: Build and push Docker image
125+
uses: docker/build-push-action@v5
126+
with:
127+
context: .
128+
platforms: linux/amd64,linux/arm64
129+
push: true
130+
tags: |
131+
${{ secrets.DOCKER_USERNAME }}/database-backup-utility:latest
132+
${{ secrets.DOCKER_USERNAME }}/database-backup-utility:${{ github.sha }}
133+
134+
release:
135+
runs-on: ubuntu-latest
136+
needs: [test, build]
137+
if: github.ref == 'refs/heads/main' && startsWith(github.ref, 'refs/tags/')
138+
139+
steps:
140+
- uses: actions/checkout@v4
141+
with:
142+
fetch-depth: 0
143+
144+
- name: Set up Go
145+
uses: actions/setup-go@v4
146+
with:
147+
go-version: "1.21"
148+
149+
- name: Build
150+
run: make build-all
151+
152+
- name: Create Release
153+
uses: softprops/action-gh-release@v1
154+
with:
155+
files: |
156+
build/*
157+
draft: false
158+
prerelease: false
159+
env:
160+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
17+
# Go workspace file
18+
go.work
19+
20+
# Build directory
21+
build/
22+
dist/
23+
24+
# IDE files
25+
.vscode/
26+
.idea/
27+
*.swp
28+
*.swo
29+
*~
30+
31+
# OS generated files
32+
.DS_Store
33+
.DS_Store?
34+
._*
35+
.Spotlight-V100
36+
.Trashes
37+
ehthumbs.db
38+
Thumbs.db
39+
40+
# Log files
41+
*.log
42+
43+
# Backup files
44+
backups/
45+
*.sql
46+
*.sql.gz
47+
*.bson
48+
*.bson.gz
49+
*.db
50+
*.db.gz
51+
52+
# Configuration files with sensitive data
53+
config.yaml
54+
config.yml
55+
.env
56+
.env.local
57+
.env.production
58+
59+
# Temporary files
60+
tmp/
61+
temp/
62+
*.tmp
63+
64+
# Coverage files
65+
coverage.out
66+
coverage.html
67+
68+
# Test database files
69+
test.db
70+
test.sqlite
71+
test.sqlite3
72+
73+
# Docker volumes
74+
docker-data/
75+
76+
# Node modules (if any frontend components)
77+
node_modules/
78+
79+
# Python cache (if any Python scripts)
80+
__pycache__/
81+
*.pyc
82+
*.pyo
83+
*.pyd
84+
.Python
85+
env/
86+
venv/
87+
.venv/
88+
89+
# JetBrains IDEs
90+
.idea/
91+
*.iml
92+
*.ipr
93+
*.iws
94+
95+
# VSCode
96+
.vscode/
97+
*.code-workspace
98+
99+
# Sublime Text
100+
*.sublime-project
101+
*.sublime-workspace
102+
103+
# Vim
104+
*.swp
105+
*.swo
106+
.netrwhist
107+
108+
# Emacs
109+
*~
110+
\#*\#
111+
/.emacs.desktop
112+
/.emacs.desktop.lock
113+
*.elc
114+
auto-save-list
115+
tramp
116+
.\#*
117+
118+
# Local development
119+
.local/
120+
local/

Dockerfile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Build stage
2+
FROM golang:1.21-alpine AS builder
3+
4+
# Install build dependencies
5+
RUN apk add --no-cache git make
6+
7+
# Set working directory
8+
WORKDIR /app
9+
10+
# Copy go mod files
11+
COPY go.mod go.sum ./
12+
13+
# Download dependencies
14+
RUN go mod download
15+
16+
# Copy source code
17+
COPY . .
18+
19+
# Build the application
20+
RUN make build
21+
22+
# Runtime stage
23+
FROM alpine:latest
24+
25+
# Install runtime dependencies
26+
RUN apk add --no-cache \
27+
ca-certificates \
28+
mysql-client \
29+
postgresql-client \
30+
mongodb-tools \
31+
sqlite
32+
33+
# Create non-root user
34+
RUN adduser -D -s /bin/sh dbbackup
35+
36+
# Set working directory
37+
WORKDIR /app
38+
39+
# Copy binary from builder stage
40+
COPY --from=builder /app/build/db-backup /usr/local/bin/db-backup
41+
42+
# Create backup directory
43+
RUN mkdir -p /backups && chown dbbackup:dbbackup /backups
44+
45+
# Switch to non-root user
46+
USER dbbackup
47+
48+
# Set default environment variables
49+
ENV BACKUP_DIR=/backups
50+
ENV LOG_LEVEL=info
51+
ENV LOG_FORMAT=json
52+
53+
# Expose volume for backups
54+
VOLUME ["/backups"]
55+
56+
# Set entrypoint
57+
ENTRYPOINT ["db-backup"]
58+
59+
# Default command
60+
CMD ["--help"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Ibrahim Raimi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)