Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo <[email protected]>
  • Loading branch information
0x07cf-dev committed May 10, 2024
1 parent 65d61f0 commit 82d5de6
Show file tree
Hide file tree
Showing 11 changed files with 514 additions and 120 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,14 @@ name: Go
on:
workflow_dispatch:
push:
# run only against tags
tags:
- 'v*.*.*'
#branches: [ "main" ]
#paths-ignore:
# - '.github/**'
# - 'configs'
pull_request:
#branches: [ "main" ]

permissions:
contents: write
# packages: write
# issues: write


jobs:

release:
name: Release
strategy:
Expand All @@ -34,7 +24,6 @@ jobs:
runs-on: ubuntu-latest

steps:

- name: Checkout code
uses: actions/checkout@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ changelog:
exclude:
- "^docs:"
- "^test:"
- '^ci:'
- "^ci:"
- "^chore:"
139 changes: 67 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,100 @@
# Go-Backup -
# Go-Backup

Go-Backup is a simple command line utility written in Go that leverages [rclone](https://rclone.org) to transfer files to a remote destination.
Go-Backup is a simple command line utility written in Go that leverages [rclone](https://rclone.org) to transfer files to cloud storage.

It uses a JSON configuration file to customize behavior for each device you run it on. For each of your machines, you can specify a list of directories and/or files to send, along with lists of pre-transfer and/or post-transfer commands to be executed. It can be configured to send the user status notifications and/or signals to external uptime monitoring services, to keep track of non-interactive executions.
It uses a JSON configuration file in which you can define custom behavior for multiple devices: for each machine you use the same configuration with, you can specify a list of directories and/or files to send, along with a list of pre-transfer commands and/or a list of post-transfer commands to be executed locally.

To keep track of unattended executions, it can be configured to send the user status notifications and/or signals to external uptime monitoring services.

###### This is how I chose to learn Go. You can achieve the same with a script and rclone itself.

## Install
### Requirements
### 📋 Requirements
- [Go](https://golang.org/doc/install) installed
- **Supported backends**: WebDAV, Drive, Dropbox, S3-compliant services.

### Releases
Pre-built binaries for Go-Backup are available in the [Releases](https://github.com/0x07cf-dev/Go-Backup/releases) section of this repository.
- **Supported remotes**: WebDAV, Drive, Dropbox, S3-compliant services.

### Build from Source
To build Go-Backup from source, follow these steps:
### 📦 Releases
Pre-built binaries are available in the [releases section](https://github.com/0x07cf-dev/Go-Backup/releases).

1. **Clone the Repository:**
Clone the Go-Backup repository to your local machine:

```sh
git clone https://github.com/0x07cf-dev/Go-Backup.git
```

2. **Navigate to the Directory:**
Change your current directory to the cloned repository:
## Configuration

```sh
cd Go-Backup
```
The first thing you need is a destination for your files. These destinations (remotes) are configured interactively using rclone, a versatile command-line program for managing files on cloud storage.

3. **Build the Executable:**
Build the Go-Backup executable using the following command:
If you don't have any rclone remote configured, run the program:

```sh
go build -o ./go-backup .
```
```sh
go-backup upload
```

This will generate the `go-backup` executable in the current directory.
You'll be prompted to create one if none can be found. You will need an URL and your access credentials, such as username and password or access token.

4. **Run:**
Once built, you can run Go-Backup using the following command:
###### For service-specific instructions see: [rclone configuration](https://rclone.org/docs/#configure).

```sh
./go-backup
```
### 📂 Paths and Commands
Configuring the program involves editing a JSON file. It expects a list of zero or more paths, and two lists of zero or more commands.

Optionally, you can specify flags to customize the execution, such as:
Each machine will create its own directory under the specified root on the remote destination. Within this directory, all paths specified for backup are recreated. On your chosen remote, you will have the structure `/Root/Hostname/...`

```sh
./go-backup --simulate --unattended upload MyRemote
./go-backup -S -U upload Drive
```
To clarify, let's consider the following configuration:

For a list of flags, refer to the Flag section below, or run ```./go-backup --help```
```json
{
"machines": [
{
"hostname": "Debian01",
"paths": [
"/etc/important/"
"/var/log/useful",
],
...
}
]
}
```

## Configuration
Now let's assume you run the program with this configuration.

Configuring Go-Backup is straightforward. You can specify
```sh
go-backup upload MyDrive -r "MyBackups"
```

### 1. Generate Default Configuration:
Run the program for the first time to generate a default configuration file. This file will serve as the template for defining backup behavior for each device.
- The machine running the program is: `Debian01`
- You specify the remote: `MyDrive`
- You specify the root: `MyBackups`

### 2. Edit the Configuration File:
You can now edit the configuration file. Provide the appropriate paths and commands for pre and post-transfer operations.
With these values, the directories `/etc/important` and `/var/log/useful` will be transferred from `Debian01` to your remote named `MyDrive` at:

You can use the same configuration file for as many devices as you'd like. *Do not modify the hostname!*
```
(MyDrive) /MyBackups/Debian01/etc/important
(MyDrive) /MyBackups/Debian01/var/log/useful
```

#### Using environment variables in your paths is supported depending on the OS:
This structure ensures that backups are organized by device and retain their original paths on the remote destination.

\$MY_VAR on Linux, %MY_VAR% on Windows
### The use of environment variables in paths and commands is supported.

```json
{
"machines": [
{
"hostname": "windows-machine",
"hostname": "windows01",
"paths": [
"%USERPROFILE%\\Desktop\\Stuff",
"C:\\Users\\Admin\\Documents\\"
"%USERPROFILE%/Desktop/Stuff",
],
"output": true,
"pre": [],
"post": []
...
},
{
"hostname": "linux-machine",
"hostname": "debian02",
"paths": [
"$HOME/stuff",
"/etc/mysql"
"/etc/stuff/some.conf"
],
"output": true,
"pre": [
"mariadb-dump --databases db1 > /path/to/output.sql"
"$HOME/stuff",
],
"post": ["rm /path/to/remove/*"]
}
...
},

...
]
}
```
Expand All @@ -106,7 +103,7 @@ You can use the same configuration file for as many devices as you'd like. *Do n

Go-Backup utilizes environment variables to setup notifications and health monitoring.<br>These variables can be set directly in your system's environment or within an environment file, using the appropriate flag.

### 📑 Using Environment Files
### 📑 Using a File
You can declare environment variables in an `.env` file for convenience. They are defined in a `KEY=value` format.

Here's an example `.env` file:
Expand All @@ -121,19 +118,19 @@ NTFY_BETTERUPTIME=abcdefghijklmnopqrstuvwxyz
```

You can specify the path to an environment file by running the program with the flags:
- `-e=/path/to/.env`.
- `--envFile=/path/to/.env`
- `go-backup -e="/path/to/.env" ...`
- `go-backup --envFile="/path/to/.env" ...`


### 🔔 Notification Setup
Go-Backup sends notifications via ntfy.sh. You can use the [public server](https://ntfy.sh/app) or you can self-host your own instance. Both options work.<br>To configure notifications, set the following environment variables:
Go-Backup sends notifications via ntfy.sh. You can use the [public instance](https://ntfy.sh/app) or you can self-host your own.<br>To configure notifications, set the following environment variables:

- `NTFY_HOST`: The host of the ntfy server (e.g., "https://ntfy.example.com").
- `NTFY_TOPIC`: The topic to which notifications will be sent. (e.g., "mybackups")
- `NTFY_TOKEN` (**Optional**): The authentication token for the ntfy server, if required.

### 🩺 Health Monitoring
Additionally, you can set up some optional uptime monitoring services using one (or all) of the following variables:
Additionally, you can optionally set to ping uptime monitoring services using one (or all) of the following variables:

- `NTFY_HEALTHCHECKS`: The ID of your Healthchecks.io monitoring service. (The part after `hc-ping.com/`)
- `NTFY_BETTERUPTIME`: The ID of your Better Uptime monitoring service. (The part after `api/v1/heartbeat/`)
Expand Down Expand Up @@ -165,11 +162,11 @@ These are the unique strings in the URLs that these services give you to ping.

## Disclaimer

Please note that this is a naive and rudimentary solution designed for small-scale needs. It lacks advanced features such as version control and comprehensive error handling.
Please note that this is a naive and rudimentary solution designed for my small-scale need. It lacks advanced features such as version control and comprehensive error handling.

This project is the result of my limited experience and is not intended to be a robust or feature-rich solution. As such, it may not meet the requirements of more complex backup scenarios.

Please consider using established backup solutions for critical data management needs. This project is provided as-is, with no guarantees of suitability or reliability.
Please consider using already established backup solutions for your critical data management needs. This project is provided as-is, with no guarantees of suitability or reliability.

I started this project because:
- I needed to upgrade my bash script that achieved the same, but was becoming nightmarish to maintain.
Expand All @@ -181,9 +178,7 @@ I started this project because:
Contributions are welcome! Feel free to submit issues or pull requests.


#### To-do:
- Better path/command parsing
- Log rotation?
- Other to-do's
#### Planned:
- Interactive configuration

---
14 changes: 7 additions & 7 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"context"
"errors"
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -50,18 +51,17 @@ var debug bool
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "go-backup",
Short: "Simple backup utility",
Long: `Go-Backup is a simple backup utility written in Go that uses rclone to transfer files to a remote destination.
It follows a .json configuration in which you can define custom behaviour for each device you run it on.
You can specify which directories and/or files to transfer, along with pre and/or post-transfer commands to be executed on the machine.
It can optionally be configured to send status notifications to the user via [ntfy.sh](https://ntfy.sh/app), and/or heartbeat signals to external uptime monitoring services in order to keep track of non-interactive executions.`,
Short: "Simple command line backup utility",
Long: `Go-Backup is a simple command line utility written in Go that leverages [rclone](https://rclone.org) to transfer files to cloud storage.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}

func SetVersionInfo(version, commit, date string) {
rootCmd.Version = fmt.Sprintf("%s (Built on %s; Git SHA: %s)", version, date, commit)
}

func remoteArg(cmd *cobra.Command, args []string) error {
if err := cobra.MaximumNArgs(1)(cmd, args); err != nil {
return err
Expand Down
8 changes: 1 addition & 7 deletions cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ import (
var uploadCmd = &cobra.Command{
Use: "upload",
Short: "Transfers from the machine to the remote",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Args: remoteArg,
Args: remoteArg,
Run: func(cmd *cobra.Command, args []string) {
session := backup.NewSession(ctx,
backup.WithRemote(remoteDest),
Expand Down
19 changes: 19 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,40 @@ require (
)

require (
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/aws/aws-sdk-go v1.46.6 // indirect
github.com/dropbox/dropbox-sdk-go-unofficial/v6 v6.0.5 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/ncw/swift/v2 v2.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/oauth2 v0.16.0 // indirect
google.golang.org/api v0.153.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/grpc v1.59.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
Loading

0 comments on commit 82d5de6

Please sign in to comment.