mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2025-09-06 10:30:39 +00:00
Compare commits
1 Commits
4ba39a8eda
...
codespace-
Author | SHA1 | Date | |
---|---|---|---|
|
4e3ae6403b |
8
.github/dependabot.yml
vendored
8
.github/dependabot.yml
vendored
@@ -1,8 +0,0 @@
|
|||||||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
|
||||||
|
|
||||||
version: 2
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: "docker"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "weekly"
|
|
23
.github/workflows/build.yml
vendored
23
.github/workflows/build.yml
vendored
@@ -3,19 +3,19 @@ name: Main
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- 'v*.*.*'
|
- "v*.*.*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
docker:
|
docker:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v2
|
uses: docker/setup-qemu-action@v1
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v1
|
||||||
- name: Docker Labels
|
- name: Docker Labels
|
||||||
id: meta
|
id: meta
|
||||||
uses: crazy-max/ghaction-docker-meta@v4
|
uses: crazy-max/ghaction-docker-meta@v2
|
||||||
with:
|
with:
|
||||||
images: cupcakearmy/autorestic
|
images: cupcakearmy/autorestic
|
||||||
tags: |
|
tags: |
|
||||||
@@ -23,12 +23,12 @@ jobs:
|
|||||||
type=semver,pattern={{major}}.{{minor}}
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
type=semver,pattern={{major}}
|
type=semver,pattern={{major}}
|
||||||
- name: Login to DockerHub
|
- name: Login to DockerHub
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v1
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v2
|
||||||
with:
|
with:
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
@@ -37,12 +37,17 @@ jobs:
|
|||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: '^1.21'
|
go-version: "^1.16.3"
|
||||||
- name: Build
|
- name: Build
|
||||||
run: go run build/build.go
|
run: go run build/build.go
|
||||||
|
|
||||||
|
- name: Sign
|
||||||
|
uses: tristan-weil/ghaction-checksum-sign-artifact@v1.0.1
|
||||||
|
with:
|
||||||
|
path: dist/*
|
||||||
- name: Release
|
- name: Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
|
24
.github/workflows/ci.yml
vendored
24
.github/workflows/ci.yml
vendored
@@ -1,24 +0,0 @@
|
|||||||
name: CI
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
branches: [master]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- 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 .
|
|
11
CHANGELOG.md
11
CHANGELOG.md
@@ -5,17 +5,6 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [1.7.4] - 2023-01-18
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- Transformer for extracting information. @11mariom
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- Bump docker restic version.
|
|
||||||
- Docs dependencies updated.
|
|
||||||
|
|
||||||
## [1.7.1] - 2022-04-27
|
## [1.7.1] - 2022-04-27
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.23-alpine as builder
|
FROM golang:1.18-alpine as builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY go.* .
|
COPY go.* .
|
||||||
@@ -6,8 +6,7 @@ RUN go mod download
|
|||||||
COPY . .
|
COPY . .
|
||||||
RUN go build
|
RUN go build
|
||||||
|
|
||||||
FROM restic/restic:0.17.1
|
FROM alpine
|
||||||
RUN apk add --no-cache rclone bash curl docker-cli
|
RUN apk add --no-cache restic rclone bash openssh
|
||||||
COPY --from=builder /app/autorestic /usr/bin/autorestic
|
COPY --from=builder /app/autorestic /usr/bin/autorestic
|
||||||
ENTRYPOINT []
|
|
||||||
CMD [ "autorestic" ]
|
CMD [ "autorestic" ]
|
||||||
|
@@ -34,7 +34,7 @@ Autorestic is a wrapper around the amazing [restic](https://restic.net/). While
|
|||||||
- Backup locations to multiple backends
|
- Backup locations to multiple backends
|
||||||
- Snapshot policies and pruning
|
- Snapshot policies and pruning
|
||||||
- Fully encrypted
|
- Fully encrypted
|
||||||
- Before/after backup hooks
|
- Pre/After hooks
|
||||||
- Exclude pattern/files
|
- Exclude pattern/files
|
||||||
- Cron jobs for automatic backup
|
- Cron jobs for automatic backup
|
||||||
- Backup & Restore docker volume
|
- Backup & Restore docker volume
|
||||||
|
@@ -4,11 +4,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
|
||||||
"crypto/sha1"
|
|
||||||
"crypto/sha256"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@@ -21,51 +17,23 @@ import (
|
|||||||
var DIR, _ = filepath.Abs("./dist")
|
var DIR, _ = filepath.Abs("./dist")
|
||||||
|
|
||||||
var targets = map[string][]string{
|
var targets = map[string][]string{
|
||||||
// "aix": {"ppc64"}, // Not supported by fsnotify
|
|
||||||
"darwin": {"amd64", "arm64"},
|
"darwin": {"amd64", "arm64"},
|
||||||
"freebsd": {"386", "amd64", "arm"},
|
"freebsd": {"386", "amd64", "arm"},
|
||||||
"linux": {"386", "amd64", "arm", "arm64", "ppc64le", "mips", "mipsle", "mips64", "mips64le", "s390x"},
|
"linux": {"386", "amd64", "arm", "arm64", "ppc64le", "mips", "mipsle", "mips64", "mips64le"},
|
||||||
"netbsd": {"386", "amd64"},
|
"netbsd": {"386", "amd64"},
|
||||||
"openbsd": {"386", "amd64"},
|
"openbsd": {"386", "amd64"},
|
||||||
// "windows": {"386", "amd64"}, // Not supported by autorestic
|
|
||||||
"solaris": {"amd64"},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type buildOptions struct {
|
type buildOptions struct {
|
||||||
Target, Arch, Version string
|
Target, Arch, Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
func build(options buildOptions, wg *sync.WaitGroup) {
|
||||||
CHECKSUM_MD5 = "MD5SUMS"
|
fmt.Printf("Building %s %s\n", options.Target, options.Arch)
|
||||||
CHECKSUM_SHA_1 = "SHA1SUMS"
|
|
||||||
CHECKSUM_SHA_256 = "SHA256SUMS"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Checksums struct {
|
|
||||||
filename, md5, sha1, sha256 string
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeChecksums(checksums *[]Checksums) {
|
|
||||||
FILE_MD5, _ := os.OpenFile(path.Join(DIR, CHECKSUM_MD5), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
|
|
||||||
defer FILE_MD5.Close()
|
|
||||||
FILE_SHA1, _ := os.OpenFile(path.Join(DIR, CHECKSUM_SHA_1), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
|
|
||||||
defer FILE_SHA1.Close()
|
|
||||||
FILE_SHA256, _ := os.OpenFile(path.Join(DIR, CHECKSUM_SHA_256), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
|
|
||||||
defer FILE_SHA256.Close()
|
|
||||||
|
|
||||||
for _, checksum := range *checksums {
|
|
||||||
fmt.Fprintf(FILE_MD5, "%s %s\n", checksum.md5, checksum.filename)
|
|
||||||
fmt.Fprintf(FILE_SHA1, "%s %s\n", checksum.sha1, checksum.filename)
|
|
||||||
fmt.Fprintf(FILE_SHA256, "%s %s\n", checksum.sha256, checksum.filename)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func build(options buildOptions, wg *sync.WaitGroup, checksums *[]Checksums) {
|
|
||||||
defer wg.Done()
|
|
||||||
|
|
||||||
fmt.Printf("Building: %s %s\n", options.Target, options.Arch)
|
|
||||||
out := fmt.Sprintf("autorestic_%s_%s_%s", options.Version, options.Target, options.Arch)
|
out := fmt.Sprintf("autorestic_%s_%s_%s", options.Version, options.Target, options.Arch)
|
||||||
out = path.Join(DIR, out)
|
out = path.Join(DIR, out)
|
||||||
|
out, _ = filepath.Abs(out)
|
||||||
|
fmt.Println(out)
|
||||||
|
|
||||||
// Build
|
// Build
|
||||||
{
|
{
|
||||||
@@ -94,39 +62,22 @@ func build(options buildOptions, wg *sync.WaitGroup, checksums *[]Checksums) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
wg.Done()
|
||||||
// Checksum
|
|
||||||
{
|
|
||||||
file := out + ".bz2"
|
|
||||||
content, _ := ioutil.ReadFile(file)
|
|
||||||
*checksums = append(*checksums, Checksums{
|
|
||||||
filename: path.Base(file),
|
|
||||||
md5: fmt.Sprintf("%x", md5.Sum(content)),
|
|
||||||
sha1: fmt.Sprintf("%x", sha1.Sum(content)),
|
|
||||||
sha256: fmt.Sprintf("%x", sha256.Sum256(content)),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Built: %s\n", path.Base(out))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
os.RemoveAll(DIR)
|
os.RemoveAll(DIR)
|
||||||
v := internal.VERSION
|
v := internal.VERSION
|
||||||
checksums := []Checksums{}
|
|
||||||
|
|
||||||
// Build async
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for target, archs := range targets {
|
for target, archs := range targets {
|
||||||
for _, arch := range archs {
|
for _, arch := range archs {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go build(buildOptions{
|
build(buildOptions{
|
||||||
Target: target,
|
Target: target,
|
||||||
Arch: arch,
|
Arch: arch,
|
||||||
Version: v,
|
Version: v,
|
||||||
}, &wg, &checksums)
|
}, &wg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
writeChecksums(&checksums)
|
|
||||||
}
|
}
|
||||||
|
40
cmd/root.go
40
cmd/root.go
@@ -55,11 +55,28 @@ func initConfig() {
|
|||||||
viper.SetConfigFile(cfgFile)
|
viper.SetConfigFile(cfgFile)
|
||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
if viper.ConfigFileUsed() == "" {
|
if viper.ConfigFileUsed() == "" {
|
||||||
colors.Error.Printf("cannot read config file %s\n", cfgFile)
|
colors.Error.Println("cannot read config file %s\n", cfgFile)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
configPaths := getConfigPaths()
|
configPaths := []string{"."}
|
||||||
|
|
||||||
|
// Home
|
||||||
|
if home, err := homedir.Dir(); err == nil {
|
||||||
|
configPaths = append(configPaths, home)
|
||||||
|
}
|
||||||
|
|
||||||
|
// XDG_CONFIG_HOME
|
||||||
|
{
|
||||||
|
prefix, found := os.LookupEnv("XDG_CONFIG_HOME")
|
||||||
|
if !found {
|
||||||
|
if home, err := homedir.Dir(); err != nil {
|
||||||
|
prefix = filepath.Join(home, ".config")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xdgConfig := filepath.Join(prefix, "autorestic")
|
||||||
|
configPaths = append(configPaths, xdgConfig)
|
||||||
|
}
|
||||||
for _, cfgPath := range configPaths {
|
for _, cfgPath := range configPaths {
|
||||||
viper.AddConfigPath(cfgPath)
|
viper.AddConfigPath(cfgPath)
|
||||||
}
|
}
|
||||||
@@ -71,22 +88,3 @@ func initConfig() {
|
|||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfigPaths() []string {
|
|
||||||
result := []string{"."}
|
|
||||||
if home, err := homedir.Dir(); err == nil {
|
|
||||||
result = append(result, home)
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
xdgConfigHome, found := os.LookupEnv("XDG_CONFIG_HOME")
|
|
||||||
if !found {
|
|
||||||
if home, err := homedir.Dir(); err == nil {
|
|
||||||
xdgConfigHome = filepath.Join(home, ".config")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xdgConfig := filepath.Join(xdgConfigHome, "autorestic")
|
|
||||||
result = append(result, xdgConfig)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
@@ -1,36 +0,0 @@
|
|||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/mitchellh/go-homedir"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"slices"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
const xdgConfigHome = "XDG_CONFIG_HOME"
|
|
||||||
|
|
||||||
func assertContains(t *testing.T, array []string, element string) {
|
|
||||||
if !slices.Contains(array, element) {
|
|
||||||
t.Errorf("Expected %s to be contained in %s", element, array)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConfigResolving(t *testing.T) {
|
|
||||||
t.Run("~/.config/autorestic is used if XDG_CONFIG_HOME is not set", func(t *testing.T) {
|
|
||||||
// Override env using testing so that env gets restored after test
|
|
||||||
t.Setenv(xdgConfigHome, "")
|
|
||||||
_ = os.Unsetenv("XDG_CONFIG_HOME")
|
|
||||||
configPaths := getConfigPaths()
|
|
||||||
homeDir, _ := homedir.Dir()
|
|
||||||
expectedConfigPath := filepath.Join(homeDir, ".config/autorestic")
|
|
||||||
assertContains(t, configPaths, expectedConfigPath)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("XDG_CONFIG_HOME is respected if set", func(t *testing.T) {
|
|
||||||
t.Setenv(xdgConfigHome, "/foo/bar")
|
|
||||||
|
|
||||||
configPaths := getConfigPaths()
|
|
||||||
assertContains(t, configPaths, filepath.Join("/", "foo", "bar", "autorestic"))
|
|
||||||
})
|
|
||||||
}
|
|
@@ -1,81 +0,0 @@
|
|||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/cupcakearmy/autorestic/internal"
|
|
||||||
"github.com/cupcakearmy/autorestic/internal/colors"
|
|
||||||
"github.com/cupcakearmy/autorestic/internal/lock"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
var unlockCmd = &cobra.Command{
|
|
||||||
Use: "unlock",
|
|
||||||
Short: "Unlock autorestic only if you are sure that no other instance is running",
|
|
||||||
Long: `Unlock autorestic only if you are sure that no other instance is running.
|
|
||||||
To check you can run "ps aux | grep autorestic".`,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
internal.GetConfig()
|
|
||||||
|
|
||||||
force, _ := cmd.Flags().GetBool("force")
|
|
||||||
|
|
||||||
if !force && isAutoresticRunning() {
|
|
||||||
colors.Error.Print("Another autorestic instance is running. Are you sure you want to unlock? (yes/no): ")
|
|
||||||
var response string
|
|
||||||
fmt.Scanln(&response)
|
|
||||||
if strings.ToLower(response) != "yes" {
|
|
||||||
colors.Primary.Println("Unlocking aborted.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err := lock.Unlock()
|
|
||||||
if err != nil {
|
|
||||||
colors.Error.Println("Could not unlock:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
colors.Success.Println("Unlock successful")
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
rootCmd.AddCommand(unlockCmd)
|
|
||||||
unlockCmd.Flags().Bool("force", false, "force unlock")
|
|
||||||
}
|
|
||||||
|
|
||||||
// isAutoresticRunning checks if autorestic is running
|
|
||||||
// and returns true if it is.
|
|
||||||
// It also prints the processes to stdout.
|
|
||||||
func isAutoresticRunning() bool {
|
|
||||||
cmd := exec.Command("sh", "-c", "ps aux | grep autorestic")
|
|
||||||
var out bytes.Buffer
|
|
||||||
cmd.Stdout = &out
|
|
||||||
err := cmd.Run()
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
lines := strings.Split(out.String(), "\n")
|
|
||||||
autoresticProcesses := []string{}
|
|
||||||
currentPid := fmt.Sprint(os.Getpid())
|
|
||||||
|
|
||||||
for _, line := range lines {
|
|
||||||
if strings.Contains(line, "autorestic") && !strings.Contains(line, "grep autorestic") && !strings.Contains(line, currentPid) {
|
|
||||||
autoresticProcesses = append(autoresticProcesses, line)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(autoresticProcesses) > 0 {
|
|
||||||
colors.Faint.Println("Found autorestic processes:")
|
|
||||||
for _, proc := range autoresticProcesses {
|
|
||||||
colors.Faint.Println(proc)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
15
docs/.codedoc/build.ts
Normal file
15
docs/.codedoc/build.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { build } from '@codedoc/core';
|
||||||
|
|
||||||
|
import { config } from './config';
|
||||||
|
import { installTheme$ } from './content/theme';
|
||||||
|
import { content } from './content';
|
||||||
|
|
||||||
|
|
||||||
|
build(config, content, installTheme$, {
|
||||||
|
resolve: {
|
||||||
|
modules: ['.codedoc/node_modules']
|
||||||
|
},
|
||||||
|
resolveLoader: {
|
||||||
|
modules: ['.codedoc/node_modules']
|
||||||
|
}
|
||||||
|
});
|
24
docs/.codedoc/config.ts
Normal file
24
docs/.codedoc/config.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { configuration } from '@codedoc/core'
|
||||||
|
|
||||||
|
export const config = configuration({
|
||||||
|
src: {
|
||||||
|
base: 'markdown',
|
||||||
|
},
|
||||||
|
dest: {
|
||||||
|
html: './build',
|
||||||
|
assets: './build',
|
||||||
|
bundle: './_',
|
||||||
|
styles: './_',
|
||||||
|
},
|
||||||
|
page: {
|
||||||
|
title: {
|
||||||
|
base: 'Autorestic',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
misc: {
|
||||||
|
github: {
|
||||||
|
user: 'cupcakearmy',
|
||||||
|
repo: 'autorestic',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
19
docs/.codedoc/content/footer.tsx
Normal file
19
docs/.codedoc/content/footer.tsx
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { CodedocConfig } from '@codedoc/core';
|
||||||
|
import { Footer as _Footer, GitterToggle$, Watermark} from '@codedoc/core/components';
|
||||||
|
|
||||||
|
|
||||||
|
export function Footer(config: CodedocConfig, renderer: any) {
|
||||||
|
let github$;
|
||||||
|
if (config.misc?.github)
|
||||||
|
github$ = <a href={`https://github.com/${config.misc.github.user}/${config.misc.github.repo}/`}
|
||||||
|
target="_blank">GitHub</a>;
|
||||||
|
|
||||||
|
let community$;
|
||||||
|
if (config.misc?.gitter)
|
||||||
|
community$ = <GitterToggle$ room={config.misc.gitter.room}/>
|
||||||
|
|
||||||
|
if (github$ && community$) return <_Footer>{github$}<hr/>{community$}</_Footer>;
|
||||||
|
else if (github$) return <_Footer>{github$}</_Footer>;
|
||||||
|
else if (community$) return <_Footer>{community$}</_Footer>;
|
||||||
|
else return <_Footer><Watermark/></_Footer>;
|
||||||
|
}
|
21
docs/.codedoc/content/header.tsx
Normal file
21
docs/.codedoc/content/header.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { CodedocConfig } from '@codedoc/core';
|
||||||
|
import { Header as _Header, GithubButton, Watermark } from '@codedoc/core/components';
|
||||||
|
|
||||||
|
|
||||||
|
export function Header(config: CodedocConfig, renderer: any) {
|
||||||
|
return (
|
||||||
|
<_Header>{config.misc?.github ?
|
||||||
|
<fragment>
|
||||||
|
<GithubButton action={config.misc.github.action || 'Star'}
|
||||||
|
repo={config.misc.github.repo}
|
||||||
|
user={config.misc.github.user}
|
||||||
|
large={config.misc.github.large === true}
|
||||||
|
count={config.misc.github.count !== false}
|
||||||
|
standardIcon={config.misc.github.standardIcon !== false}/>
|
||||||
|
<br/><br/>
|
||||||
|
</fragment>
|
||||||
|
: ''}
|
||||||
|
<Watermark/>
|
||||||
|
</_Header>
|
||||||
|
)
|
||||||
|
}
|
57
docs/.codedoc/content/index.tsx
Normal file
57
docs/.codedoc/content/index.tsx
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import { RendererLike } from '@connectv/html'
|
||||||
|
import { File } from 'rxline/fs'
|
||||||
|
import {
|
||||||
|
Page,
|
||||||
|
Meta,
|
||||||
|
ContentNav,
|
||||||
|
Fonts,
|
||||||
|
ToC,
|
||||||
|
GithubSearch$,
|
||||||
|
} from '@codedoc/core/components'
|
||||||
|
|
||||||
|
import { config } from '../config'
|
||||||
|
import { Header } from './header'
|
||||||
|
import { Footer } from './footer'
|
||||||
|
|
||||||
|
export function content(
|
||||||
|
_content: HTMLElement,
|
||||||
|
toc: HTMLElement,
|
||||||
|
renderer: RendererLike<any, any>,
|
||||||
|
file: File<string>
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
<Page
|
||||||
|
title={config.page.title.extractor(_content, config, file)}
|
||||||
|
favicon={config.page.favicon}
|
||||||
|
meta={<Meta {...config.page.meta} />}
|
||||||
|
fonts={<Fonts {...config.page.fonts} />}
|
||||||
|
scripts={config.page.scripts}
|
||||||
|
stylesheets={config.page.stylesheets}
|
||||||
|
header={<Header {...config} />}
|
||||||
|
footer={<Footer {...config} />}
|
||||||
|
toc={
|
||||||
|
<ToC
|
||||||
|
default={'open'}
|
||||||
|
search={
|
||||||
|
config.misc?.github ? (
|
||||||
|
<GithubSearch$
|
||||||
|
repo={config.misc.github.repo}
|
||||||
|
user={config.misc.github.user}
|
||||||
|
root={config.src.base}
|
||||||
|
pick={config.src.pick.source}
|
||||||
|
drop={config.src.drop.source}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{toc}
|
||||||
|
</ToC>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{_content}
|
||||||
|
<ContentNav content={_content} />
|
||||||
|
</Page>
|
||||||
|
)
|
||||||
|
}
|
8
docs/.codedoc/content/theme.ts
Normal file
8
docs/.codedoc/content/theme.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { funcTransport } from '@connectv/sdh/transport';
|
||||||
|
import { useTheme } from '@codedoc/core/transport';
|
||||||
|
|
||||||
|
import { theme } from '../theme';
|
||||||
|
|
||||||
|
|
||||||
|
export function installTheme() { useTheme(theme); }
|
||||||
|
export const installTheme$ = /*#__PURE__*/funcTransport(installTheme);
|
10811
docs/.codedoc/package-lock.json
generated
Normal file
10811
docs/.codedoc/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
5
docs/.codedoc/package.json
Normal file
5
docs/.codedoc/package.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"@codedoc/core": "^0.2.24"
|
||||||
|
}
|
||||||
|
}
|
18
docs/.codedoc/serve.ts
Normal file
18
docs/.codedoc/serve.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { join } from 'path';
|
||||||
|
import { serve } from '@codedoc/core';
|
||||||
|
|
||||||
|
import { config } from './config';
|
||||||
|
import { content } from './content';
|
||||||
|
import { installTheme$ } from './content/theme';
|
||||||
|
|
||||||
|
|
||||||
|
const root = join(__dirname, '../');
|
||||||
|
|
||||||
|
serve(root, config, content, installTheme$, {
|
||||||
|
resolve: {
|
||||||
|
modules: ['.codedoc/node_modules']
|
||||||
|
},
|
||||||
|
resolveLoader: {
|
||||||
|
modules: ['.codedoc/node_modules']
|
||||||
|
}
|
||||||
|
});
|
11
docs/.codedoc/theme.ts
Normal file
11
docs/.codedoc/theme.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { createTheme } from '@codedoc/core/transport';
|
||||||
|
|
||||||
|
|
||||||
|
export const theme = /*#__PURE__*/createTheme({
|
||||||
|
light: {
|
||||||
|
primary: '#1eb2a6'
|
||||||
|
},
|
||||||
|
dark: {
|
||||||
|
primary: '#1eb2a6'
|
||||||
|
}
|
||||||
|
});
|
26
docs/.codedoc/tsconfig.json
Normal file
26
docs/.codedoc/tsconfig.json
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es6",
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"declaration": false,
|
||||||
|
"strictNullChecks": true,
|
||||||
|
"strictFunctionTypes": true,
|
||||||
|
"noImplicitThis": true,
|
||||||
|
"alwaysStrict": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"jsx": "react",
|
||||||
|
"jsxFactory": "renderer.create",
|
||||||
|
"lib": [
|
||||||
|
"es2017",
|
||||||
|
"dom"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"./**/*"
|
||||||
|
]
|
||||||
|
}
|
22
docs/.codedoc/watch.ts
Normal file
22
docs/.codedoc/watch.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { exec, spawn } from 'child_process';
|
||||||
|
import { config } from './config';
|
||||||
|
|
||||||
|
|
||||||
|
const cmd = 'ts-node-dev';
|
||||||
|
const params = `--project .codedoc/tsconfig.json`
|
||||||
|
+ ` -T --watch ${config.src.base},.codedoc`
|
||||||
|
+ ` --ignore-watch .codedoc/node_modules`
|
||||||
|
+ ` .codedoc/serve`;
|
||||||
|
|
||||||
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
const child = exec(cmd + ' ' + params);
|
||||||
|
|
||||||
|
child.stdout?.pipe(process.stdout);
|
||||||
|
child.stderr?.pipe(process.stderr);
|
||||||
|
child.on('close', () => {});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const child = spawn(cmd, [params], { stdio: 'inherit', shell: 'bash' });
|
||||||
|
child.on('close', () => {});
|
||||||
|
}
|
2
docs/.gitignore
vendored
2
docs/.gitignore
vendored
@@ -1,2 +1,2 @@
|
|||||||
node_modules
|
node_modules
|
||||||
.next
|
build
|
@@ -1 +0,0 @@
|
|||||||
v22.7.0
|
|
54
docs/markdown/_toc.md
Normal file
54
docs/markdown/_toc.md
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
[Home](/)
|
||||||
|
[Quick Start](/quick)
|
||||||
|
[Installation](/installation)
|
||||||
|
[Configuration](/config)
|
||||||
|
[Upgrade](/upgrade)
|
||||||
|
|
||||||
|
> :Collapse label=Locations
|
||||||
|
>
|
||||||
|
> [Overview](/location/overview)
|
||||||
|
> [Hooks](/location/hooks)
|
||||||
|
>
|
||||||
|
> > :Collapse label=Options
|
||||||
|
> >
|
||||||
|
> > [Overview](/location/options)
|
||||||
|
> > [Excluding Files](/location/exclude)
|
||||||
|
> > [Forget Policy](/location/forget)
|
||||||
|
> > [Copy](/location/copy)
|
||||||
|
>
|
||||||
|
> [Cron](/location/cron)
|
||||||
|
> [Docker Volumes](/location/docker)
|
||||||
|
|
||||||
|
> :Collapse label=Backend
|
||||||
|
>
|
||||||
|
> [Overview](/backend/overview)
|
||||||
|
> [Available Backends](/backend/available)
|
||||||
|
> [Options](/backend/options)
|
||||||
|
> [Environment](/backend/env)
|
||||||
|
|
||||||
|
> :Collapse label=CLI
|
||||||
|
>
|
||||||
|
> [General](/cli/general)
|
||||||
|
> [Info](/cli/info)
|
||||||
|
> [Check](/cli/check)
|
||||||
|
> [Completion](/cli/completion)
|
||||||
|
> [Backup](/cli/backup)
|
||||||
|
> [Restore](/cli/restore)
|
||||||
|
> [Forget](/cli/forget)
|
||||||
|
> [Cron](/cli/cron)
|
||||||
|
> [Exec](/cli/exec)
|
||||||
|
> [Install](/cli/install)
|
||||||
|
> [Uninstall](/cli/uninstall)
|
||||||
|
> [Upgrade](/cli/upgrade)
|
||||||
|
|
||||||
|
> :Collapse label=Migration
|
||||||
|
>
|
||||||
|
> [0.x → 1.0](/migration/0.x_1.0)
|
||||||
|
> [1.4 → 1.5](/migration/1.4_1.5)
|
||||||
|
|
||||||
|
[Examples](/examples)
|
||||||
|
[Docker](/docker)
|
||||||
|
[QA](/qa)
|
||||||
|
[Community](/community)
|
||||||
|
[Contributors](/contrib)
|
||||||
|
|
@@ -83,3 +83,5 @@ backends:
|
|||||||
user: user
|
user: user
|
||||||
password: pass
|
password: pass
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -63,3 +63,5 @@ backends:
|
|||||||
type: b2
|
type: b2
|
||||||
path: myBucket
|
path: myBucket
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -15,3 +15,5 @@ backend:
|
|||||||
```
|
```
|
||||||
|
|
||||||
In this example, whenever `autorestic` runs `restic backup` it will append a `--tag abc --tag` to the native command.
|
In this example, whenever `autorestic` runs `restic backup` it will append a `--tag abc --tag` to the native command.
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
20
docs/markdown/backend/overview.md
Normal file
20
docs/markdown/backend/overview.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# 💽 Backends
|
||||||
|
|
||||||
|
Backends are the outputs of the backup process. Each location needs at least one.
|
||||||
|
|
||||||
|
Note: names of backends MUST be lower case!
|
||||||
|
|
||||||
|
```yaml | .autorestic.yml
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
backends:
|
||||||
|
name-of-backend:
|
||||||
|
type: local
|
||||||
|
path: /data/my/backups
|
||||||
|
```
|
||||||
|
|
||||||
|
## Types
|
||||||
|
|
||||||
|
We restic supports multiple types of backends. See the [full list](/backend/available) for details.
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -21,3 +21,5 @@ autorestic backup -l foo -l bar
|
|||||||
```bash
|
```bash
|
||||||
autorestic backup -l location@backend
|
autorestic backup -l location@backend
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -7,3 +7,5 @@ autorestic check
|
|||||||
Checks locations and backends are configured properly and initializes them if they are not already.
|
Checks locations and backends are configured properly and initializes them if they are not already.
|
||||||
|
|
||||||
This is mostly an internal command, but useful to verify if a backend is configured correctly.
|
This is mostly an internal command, but useful to verify if a backend is configured correctly.
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -13,3 +13,5 @@ Supported shells are
|
|||||||
- powershell
|
- powershell
|
||||||
|
|
||||||
To see how to install run `autorestic help completion` and follow the instructions for your specific shell
|
To see how to install run `autorestic help completion` and follow the instructions for your specific shell
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -9,3 +9,5 @@ This command is mostly intended to be triggered by an automated system like syst
|
|||||||
It will run cron jobs as [specified in the cron section](/location/cron) of a specific location.
|
It will run cron jobs as [specified in the cron section](/location/cron) of a specific location.
|
||||||
|
|
||||||
The `--lean` flag will omit output like _skipping location x: not due yet_. This can be useful if you are dumping the output of the cron job to a log file and don't want to be overwhelmed by the output log.
|
The `--lean` flag will omit output like _skipping location x: not due yet_. This can be useful if you are dumping the output of the cron job to a log file and don't want to be overwhelmed by the output log.
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -11,3 +11,5 @@ autorestic exec -av -- snapshots
|
|||||||
```
|
```
|
||||||
|
|
||||||
With `exec` you can basically run every cli command that you would be able to run with the restic cli. It only pre-fills path, key, etc.
|
With `exec` you can basically run every cli command that you would be able to run with the restic cli. It only pre-fills path, key, etc.
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -4,8 +4,10 @@
|
|||||||
autorestic forget [-l, --location] [-a, --all] [--dry-run] [--prune]
|
autorestic forget [-l, --location] [-a, --all] [--dry-run] [--prune]
|
||||||
```
|
```
|
||||||
|
|
||||||
This will prune and remove old data form the backends according to the [keep policy you have specified for the location](/location/options/forget).
|
This will prune and remove old data form the backends according to the [keep policy you have specified for the location](/location/forget).
|
||||||
|
|
||||||
The `--dry-run` flag will do a dry run showing what would have been deleted, but won't touch the actual data.
|
The `--dry-run` flag will do a dry run showing what would have been deleted, but won't touch the actual data.
|
||||||
|
|
||||||
The `--prune` flag will also [prune the data](https://restic.readthedocs.io/en/latest/060_forget.html#removing-backup-snapshots). This is a costly operation that can take longer, however it will free up the actual space.
|
The `--prune` flag will also [prune the data](https://restic.readthedocs.io/en/latest/060_forget.html#removing-backup-snapshots). This is a costly operation that can take longer, however it will free up the actual space.
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -34,3 +34,5 @@ With `--restic-bin` you can specify to run a specific restic binary. This can be
|
|||||||
```bash
|
```bash
|
||||||
autorestic --restic-bin /some/path/to/my/custom/restic/binary
|
autorestic --restic-bin /some/path/to/my/custom/restic/binary
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -14,3 +14,5 @@ autorestic info
|
|||||||
```bash
|
```bash
|
||||||
autorestic -c path/to/some/config.yml info
|
autorestic -c path/to/some/config.yml info
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -5,3 +5,5 @@ Installs both restic and autorestic to `/usr/local/bin`.
|
|||||||
```bash
|
```bash
|
||||||
autorestic install
|
autorestic install
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -15,3 +15,5 @@ autorestic restore -l home --from hdd --to /path/where/to/restore
|
|||||||
```
|
```
|
||||||
|
|
||||||
This will restore the location `home` to the `/path/where/to/restore` folder and taking the data from the backend `hdd`
|
This will restore the location `home` to the `/path/where/to/restore` folder and taking the data from the backend `hdd`
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -5,3 +5,5 @@ Uninstalls both restic and autorestic from `/usr/local/bin`.
|
|||||||
```bash
|
```bash
|
||||||
autorestic uninstall
|
autorestic uninstall
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -7,3 +7,5 @@ autorestic upgrade
|
|||||||
```
|
```
|
||||||
|
|
||||||
Updates both restic and autorestic automagically.
|
Updates both restic and autorestic automagically.
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -1,7 +1,5 @@
|
|||||||
# 🏘 Community
|
# 🏘 Community
|
||||||
|
|
||||||
## Software
|
|
||||||
|
|
||||||
A list of community driven projects. (No official affiliation)
|
A list of community driven projects. (No official affiliation)
|
||||||
|
|
||||||
- SystemD Units: <https://gitlab.com/py_crash/autorestic-systemd-units>
|
- SystemD Units: <https://gitlab.com/py_crash/autorestic-systemd-units>
|
||||||
@@ -10,8 +8,5 @@ A list of community driven projects. (No official affiliation)
|
|||||||
- Ansible Role: <https://github.com/ItsNotGoodName/ansible-role-autorestic>
|
- Ansible Role: <https://github.com/ItsNotGoodName/ansible-role-autorestic>
|
||||||
- Ansible Role: <https://github.com/FuzzyMistborn/ansible-role-autorestic>
|
- Ansible Role: <https://github.com/FuzzyMistborn/ansible-role-autorestic>
|
||||||
- Ansible Role: <https://0xacab.org/varac-projects/ansible-role-autorestic>
|
- Ansible Role: <https://0xacab.org/varac-projects/ansible-role-autorestic>
|
||||||
- Ansible Role: <https://github.com/dbrennand/ansible-role-autorestic>
|
|
||||||
|
|
||||||
## Writing
|
> :ToCPrevNext
|
||||||
|
|
||||||
- [restic: excellent resource for local and cloud backup](https://notes.nicfab.eu/en/posts/restic/)
|
|
@@ -2,11 +2,10 @@
|
|||||||
|
|
||||||
## Path
|
## Path
|
||||||
|
|
||||||
By default autorestic searches for a `.autorestic.yml` file in the current directory, your home folder and your XDG config folder (`~/.config/` by default):
|
By default autorestic searches for a `.autorestic.yml` file in the current directory and your home folder.
|
||||||
|
|
||||||
- `./.autorestic.yml`
|
- `./.autorestic.yml`
|
||||||
- `~/.autorestic.yml`
|
- `~/.autorestic.yml`
|
||||||
- `~/.config/autorestic/.autorestic.yml`
|
|
||||||
|
|
||||||
You can also specify a custom file with the `-c path/to/some/config.yml`
|
You can also specify a custom file with the `-c path/to/some/config.yml`
|
||||||
|
|
||||||
@@ -56,8 +55,6 @@ version: 2
|
|||||||
|
|
||||||
extras:
|
extras:
|
||||||
hooks: &foo
|
hooks: &foo
|
||||||
prevalidate:
|
|
||||||
- echo "Wake up!"
|
|
||||||
before:
|
before:
|
||||||
- echo "Hello"
|
- echo "Hello"
|
||||||
after:
|
after:
|
||||||
@@ -86,3 +83,5 @@ locations:
|
|||||||
forget:
|
forget:
|
||||||
<<: *bar
|
<<: *bar
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -17,3 +17,5 @@ This amazing people helped the project!
|
|||||||
- @TheForcer - Typos.
|
- @TheForcer - Typos.
|
||||||
- @themorlan - Typos.
|
- @themorlan - Typos.
|
||||||
- @somebox - Typos.
|
- @somebox - Typos.
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -36,3 +36,5 @@ locations:
|
|||||||
to:
|
to:
|
||||||
- somewhere-else
|
- somewhere-else
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -13,8 +13,10 @@ Autorestic is a wrapper around the amazing [restic](https://restic.net/). While
|
|||||||
- Backup locations to multiple backends
|
- Backup locations to multiple backends
|
||||||
- Snapshot policies and pruning
|
- Snapshot policies and pruning
|
||||||
- Fully encrypted
|
- Fully encrypted
|
||||||
- Before/after backup hooks
|
- Pre/After hooks
|
||||||
- Exclude pattern/files
|
- Exclude pattern/files
|
||||||
- Cron jobs for automatic backup
|
- Cron jobs for automatic backup
|
||||||
- Backup & Restore docker volumes
|
- Backup & Restore docker volumes
|
||||||
- Generated completions for `[bash|zsh|fish|powershell]`
|
- Generated completions for `[bash|zsh|fish|powershell]`
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -5,7 +5,7 @@ Linux & macOS. Windows is not supported. If you have problems installing please
|
|||||||
Autorestic requires `bash`, `wget` and `bzip2` to be installed. For most systems these should be already installed.
|
Autorestic requires `bash`, `wget` and `bzip2` to be installed. For most systems these should be already installed.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wget -qO - https://raw.githubusercontent.com/cupcakearmy/autorestic/master/install.sh | bash
|
wget -qO - https://raw.githubusercontent.com/CupCakeArmy/autorestic/master/install.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
## Alternatives
|
## Alternatives
|
||||||
@@ -24,10 +24,8 @@ You can download the right binary from the release page and simply copy it to `/
|
|||||||
|
|
||||||
If you are on macOS you can install through brew: `brew install autorestic`.
|
If you are on macOS you can install through brew: `brew install autorestic`.
|
||||||
|
|
||||||
### Fedora
|
|
||||||
|
|
||||||
Fedora users can install the [autorestic](https://src.fedoraproject.org/rpms/autorestic/) package with `dnf install autorestic`.
|
|
||||||
|
|
||||||
### AUR
|
### AUR
|
||||||
|
|
||||||
If you are on Arch there is an [AUR Package](https://aur.archlinux.org/packages/autorestic-bin/)
|
~~If you are on Arch there is an [AUR Package](https://aur.archlinux.org/packages/autorestic-bin/) (looking for maintainers).~~ - Deprecated
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -1,6 +1,6 @@
|
|||||||
# Cron
|
# Cron
|
||||||
|
|
||||||
Often it is useful to trigger backups automatically. For this, we can specify a `cron` attribute to each location.
|
Often it is usefully to trigger backups automatically. For this we can specify a `cron` attribute to each location.
|
||||||
|
|
||||||
```yaml | .autorestic.yml
|
```yaml | .autorestic.yml
|
||||||
locations:
|
locations:
|
||||||
@@ -10,15 +10,15 @@ locations:
|
|||||||
cron: '0 3 * * 0' # Every Sunday at 3:00
|
cron: '0 3 * * 0' # Every Sunday at 3:00
|
||||||
```
|
```
|
||||||
|
|
||||||
Here is an awesome website with [some examples](https://crontab.guru/examples.html) and an [explorer](https://crontab.guru/).
|
Here is a awesome website with [some examples](https://crontab.guru/examples.html) and an [explorer](https://crontab.guru/)
|
||||||
|
|
||||||
## Installing the cron
|
## Installing the cron
|
||||||
|
|
||||||
**This has to be done only once, regardless of how many cron jobs you have in your config file.**
|
**This has to be done only once, regardless of now many cron jobs you have in your config file.**
|
||||||
|
|
||||||
To actually enable cron jobs you need something to call `autorestic cron` on a timed schedule.
|
To actually enable cron jobs you need something to call `autorestic cron` on a timed schedule.
|
||||||
Note that the schedule has nothing to do with the `cron` attribute in each location.
|
Note that the schedule has nothing to do with the `cron` attribute in each location.
|
||||||
My advice would be to trigger the command every 5min, but if you have a cronjob that runs only once a week, it's probably enough to schedule it once a day.
|
My advise would be to trigger the command every 5min, but if you have a cronjob that runs only once a week, it's probably enough to schedule it once a day.
|
||||||
|
|
||||||
### Crontab
|
### Crontab
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ Then paste this at the bottom of the file and save it. Note that in this specifi
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# This is required, as it otherwise cannot find restic as a command.
|
# This is required, as it otherwise cannot find restic as a command.
|
||||||
PATH="/usr/local/bin:$PATH"
|
PATH="/usr/local/bin:/usr/bin:/bin"
|
||||||
|
|
||||||
# Example running every 5 minutes
|
# Example running every 5 minutes
|
||||||
*/5 * * * * autorestic -c /path/to/my/.autorestic.yml --ci cron
|
*/5 * * * * autorestic -c /path/to/my/.autorestic.yml --ci cron
|
||||||
@@ -50,4 +50,6 @@ To debug a cron job you can use
|
|||||||
|
|
||||||
Now you can add as many `cron` attributes as you wish in the config file ⏱
|
Now you can add as many `cron` attributes as you wish in the config file ⏱
|
||||||
|
|
||||||
> Also note that manually triggered backups with `autorestic backup` will not influence the cron timeline, they are intentionally not linked.
|
> Also note that manually triggered backups with `autorestic backup` will not influence the cron timeline, they are willingly not linked.
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -18,7 +18,7 @@ services:
|
|||||||
|
|
||||||
```yaml | .autorestic.yml
|
```yaml | .autorestic.yml
|
||||||
locations:
|
locations:
|
||||||
hello:
|
foo:
|
||||||
from: my-data
|
from: my-data
|
||||||
type: volume
|
type: volume
|
||||||
# ...
|
# ...
|
||||||
@@ -35,3 +35,5 @@ autorestic restore -l hello
|
|||||||
```
|
```
|
||||||
|
|
||||||
The volume has to exists whenever backing up or restoring.
|
The volume has to exists whenever backing up or restoring.
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -16,3 +16,5 @@ locations:
|
|||||||
- '*.abc'
|
- '*.abc'
|
||||||
exclude-file: .gitignore
|
exclude-file: .gitignore
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -53,3 +53,5 @@ locations:
|
|||||||
forget:
|
forget:
|
||||||
keep-last: 5
|
keep-last: 5
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -6,28 +6,23 @@ They consist of a list of commands that will be executed in the same directory a
|
|||||||
|
|
||||||
The following hooks groups are supported, none are required:
|
The following hooks groups are supported, none are required:
|
||||||
|
|
||||||
- `prevalidate`
|
|
||||||
- `before`
|
- `before`
|
||||||
- `after`
|
- `after`
|
||||||
- `failure`
|
- `failure`
|
||||||
- `success`
|
- `success`
|
||||||
|
|
||||||
The difference between `prevalidate` and `before` hooks are that `prevalidate` is run before checking the backup location is valid, including checking that the `from` directories exist. This can be useful, for example, to mount the source filesystem that contains the directories listed in `from`.
|
|
||||||
|
|
||||||
```yml | .autorestic.yml
|
```yml | .autorestic.yml
|
||||||
locations:
|
locations:
|
||||||
my-location:
|
my-location:
|
||||||
from: /data
|
from: /data
|
||||||
to: my-backend
|
to: my-backend
|
||||||
hooks:
|
hooks:
|
||||||
prevalidate:
|
|
||||||
- echo "Checks"
|
|
||||||
before:
|
before:
|
||||||
- echo "One"
|
- echo "One"
|
||||||
- echo "Two"
|
- echo "Two"
|
||||||
- echo "Three"
|
- echo "Three"
|
||||||
after:
|
after:
|
||||||
- echo "Bye"
|
- echo "Byte"
|
||||||
failure:
|
failure:
|
||||||
- echo "Something went wrong"
|
- echo "Something went wrong"
|
||||||
success:
|
success:
|
||||||
@@ -36,15 +31,13 @@ locations:
|
|||||||
|
|
||||||
## Flowchart
|
## Flowchart
|
||||||
|
|
||||||
1. `prevalidate` hook
|
1. `before` hook
|
||||||
2. Check backup location
|
2. Run backup
|
||||||
3. `before` hook
|
3. `after` hook
|
||||||
4. Run backup
|
4. - `success` hook if no errors were found
|
||||||
5. `after` hook
|
|
||||||
6. - `success` hook if no errors were found
|
|
||||||
- `failure` hook if at least one error was encountered
|
- `failure` hook if at least one error was encountered
|
||||||
|
|
||||||
If either the `prevalidate` or `before` hook encounters errors then the backup and `after` hooks will be skipped and only the `failed` hooks will run.
|
If the `before` hook encounters errors the backup and `after` hooks will be skipped and only the `failed` hooks will run.
|
||||||
|
|
||||||
## Environment variables
|
## Environment variables
|
||||||
|
|
||||||
@@ -83,3 +76,5 @@ AUTORESTIC_LOCATION=bar
|
|||||||
AUTORESTIC_FILES_ADDED_0=42
|
AUTORESTIC_FILES_ADDED_0=42
|
||||||
AUTORESTIC_FILES_ADDED_FOO=42
|
AUTORESTIC_FILES_ADDED_FOO=42
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -63,3 +63,5 @@ backends:
|
|||||||
locations:
|
locations:
|
||||||
# ...
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -4,7 +4,6 @@ Locations can be seen as the input to the backup process. Generally this is simp
|
|||||||
The paths can be relative from the config file. A location can have multiple backends, so that the data is secured across multiple servers.
|
The paths can be relative from the config file. A location can have multiple backends, so that the data is secured across multiple servers.
|
||||||
|
|
||||||
Note: names of locations MUST be lower case!
|
Note: names of locations MUST be lower case!
|
||||||
|
|
||||||
```yaml | .autorestic.yml
|
```yaml | .autorestic.yml
|
||||||
version: 2
|
version: 2
|
||||||
|
|
||||||
@@ -31,3 +30,5 @@ Paths can be absolute or relative. If relative they are resolved relative to the
|
|||||||
## `to`
|
## `to`
|
||||||
|
|
||||||
This is either a single backend or an array of backends. The backends have to be configured in the same config file.
|
This is either a single backend or an array of backends. The backends have to be configured in the same config file.
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -22,3 +22,5 @@ remote:
|
|||||||
```
|
```
|
||||||
|
|
||||||
Other than the config file there is a new `-v, --verbose` flag which shows the output of native commands, which are now hidden by default.
|
Other than the config file there is a new `-v, --verbose` flag which shows the output of native commands, which are now hidden by default.
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -64,3 +64,5 @@ Autorestic changed the way backups are referenced. Before we took the paths as t
|
|||||||
```bash
|
```bash
|
||||||
autorestic exec -va -- tag --add ar:location:LOCATION_NAME # Only if you have only one location
|
autorestic exec -va -- tag --add ar:location:LOCATION_NAME # Only if you have only one location
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -6,3 +6,5 @@ This happens when autorestic needs to write to the config file: e.g. when we are
|
|||||||
Unfortunately during this process formatting and comments are lost because the `yaml` library used is not comment and/or format aware.
|
Unfortunately during this process formatting and comments are lost because the `yaml` library used is not comment and/or format aware.
|
||||||
|
|
||||||
That is why autorestic will place a copy of your old config next to the one we are writing to.
|
That is why autorestic will place a copy of your old config next to the one we are writing to.
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -3,7 +3,7 @@
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wget -qO - https://raw.githubusercontent.com/cupcakearmy/autorestic/master/install.sh | bash
|
wget -qO - https://raw.githubusercontent.com/CupCakeArmy/autorestic/master/install.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
See [installation](/installation) for alternative options.
|
See [installation](/installation) for alternative options.
|
||||||
@@ -82,3 +82,5 @@ autorestic restore -l home --from hdd --to /path/where/to/restore
|
|||||||
```
|
```
|
||||||
|
|
||||||
This will restore the location `home` from the backend `hdd` to the given path.
|
This will restore the location `home` from the backend `hdd` to the given path.
|
||||||
|
|
||||||
|
> :ToCPrevNext
|
@@ -1,6 +0,0 @@
|
|||||||
const withNextra = require('nextra')({
|
|
||||||
theme: 'nextra-theme-docs',
|
|
||||||
themeConfig: './theme.config.jsx',
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = withNextra()
|
|
1149
docs/package-lock.json
generated
Normal file
1149
docs/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,10 @@
|
|||||||
{
|
{
|
||||||
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "NEXT_TELEMETRY_DISABLED=1 next build",
|
"build": "codedoc install && codedoc build",
|
||||||
"dev": "NEXT_TELEMETRY_DISABLED=1 next",
|
"dev": "codedoc serve"
|
||||||
"start": "NEXT_TELEMETRY_DISABLED=1 next start"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"next": "^14.2.7",
|
"@codedoc/cli": "^0.2.8"
|
||||||
"nextra": "^2.13.4",
|
}
|
||||||
"nextra-theme-docs": "^2.13.4",
|
|
||||||
"react": "^18.3.1",
|
|
||||||
"react-dom": "^18.3.1"
|
|
||||||
},
|
|
||||||
"packageManager": "pnpm@9.9.0"
|
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"index": "Home",
|
|
||||||
"quick": "Quick Start",
|
|
||||||
"installation": "Installation",
|
|
||||||
"config": "Configuration",
|
|
||||||
"location": "Locations",
|
|
||||||
"backend": "Backend",
|
|
||||||
"cli": "CLI",
|
|
||||||
"migration": "Migration"
|
|
||||||
}
|
|
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"index": "Overview",
|
|
||||||
"available": "Available backends",
|
|
||||||
"options": "Options",
|
|
||||||
"env": "Environment"
|
|
||||||
}
|
|
@@ -1,40 +0,0 @@
|
|||||||
# 💽 Backends
|
|
||||||
|
|
||||||
Backends are the outputs of the backup process. Each location needs at least one.
|
|
||||||
|
|
||||||
Note: names of backends MUST be lower case!
|
|
||||||
|
|
||||||
```yaml | .autorestic.yml
|
|
||||||
version: 2
|
|
||||||
|
|
||||||
backends:
|
|
||||||
name-of-backend:
|
|
||||||
type: local
|
|
||||||
path: /data/my/backups
|
|
||||||
```
|
|
||||||
|
|
||||||
## Types
|
|
||||||
|
|
||||||
We restic supports multiple types of backends. See the [full list](/backend/available) for details.
|
|
||||||
|
|
||||||
## Avoid Generating Keys
|
|
||||||
|
|
||||||
By default, `autorestic` will generate a key for every backend if none is defined. This is done by updating your config file with the key.
|
|
||||||
|
|
||||||
In cases where you want to provide the key yourself, you can ensure that `autorestic` doesn't accidentally generate one for you by setting `requireKey: true`.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```yaml | .autorestic.yml
|
|
||||||
version: 2
|
|
||||||
|
|
||||||
backends:
|
|
||||||
foo:
|
|
||||||
type: local
|
|
||||||
path: /data/my/backups
|
|
||||||
# Alternatively, you can set the key through the `AUTORESTIC_FOO_RESTIC_PASSWORD` environment variable.
|
|
||||||
key: ... your key here ...
|
|
||||||
requireKey: true
|
|
||||||
```
|
|
||||||
|
|
||||||
With this setting, if a key is missing, `autorestic` will crash instead of generating a new key and updating your config file.
|
|
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"general": "General"
|
|
||||||
}
|
|
@@ -1,32 +0,0 @@
|
|||||||
# Unlock
|
|
||||||
|
|
||||||
In case autorestic throws the error message `an instance is already running. exiting`, but there is no instance running you can unlock the lock.
|
|
||||||
|
|
||||||
To verify that there is no instance running you can use `ps aux | grep autorestic`.
|
|
||||||
|
|
||||||
Example with no instance running:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
> ps aux | grep autorestic
|
|
||||||
root 39260 0.0 0.0 6976 2696 pts/11 S+ 19:41 0:00 grep autorestic
|
|
||||||
```
|
|
||||||
|
|
||||||
Example with an instance running:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
> ps aux | grep autorestic
|
|
||||||
root 29465 0.0 0.0 1162068 7380 pts/7 Sl+ 19:28 0:00 autorestic --ci backup -a
|
|
||||||
root 39260 0.0 0.0 6976 2696 pts/11 S+ 19:41 0:00 grep autorestic
|
|
||||||
```
|
|
||||||
|
|
||||||
**If an instance is running you should not unlock as it could lead to data loss!**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
autorestic unlock
|
|
||||||
```
|
|
||||||
|
|
||||||
Use the `--force` to prevent the confirmation prompt if an instance is running.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
autorestic unlock --force
|
|
||||||
```
|
|
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"index": "Overview",
|
|
||||||
"hooks": "Hooks",
|
|
||||||
"options": "Options",
|
|
||||||
"cron": "Cronjobs",
|
|
||||||
"docker": "Docker volumes"
|
|
||||||
}
|
|
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"index": "Overview"
|
|
||||||
}
|
|
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"0.x_1.0": "0.x → 1.0",
|
|
||||||
"1.4_1.5": "1.4 → 1.5"
|
|
||||||
}
|
|
3190
docs/pnpm-lock.yaml
generated
3190
docs/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,24 +0,0 @@
|
|||||||
export default {
|
|
||||||
logo: <span>Autorestic</span>,
|
|
||||||
docsRepositoryBase: 'https://github.com/cupcakearmy/autorestic/tree/master/docs',
|
|
||||||
project: {
|
|
||||||
link: 'https://github.com/cupcakearmy/autorestic',
|
|
||||||
},
|
|
||||||
sidebar: {
|
|
||||||
defaultMenuCollapseLevel: 1,
|
|
||||||
},
|
|
||||||
feedback: {
|
|
||||||
content: 'Question? An error? Give feedback →',
|
|
||||||
},
|
|
||||||
footer: {
|
|
||||||
text: (
|
|
||||||
<span>
|
|
||||||
MIT {new Date().getFullYear()} ©{' '}
|
|
||||||
<a href="https://github.com/cupcakearmy" target="_blank">
|
|
||||||
cupcakearmy
|
|
||||||
</a>
|
|
||||||
.
|
|
||||||
</span>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
}
|
|
3
docs/vercel.json
Normal file
3
docs/vercel.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"cleanUrls": true
|
||||||
|
}
|
11
go.mod
11
go.mod
@@ -1,6 +1,6 @@
|
|||||||
module github.com/cupcakearmy/autorestic
|
module github.com/cupcakearmy/autorestic
|
||||||
|
|
||||||
go 1.21
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/blang/semver/v4 v4.0.0
|
github.com/blang/semver/v4 v4.0.0
|
||||||
@@ -11,11 +11,9 @@ require (
|
|||||||
github.com/robfig/cron v1.2.0
|
github.com/robfig/cron v1.2.0
|
||||||
github.com/spf13/cobra v1.4.0
|
github.com/spf13/cobra v1.4.0
|
||||||
github.com/spf13/viper v1.11.0
|
github.com/spf13/viper v1.11.0
|
||||||
github.com/stretchr/testify v1.9.0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
|
||||||
github.com/fsnotify/fsnotify v1.5.1 // indirect
|
github.com/fsnotify/fsnotify v1.5.1 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
@@ -25,15 +23,14 @@ require (
|
|||||||
github.com/mitchellh/mapstructure v1.4.3 // indirect
|
github.com/mitchellh/mapstructure v1.4.3 // indirect
|
||||||
github.com/pelletier/go-toml v1.9.4 // indirect
|
github.com/pelletier/go-toml v1.9.4 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
|
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
|
||||||
github.com/spf13/afero v1.8.2 // indirect
|
github.com/spf13/afero v1.8.2 // indirect
|
||||||
github.com/spf13/cast v1.4.1 // indirect
|
github.com/spf13/cast v1.4.1 // indirect
|
||||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
github.com/subosito/gotenv v1.2.0 // indirect
|
github.com/subosito/gotenv v1.2.0 // indirect
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
|
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
|
||||||
golang.org/x/text v0.3.8 // indirect
|
golang.org/x/text v0.3.7 // indirect
|
||||||
gopkg.in/ini.v1 v1.66.4 // indirect
|
gopkg.in/ini.v1 v1.66.4 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||||
)
|
)
|
||||||
|
15
go.sum
15
go.sum
@@ -182,9 +182,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
|||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
|
||||||
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
|
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
|
||||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
||||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
@@ -325,8 +324,8 @@ golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
|
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
@@ -334,8 +333,8 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3
|
|||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
|
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
@@ -488,8 +487,8 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
@@ -10,8 +10,6 @@ if [[ $NATIVE_OS == *"linux"* ]]; then
|
|||||||
OS=linux
|
OS=linux
|
||||||
elif [[ $NATIVE_OS == *"darwin"* ]]; then
|
elif [[ $NATIVE_OS == *"darwin"* ]]; then
|
||||||
OS=darwin
|
OS=darwin
|
||||||
elif [[ $NATIVE_OS == *"freebsd"* ]]; then
|
|
||||||
OS=freebsd
|
|
||||||
else
|
else
|
||||||
echo "Could not determine OS automatically, please check the release page manually: https://github.com/cupcakearmy/autorestic/releases"
|
echo "Could not determine OS automatically, please check the release page manually: https://github.com/cupcakearmy/autorestic/releases"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -19,7 +17,7 @@ fi
|
|||||||
echo $OS
|
echo $OS
|
||||||
|
|
||||||
NATIVE_ARCH=$(uname -m | tr '[:upper:]' '[:lower:]')
|
NATIVE_ARCH=$(uname -m | tr '[:upper:]' '[:lower:]')
|
||||||
if [[ $NATIVE_ARCH == *"x86_64"* || $NATIVE_ARCH == *"amd64"* ]]; then
|
if [[ $NATIVE_ARCH == *"x86_64"* ]]; then
|
||||||
ARCH=amd64
|
ARCH=amd64
|
||||||
elif [[ $NATIVE_ARCH == *"arm64"* || $NATIVE_ARCH == *"aarch64"* ]]; then
|
elif [[ $NATIVE_ARCH == *"arm64"* || $NATIVE_ARCH == *"aarch64"* ]]; then
|
||||||
ARCH=arm64
|
ARCH=arm64
|
||||||
@@ -33,11 +31,6 @@ else
|
|||||||
fi
|
fi
|
||||||
echo $ARCH
|
echo $ARCH
|
||||||
|
|
||||||
if ! command -v bzip2 &>/dev/null; then
|
|
||||||
echo "Missing bzip2 command. Please install the bzip2 package for your system."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
wget -qO - https://api.github.com/repos/cupcakearmy/autorestic/releases/latest \
|
wget -qO - https://api.github.com/repos/cupcakearmy/autorestic/releases/latest \
|
||||||
| grep "browser_download_url.*_${OS}_${ARCH}" \
|
| grep "browser_download_url.*_${OS}_${ARCH}" \
|
||||||
| cut -d : -f 2,3 \
|
| cut -d : -f 2,3 \
|
||||||
|
@@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/cupcakearmy/autorestic/internal/colors"
|
"github.com/cupcakearmy/autorestic/internal/colors"
|
||||||
@@ -19,14 +18,13 @@ type BackendRest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Backend struct {
|
type Backend struct {
|
||||||
name string
|
name string
|
||||||
Type string `mapstructure:"type,omitempty"`
|
Type string `mapstructure:"type,omitempty"`
|
||||||
Path string `mapstructure:"path,omitempty"`
|
Path string `mapstructure:"path,omitempty"`
|
||||||
Key string `mapstructure:"key,omitempty"`
|
Key string `mapstructure:"key,omitempty"`
|
||||||
RequireKey bool `mapstructure:"requireKey,omitempty"`
|
Env map[string]string `mapstructure:"env,omitempty"`
|
||||||
Env map[string]string `mapstructure:"env,omitempty"`
|
Rest BackendRest `mapstructure:"rest,omitempty"`
|
||||||
Rest BackendRest `mapstructure:"rest,omitempty"`
|
Options Options `mapstructure:"options,omitempty"`
|
||||||
Options Options `mapstructure:"options,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBackend(name string) (Backend, bool) {
|
func GetBackend(name string) (Backend, bool) {
|
||||||
@@ -40,7 +38,7 @@ func (b Backend) generateRepo() (string, error) {
|
|||||||
case "local":
|
case "local":
|
||||||
return GetPathRelativeToConfig(b.Path)
|
return GetPathRelativeToConfig(b.Path)
|
||||||
case "rest":
|
case "rest":
|
||||||
parsed, err := url.Parse(os.ExpandEnv(b.Path))
|
parsed, err := url.Parse(b.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -59,8 +57,6 @@ func (b Backend) generateRepo() (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var nonAlphaRegex = regexp.MustCompile("[^A-Za-z0-9]")
|
|
||||||
|
|
||||||
func (b Backend) getEnv() (map[string]string, error) {
|
func (b Backend) getEnv() (map[string]string, error) {
|
||||||
env := make(map[string]string)
|
env := make(map[string]string)
|
||||||
// Key
|
// Key
|
||||||
@@ -76,9 +72,7 @@ func (b Backend) getEnv() (map[string]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// From Envfile and passed as env
|
// From Envfile and passed as env
|
||||||
nameForEnv := strings.ToUpper(b.name)
|
var prefix = "AUTORESTIC_" + strings.ToUpper(b.name) + "_"
|
||||||
nameForEnv = nonAlphaRegex.ReplaceAllString(nameForEnv, "_")
|
|
||||||
var prefix = "AUTORESTIC_" + nameForEnv + "_"
|
|
||||||
for _, variable := range os.Environ() {
|
for _, variable := range os.Environ() {
|
||||||
var splitted = strings.SplitN(variable, "=", 2)
|
var splitted = strings.SplitN(variable, "=", 2)
|
||||||
if strings.HasPrefix(splitted[0], prefix) {
|
if strings.HasPrefix(splitted[0], prefix) {
|
||||||
@@ -110,9 +104,6 @@ func (b Backend) validate() error {
|
|||||||
// Check if key is set in environment
|
// Check if key is set in environment
|
||||||
env, _ := b.getEnv()
|
env, _ := b.getEnv()
|
||||||
if _, found := env["RESTIC_PASSWORD"]; !found {
|
if _, found := env["RESTIC_PASSWORD"]; !found {
|
||||||
if b.RequireKey {
|
|
||||||
return fmt.Errorf("backend %s requires a key but none was provided", b.name)
|
|
||||||
}
|
|
||||||
// No key set in config file or env => generate random key and save file
|
// No key set in config file or env => generate random key and save file
|
||||||
key := generateRandomKey()
|
key := generateRandomKey()
|
||||||
b.Key = key
|
b.Key = key
|
||||||
@@ -152,7 +143,6 @@ func (b Backend) Exec(args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
options := ExecuteOptions{Envs: env}
|
options := ExecuteOptions{Envs: env}
|
||||||
args = append(args, combineBackendOptions("exec", b)...)
|
|
||||||
_, out, err := ExecuteResticCommand(options, args...)
|
_, out, err := ExecuteResticCommand(options, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
colors.Error.Println(out)
|
colors.Error.Println(out)
|
||||||
@@ -192,7 +182,6 @@ func (b Backend) ExecDocker(l Location, args []string) (int, string, error) {
|
|||||||
case "s3":
|
case "s3":
|
||||||
case "azure":
|
case "azure":
|
||||||
case "gs":
|
case "gs":
|
||||||
case "rest":
|
|
||||||
// No additional setup needed
|
// No additional setup needed
|
||||||
case "rclone":
|
case "rclone":
|
||||||
// Read host rclone config and mount it into the container
|
// Read host rclone config and mount it into the container
|
||||||
|
@@ -6,7 +6,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGenerateRepo(t *testing.T) {
|
func TestGenerateRepo(t *testing.T) {
|
||||||
@@ -195,33 +194,6 @@ func TestGetEnv(t *testing.T) {
|
|||||||
assertEqual(t, result["B2_ACCOUNT_ID"], "foo123")
|
assertEqual(t, result["B2_ACCOUNT_ID"], "foo123")
|
||||||
assertEqual(t, result["B2_ACCOUNT_KEY"], "foo456")
|
assertEqual(t, result["B2_ACCOUNT_KEY"], "foo456")
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, char := range "@-_:/" {
|
|
||||||
t.Run(fmt.Sprintf("env var with special char (%c)", char), func(t *testing.T) {
|
|
||||||
// generate env variables
|
|
||||||
// TODO better way to teardown
|
|
||||||
defer os.Unsetenv("AUTORESTIC_FOO_BAR_RESTIC_PASSWORD")
|
|
||||||
defer os.Unsetenv("AUTORESTIC_FOO_BAR_B2_ACCOUNT_ID")
|
|
||||||
defer os.Unsetenv("AUTORESTIC_FOO_BAR_B2_ACCOUNT_KEY")
|
|
||||||
os.Setenv("AUTORESTIC_FOO_BAR_RESTIC_PASSWORD", "secret123")
|
|
||||||
os.Setenv("AUTORESTIC_FOO_BAR_B2_ACCOUNT_ID", "foo123")
|
|
||||||
os.Setenv("AUTORESTIC_FOO_BAR_B2_ACCOUNT_KEY", "foo456")
|
|
||||||
|
|
||||||
b := Backend{
|
|
||||||
name: fmt.Sprintf("foo%cbar", char),
|
|
||||||
Type: "local",
|
|
||||||
Path: "/foo/bar",
|
|
||||||
}
|
|
||||||
result, err := b.getEnv()
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("unexpected error %v", err)
|
|
||||||
}
|
|
||||||
assertEqual(t, result["RESTIC_REPOSITORY"], "/foo/bar")
|
|
||||||
assertEqual(t, result["RESTIC_PASSWORD"], "secret123")
|
|
||||||
assertEqual(t, result["B2_ACCOUNT_ID"], "foo123")
|
|
||||||
assertEqual(t, result["B2_ACCOUNT_KEY"], "foo456")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidate(t *testing.T) {
|
func TestValidate(t *testing.T) {
|
||||||
@@ -250,16 +222,4 @@ func TestValidate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
assertEqual(t, err.Error(), "Backend \"foo\" has no \"path\"")
|
assertEqual(t, err.Error(), "Backend \"foo\" has no \"path\"")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("require key with no key", func(t *testing.T) {
|
|
||||||
b := Backend{
|
|
||||||
name: "foo",
|
|
||||||
Type: "local",
|
|
||||||
Path: "~/foo/bar",
|
|
||||||
RequireKey: true,
|
|
||||||
}
|
|
||||||
err := b.validate()
|
|
||||||
fmt.Printf("error: %v\n", err)
|
|
||||||
assert.EqualError(t, err, "backend foo requires a key but none was provided")
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@@ -36,7 +37,7 @@ func dlJSON(url string) (GithubRelease, error) {
|
|||||||
return parsed, err
|
return parsed, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return parsed, err
|
return parsed, err
|
||||||
|
|
||||||
@@ -72,10 +73,9 @@ func downloadAndInstallAsset(body GithubRelease, name string) error {
|
|||||||
// Uncompress
|
// Uncompress
|
||||||
bz := bzip2.NewReader(resp.Body)
|
bz := bzip2.NewReader(resp.Body)
|
||||||
|
|
||||||
// Save to tmp file in the same directory as the install directory
|
// Save to tmp
|
||||||
// Linux does not support overwriting the file that is currently being running
|
// Linux does not support overwriting the file that is currently being overwritten, but it can be deleted and a new one moved in its place.
|
||||||
// But it can be delete the old one and a new one moved in its place.
|
tmp, err := ioutil.TempFile(os.TempDir(), "autorestic-")
|
||||||
tmp, err := os.CreateTemp(INSTALL_PATH, "autorestic-")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -89,24 +89,22 @@ func downloadAndInstallAsset(body GithubRelease, name string) error {
|
|||||||
|
|
||||||
to := path.Join(INSTALL_PATH, name)
|
to := path.Join(INSTALL_PATH, name)
|
||||||
defer os.Remove(tmp.Name()) // Cleanup temporary file after thread exits
|
defer os.Remove(tmp.Name()) // Cleanup temporary file after thread exits
|
||||||
|
if err := os.Rename(tmp.Name(), to); err != nil {
|
||||||
mode := os.FileMode(0755)
|
colors.Error.Printf("os.Rename() failed (%v), retrying with io.Copy()\n", err.Error())
|
||||||
if originalBin, err := os.Lstat(to); err == nil {
|
var src *os.File
|
||||||
mode = originalBin.Mode()
|
var dst *os.File
|
||||||
err := os.Remove(to)
|
if src, err = os.Open(tmp.Name()); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
|
}
|
||||||
|
if dst, err = os.Create(to); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := io.Copy(dst, src); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := os.Chmod(to, 0755); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
err = os.Rename(tmp.Name(), to)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = os.Chmod(to, mode)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
colors.Success.Printf("Successfully installed '%s' under %s\n", name, INSTALL_PATH)
|
colors.Success.Printf("Successfully installed '%s' under %s\n", name, INSTALL_PATH)
|
||||||
|
@@ -17,7 +17,7 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION = "1.8.3"
|
const VERSION = "1.7.3"
|
||||||
|
|
||||||
type OptionMap map[string][]interface{}
|
type OptionMap map[string][]interface{}
|
||||||
type Options map[string]OptionMap
|
type Options map[string]OptionMap
|
||||||
@@ -132,11 +132,10 @@ func (c *Config) Describe() {
|
|||||||
|
|
||||||
tmp = ""
|
tmp = ""
|
||||||
hooks := map[string][]string{
|
hooks := map[string][]string{
|
||||||
"PreValidate": l.Hooks.PreValidate,
|
"Before": l.Hooks.Before,
|
||||||
"Before": l.Hooks.Before,
|
"After": l.Hooks.After,
|
||||||
"After": l.Hooks.After,
|
"Failure": l.Hooks.Failure,
|
||||||
"Failure": l.Hooks.Failure,
|
"Success": l.Hooks.Success,
|
||||||
"Success": l.Hooks.Success,
|
|
||||||
}
|
}
|
||||||
for hook, commands := range hooks {
|
for hook, commands := range hooks {
|
||||||
if len(commands) > 0 {
|
if len(commands) > 0 {
|
||||||
|
@@ -33,12 +33,11 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Hooks struct {
|
type Hooks struct {
|
||||||
Dir string `mapstructure:"dir"`
|
Dir string `mapstructure:"dir"`
|
||||||
PreValidate HookArray `mapstructure:"prevalidate,omitempty"`
|
Before HookArray `mapstructure:"before,omitempty"`
|
||||||
Before HookArray `mapstructure:"before,omitempty"`
|
After HookArray `mapstructure:"after,omitempty"`
|
||||||
After HookArray `mapstructure:"after,omitempty"`
|
Success HookArray `mapstructure:"success,omitempty"`
|
||||||
Success HookArray `mapstructure:"success,omitempty"`
|
Failure HookArray `mapstructure:"failure,omitempty"`
|
||||||
Failure HookArray `mapstructure:"failure,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type LocationCopy = map[string][]string
|
type LocationCopy = map[string][]string
|
||||||
@@ -185,18 +184,12 @@ func (l Location) Backup(cron bool, specificBackend string) []error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hooks before location validation
|
|
||||||
if err := l.ExecuteHooks(l.Hooks.PreValidate, options); err != nil {
|
|
||||||
errors = append(errors, err)
|
|
||||||
goto after
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := l.validate(); err != nil {
|
if err := l.validate(); err != nil {
|
||||||
errors = append(errors, err)
|
errors = append(errors, err)
|
||||||
goto after
|
goto after
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hooks after location validation
|
// Hooks
|
||||||
if err := l.ExecuteHooks(l.Hooks.Before, options); err != nil {
|
if err := l.ExecuteHooks(l.Hooks.Before, options); err != nil {
|
||||||
errors = append(errors, err)
|
errors = append(errors, err)
|
||||||
goto after
|
goto after
|
||||||
@@ -296,13 +289,12 @@ func (l Location) Backup(cron bool, specificBackend string) []error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// After backup hooks
|
// After hooks
|
||||||
if err := l.ExecuteHooks(l.Hooks.After, options); err != nil {
|
if err := l.ExecuteHooks(l.Hooks.After, options); err != nil {
|
||||||
errors = append(errors, err)
|
errors = append(errors, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
after:
|
after:
|
||||||
// Success/failure hooks
|
|
||||||
var commands []string
|
var commands []string
|
||||||
var isSuccess = len(errors) == 0
|
var isSuccess = len(errors) == 0
|
||||||
if isSuccess {
|
if isSuccess {
|
||||||
@@ -316,10 +308,7 @@ after:
|
|||||||
|
|
||||||
// Forget and optionally prune
|
// Forget and optionally prune
|
||||||
if isSuccess && l.ForgetOption != "" && l.ForgetOption != LocationForgetNo {
|
if isSuccess && l.ForgetOption != "" && l.ForgetOption != LocationForgetNo {
|
||||||
err := l.Forget(l.ForgetOption == LocationForgetPrune, false)
|
l.Forget(l.ForgetOption == LocationForgetPrune, false)
|
||||||
if err != nil {
|
|
||||||
errors = append(errors, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errors) == 0 {
|
if len(errors) == 0 {
|
||||||
|
@@ -14,9 +14,9 @@ func (e addedExtractor) Matches(line string) bool {
|
|||||||
}
|
}
|
||||||
func (e addedExtractor) Extract(metadata *BackupLogMetadata, line string) {
|
func (e addedExtractor) Extract(metadata *BackupLogMetadata, line string) {
|
||||||
// Sample line: "Added to the repo: 0 B"
|
// Sample line: "Added to the repo: 0 B"
|
||||||
metadata.AddedSize = strings.TrimSpace(e.re.ReplaceAllString(line, "$2"))
|
metadata.AddedSize = strings.TrimSpace(e.re.ReplaceAllString(line, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAddedExtractor() MetadatExtractor {
|
func NewAddedExtractor() MetadatExtractor {
|
||||||
return addedExtractor{regexp.MustCompile(`(?i)^Added to the repo(sitory)?: ([\d\.]+ \w+)( \([\d\.]+[\w\s]+\))?`)}
|
return addedExtractor{regexp.MustCompile(`(?i)^Added to the repo:`)}
|
||||||
}
|
}
|
||||||
|
2
main.go
2
main.go
@@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
|
|||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
Reference in New Issue
Block a user