Compare commits

...

9 Commits

Author SHA1 Message Date
873170c6d1 fix auto update 2021-04-20 23:26:57 +02:00
ea82fea8e1 add cron tag 2021-04-20 20:49:09 +02:00
a35edcaea5 version bump 2021-04-17 20:55:09 +02:00
86d44eafad exit with better message 2021-04-17 20:51:40 +02:00
e927fd5a64 panic on already running 2021-04-17 20:45:52 +02:00
d5e13d4e27 changelog 2021-04-17 17:54:24 +02:00
824c90904c docs 2021-04-17 17:51:23 +02:00
58fb5e073a Update README.md 2021-04-17 17:50:53 +02:00
541a7c2a72 add autocompletetions 2021-04-17 17:48:31 +02:00
10 changed files with 147 additions and 19 deletions

32
CHANGELOG.md Normal file
View File

@@ -0,0 +1,32 @@
# Changelog
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/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.3] - 2021-04-20
### Fixed
- Auto upgrade script was not working on linux as linux does not support writing to the binary that is being executed
## [1.0.2] - 2021-04-20
### Added
- Add the `cron` tag to backup to backups made with cron.
### Fixed
- Don't unlock lockfile if process is already running.
## [1.0.1] - 2021-04-17
### Added
- Completion command for various shells
## [1.0.0] - 2021-04-17
- Rewrite in go. See https://autorestic.vercel.app/upgrade for migration.

View File

@@ -16,10 +16,23 @@
<br> <br>
<br> <br>
### Why / What? ### 💭 Why / What?
Autorestic is a wrapper around the amazing [restic](https://restic.net/). While being amazing the restic cli can be a bit overwhelming and difficult to manage if you have many different location that you want to backup to multiple locations. This utility is aimed at making this easier 🙂 Autorestic is a wrapper around the amazing [restic](https://restic.net/). While being amazing the restic cli can be a bit overwhelming and difficult to manage if you have many different location that you want to backup to multiple locations. This utility is aimed at making this easier 🙂
### Questions / Support ### 🌈 Features
- YAML config files, no CLI
- Incremental -> Minimal space is used
- Backup locations to multiple backends
- Snapshot policies and pruning
- Fully encrypted
- Pre/After hooks
- Exclude pattern/files
- Cron jobs for automatic backup
- Backup & Restore docker volume
- Generated completions for `[bash|zsh|fish|powershell]`
### ❓ Questions / Support
Check the [discussions page](https://github.com/cupcakearmy/autorestic/discussions) Check the [discussions page](https://github.com/cupcakearmy/autorestic/discussions)

View File

@@ -1,9 +1,9 @@
# Releasing # Releasing
Releases are handled by the CD server with includes checksums for each binary. Releases are automatically built by the github workflow and uploaded to the release.
```bash 1. Bump `VERSION` in `internal/config.go`.
git tag 0.x 2. Update `CHANGELOG.md`
git push 3. Commit to master
git push origin --tags 4. Create a new release with the `v1.2.3` tag and mark as draft.
``` 5. The Github action will build the binaries, upload and mark the release as ready when done.

View File

@@ -20,7 +20,7 @@ var backupCmd = &cobra.Command{
CheckErr(err) CheckErr(err)
for _, name := range selected { for _, name := range selected {
location, _ := internal.GetLocation(name) location, _ := internal.GetLocation(name)
location.Backup() location.Backup(false)
} }
}, },
} }

70
cmd/completion.go Normal file
View File

@@ -0,0 +1,70 @@
package cmd
import (
"os"
"github.com/spf13/cobra"
)
var completionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
Long: `To load completions:
Bash:
$ source <(autorestic completion bash)
# To load completions for each session, execute once:
# Linux:
$ autorestic completion bash > /etc/bash_completion.d/autorestic
# macOS:
$ autorestic completion bash > /usr/local/etc/bash_completion.d/autorestic
Zsh:
# If shell completion is not already enabled in your environment,
# you will need to enable it. You can execute the following once:
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
# To load completions for each session, execute once:
$ autorestic completion zsh > "${fpath[1]}/_autorestic"
# You will need to start a new shell for this setup to take effect.
fish:
$ autorestic completion fish | source
# To load completions for each session, execute once:
$ autorestic completion fish > ~/.config/fish/completions/autorestic.fish
PowerShell:
PS> autorestic completion powershell | Out-String | Invoke-Expression
# To load completions for every new session, run:
PS> autorestic completion powershell > autorestic.ps1
# and source this file from your PowerShell profile.
`,
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactValidArgs(1),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
cmd.Root().GenZshCompletion(os.Stdout)
case "fish":
cmd.Root().GenFishCompletion(os.Stdout, true)
case "powershell":
cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
}
},
}
func init() {
rootCmd.AddCommand(completionCmd)
}

View File

@@ -17,5 +17,6 @@ Autorestic is a wrapper around the amazing [restic](https://restic.net/). While
- 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]`
> :ToCPrevNext > :ToCPrevNext

View File

@@ -72,14 +72,21 @@ func downloadAndInstallAsset(body GithubRelease, name string) error {
// Uncompress // Uncompress
bz := bzip2.NewReader(resp.Body) bz := bzip2.NewReader(resp.Body)
// Save binary // Save to tmp
file, err := os.Create(path.Join(INSTALL_PATH, name)) // 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.
tmp, err := ioutil.TempFile(os.TempDir(), "autorestic-")
if err != nil { if err != nil {
return err return err
} }
file.Chmod(0755) defer tmp.Close()
defer file.Close() tmp.Chmod(0755)
io.Copy(file, bz) io.Copy(tmp, bz)
to := path.Join(INSTALL_PATH, name)
os.Remove(to) // Delete if current, ignore error if file does not exits.
if err := os.Rename(tmp.Name(), to); err != nil {
return nil
}
colors.Success.Printf("Successfully installed '%s' under %s\n", name, INSTALL_PATH) colors.Success.Printf("Successfully installed '%s' under %s\n", name, INSTALL_PATH)
return nil return nil

View File

@@ -12,7 +12,7 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
const VERSION = "1.0.0" const VERSION = "1.0.3"
var CI bool = false var CI bool = false
var VERBOSE bool = false var VERBOSE bool = false

View File

@@ -118,7 +118,7 @@ func (l Location) getPath() (string, error) {
return "", fmt.Errorf("could not get path for location \"%s\"", l.name) return "", fmt.Errorf("could not get path for location \"%s\"", l.name)
} }
func (l Location) Backup() error { func (l Location) Backup(cron bool) error {
colors.PrimaryPrint(" Backing up location \"%s\" ", l.name) colors.PrimaryPrint(" Backing up location \"%s\" ", l.name)
t := l.getType() t := l.getType()
options := ExecuteOptions{ options := ExecuteOptions{
@@ -147,6 +147,9 @@ func (l Location) Backup() error {
flags := l.getOptions("backup") flags := l.getOptions("backup")
cmd := []string{"backup"} cmd := []string{"backup"}
cmd = append(cmd, flags...) cmd = append(cmd, flags...)
if cron {
cmd = append(cmd, "--tag", "cron")
}
cmd = append(cmd, ".") cmd = append(cmd, ".")
backupOptions := ExecuteOptions{ backupOptions := ExecuteOptions{
Dir: options.Dir, Dir: options.Dir,
@@ -291,7 +294,7 @@ func (l Location) RunCron() error {
now := time.Now() now := time.Now()
if now.After(next) { if now.After(next) {
lock.SetCron(l.name, now.Unix()) lock.SetCron(l.name, now.Unix())
l.Backup() l.Backup(true)
} else { } else {
colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name) colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name)
} }

View File

@@ -1,10 +1,11 @@
package lock package lock
import ( import (
"errors" "os"
"path" "path"
"sync" "sync"
"github.com/cupcakearmy/autorestic/internal/colors"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@@ -33,7 +34,8 @@ func setLock(locked bool) error {
if locked { if locked {
running := lock.GetBool("running") running := lock.GetBool("running")
if running { if running {
return errors.New("an instance is already running") colors.Error.Println("an instance is already running. exiting")
os.Exit(1)
} }
} }
lock.Set("running", locked) lock.Set("running", locked)