mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2025-09-06 18:40:40 +00:00
Compare commits
7 Commits
v1.8.3
...
5e98d4b362
Author | SHA1 | Date | |
---|---|---|---|
|
5e98d4b362 | ||
|
d243c924cc | ||
|
6424c64304 | ||
|
d39dafaef1 | ||
|
5a0f7e94f4 | ||
|
6a60d02759 | ||
1f7240c6a0 |
38
.github/workflows/ci.yml
vendored
Normal file
38
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
name: CI
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches: [master]
|
||||
|
||||
env:
|
||||
RESTIC_VERSION: "0.17.1"
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install restic@${{ env.RESTIC_VERSION }}
|
||||
run: |
|
||||
mkdir -p tools/restic
|
||||
curl --fail --location --silent --show-error --output tools/restic/restic.bz2 \
|
||||
"https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_linux_amd64.bz2"
|
||||
bzip2 -d tools/restic/restic.bz2
|
||||
chmod +x tools/restic/restic
|
||||
echo "$GITHUB_WORKSPACE/tools/restic" >> "$GITHUB_PATH"
|
||||
- run: restic version
|
||||
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '^1.21'
|
||||
- run: go test -v ./...
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '^1.21'
|
||||
- run: go build -v .
|
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.22-alpine as builder
|
||||
FROM golang:1.23-alpine as builder
|
||||
|
||||
WORKDIR /app
|
||||
COPY go.* .
|
||||
@@ -6,7 +6,7 @@ RUN go mod download
|
||||
COPY . .
|
||||
RUN go build
|
||||
|
||||
FROM restic/restic:0.17.0
|
||||
FROM restic/restic:0.17.1
|
||||
RUN apk add --no-cache rclone bash curl docker-cli
|
||||
COPY --from=builder /app/autorestic /usr/bin/autorestic
|
||||
ENTRYPOINT []
|
||||
|
75
cmd/backup_test.go
Normal file
75
cmd/backup_test.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func runCmd(t *testing.T, args ...string) error {
|
||||
t.Helper()
|
||||
|
||||
viper.Reset()
|
||||
rootCmd.SetArgs(args)
|
||||
|
||||
err := rootCmd.Execute()
|
||||
return err
|
||||
}
|
||||
|
||||
func TestBackupCmd(t *testing.T) {
|
||||
t.Run("simple local backup and restore", func(t *testing.T) {
|
||||
workDir := t.TempDir()
|
||||
|
||||
// Prepare content to be backed up
|
||||
locationDir := path.Join(workDir, "my-location")
|
||||
err := os.Mkdir(locationDir, 0750)
|
||||
assert.Nil(t, err)
|
||||
err = os.WriteFile(path.Join(locationDir, "back-me-up.txt"), []byte("hello world"), 0640)
|
||||
assert.Nil(t, err)
|
||||
|
||||
// Write config file
|
||||
config, err := yaml.Marshal(map[string]interface{}{
|
||||
"version": 2,
|
||||
"locations": map[string]map[string]interface{}{
|
||||
"my-location": {
|
||||
"type": "local",
|
||||
"from": []string{locationDir},
|
||||
"to": []string{"test"},
|
||||
},
|
||||
},
|
||||
"backends": map[string]map[string]interface{}{
|
||||
"test": {
|
||||
"type": "local",
|
||||
"path": path.Join(workDir, "test-backend"),
|
||||
"key": "supersecret",
|
||||
},
|
||||
},
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
configPath := path.Join(workDir, ".autorestic.yml")
|
||||
err = os.WriteFile(configPath, config, 0640)
|
||||
assert.Nil(t, err)
|
||||
|
||||
// Init repo (not initialized by default)
|
||||
err = runCmd(t, "exec", "--ci", "-a", "-c", configPath, "init")
|
||||
assert.Nil(t, err)
|
||||
|
||||
// Do the backup
|
||||
err = runCmd(t, "backup", "--ci", "-a", "-c", configPath)
|
||||
assert.Nil(t, err)
|
||||
|
||||
// Restore in a separate dir
|
||||
restoreDir := path.Join(workDir, "restore")
|
||||
err = runCmd(t, "restore", "--ci", "-c", configPath, "-l", "my-location", "--to", restoreDir)
|
||||
assert.Nil(t, err)
|
||||
|
||||
// Check restored file
|
||||
restoredContent, err := os.ReadFile(path.Join(restoreDir, locationDir, "back-me-up.txt"))
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "hello world", string(restoredContent))
|
||||
})
|
||||
}
|
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"scripts": {
|
||||
"build": "NEXT_TELEMETRY_DISABLED=1 next build",
|
||||
"dev": "NEXT_TELEMETRY_DISABLED=1 next"
|
||||
"dev": "NEXT_TELEMETRY_DISABLED=1 next",
|
||||
"start": "NEXT_TELEMETRY_DISABLED=1 next start"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "^14.2.7",
|
||||
|
@@ -18,7 +18,7 @@ services:
|
||||
|
||||
```yaml | .autorestic.yml
|
||||
locations:
|
||||
foo:
|
||||
hello:
|
||||
from: my-data
|
||||
type: volume
|
||||
# ...
|
||||
|
Reference in New Issue
Block a user