Skip to content

Commit

Permalink
Merge pull request #138 from jkaninda/refactor
Browse files Browse the repository at this point in the history
feat: add Azure Blob storage
  • Loading branch information
jkaninda authored Dec 6, 2024
2 parents c5e0353 + 3703b00 commit 6503e4b
Show file tree
Hide file tree
Showing 33 changed files with 1,184 additions and 1,685 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM golang:1.23.3 AS build
WORKDIR /app

ARG appVersion=""
# Copy the source code.
COPY . .
# Installs Go dependencies
RUN go mod download

# Build
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/pg-bkup
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'github.com/jkaninda/pg-bkup/utils.Version=${appVersion}'" -o /app/pg-bkup

FROM alpine:3.20.3
ENV TZ=UTC
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ It supports a variety of storage options and ensures data security through GPG e
- AWS S3 or any S3-compatible object storage
- FTP
- SSH-compatible storage
- Azure Blob storage

- **Data Security:**
- Backups can be encrypted using **GPG** to ensure confidentiality.
Expand Down Expand Up @@ -62,6 +63,7 @@ Successfully tested on:
- AWS S3 or any S3 Alternatives for Object Storage
- SSH remote storage server
- FTP remote storage server
- Azure Blob storage

## Quickstart

Expand Down
13 changes: 6 additions & 7 deletions cmd/backup.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Package cmd /
package cmd

/*
MIT License
Expand All @@ -24,9 +21,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package cmd

import (
"github.com/jkaninda/pg-bkup/internal"
"github.com/jkaninda/pg-bkup/pkg/logger"
"github.com/jkaninda/pg-bkup/pkg"
"github.com/jkaninda/pg-bkup/utils"
"github.com/spf13/cobra"
)
Expand All @@ -37,9 +36,9 @@ var BackupCmd = &cobra.Command{
Example: utils.BackupExample,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
internal.StartBackup(cmd)
pkg.StartBackup(cmd)
} else {
logger.Fatal(`"backup" accepts no argument %q`, args)
utils.Fatal(`"backup" accepts no argument %q`, args)

}
},
Expand Down
10 changes: 5 additions & 5 deletions cmd/migrate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Package cmd /
/*
MIT License
Expand All @@ -22,11 +21,12 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package cmd

import (
"github.com/jkaninda/pg-bkup/internal"
"github.com/jkaninda/pg-bkup/pkg/logger"
"github.com/jkaninda/pg-bkup/pkg"
"github.com/jkaninda/pg-bkup/utils"
"github.com/spf13/cobra"
)

Expand All @@ -35,9 +35,9 @@ var MigrateCmd = &cobra.Command{
Short: "Migrate database from a source database to a target database",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
internal.StartMigration(cmd)
pkg.StartMigration(cmd)
} else {
logger.Fatal(`"migrate" accepts no argument %q`, args)
utils.Fatal(`"migrate" accepts no argument %q`, args)

}

Expand Down
11 changes: 5 additions & 6 deletions cmd/restore.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Package cmd /
/*
MIT License
Copyright (c) 2023 Jonas Kaninda
# Copyright (c) 2023 Jonas Kaninda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,11 +21,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package cmd

import (
"github.com/jkaninda/pg-bkup/internal"
"github.com/jkaninda/pg-bkup/pkg/logger"
"github.com/jkaninda/pg-bkup/pkg"
"github.com/jkaninda/pg-bkup/utils"
"github.com/spf13/cobra"
)
Expand All @@ -37,9 +36,9 @@ var RestoreCmd = &cobra.Command{
Example: utils.RestoreExample,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
internal.StartRestore(cmd)
pkg.StartRestore(cmd)
} else {
logger.Fatal(`"restore" accepts no argument %q`, args)
utils.Fatal(`"restore" accepts no argument %q`, args)

}

Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Package cmd /
/*
MIT License
Copyright (c) 2023 Jonas Kaninda
# Copyright (c) 2023 Jonas Kaninda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package cmd

import (
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Package cmd /
/*
MIT License
Expand All @@ -22,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package cmd

import (
Expand Down
44 changes: 44 additions & 0 deletions docs/how-tos/azure-blob.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: Azure Blob storage
layout: default
parent: How Tos
nav_order: 5
---
# Azure Blob storage

{: .note }
As described on local backup section, to change the storage of your backup and use Azure Blob as storage. You need to add `--storage azure` (-s azure).
You can also specify a folder where you want to save you data by adding `--path my-custom-path` flag.


## Backup to Azure Blob storage

```yml
services:
mysql-bkup:
# In production, it is advised to lock your image tag to a proper
# release version instead of using `latest`.
# Check https://github.com/jkaninda/pg-bkup/releases
# for a list of available releases.
image: jkaninda/pg-bkup
container_name: pg-bkup
command: backup --storage azure -d database --path my-custom-path
environment:
- DB_PORT=5432
- DB_HOST=postgres
- DB_NAME=database
- DB_USERNAME=username
- DB_PASSWORD=password
## Azure Blob configurations
- AZURE_STORAGE_CONTAINER_NAME=backup-container
- AZURE_STORAGE_ACCOUNT_NAME=account-name
- AZURE_STORAGE_ACCOUNT_KEY=Ppby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==
# pg-bkup container must be connected to the same network with your database
networks:
- web
networks:
web:
```
21 changes: 13 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,35 @@ module github.com/jkaninda/pg-bkup
go 1.23.2

require (
github.com/aws/aws-sdk-go v1.55.5
github.com/bramvdbogaerde/go-scp v1.5.0
github.com/go-mail/mail v2.3.1+incompatible
github.com/jkaninda/encryptor v0.0.0-20241013064832-ed4bd6a1b221
github.com/jlaffaye/ftp v0.2.0
github.com/jkaninda/go-storage v0.1.2
github.com/robfig/cron/v3 v3.0.1
github.com/spf13/cobra v1.8.1
golang.org/x/crypto v0.29.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/ProtonMail/go-crypto v1.1.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.5.0 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f // indirect
github.com/ProtonMail/gopenpgp/v2 v2.8.0 // indirect
github.com/ProtonMail/gopenpgp/v2 v2.7.5 // indirect
github.com/aws/aws-sdk-go v1.55.5 // indirect
github.com/bramvdbogaerde/go-scp v1.5.0 // indirect
github.com/cloudflare/circl v1.5.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jlaffaye/ftp v0.2.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/mail.v2 v2.3.1 // indirect
)
Loading

0 comments on commit 6503e4b

Please sign in to comment.