aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma <felix+debian@gueux.org>2017-01-08 15:32:30 +0100
committerFélix Sipma <felix+debian@gueux.org>2017-01-08 15:32:30 +0100
commit2d97cde7a4b935ade9d8dbf05dff136fac357e3b (patch)
tree669034103e71a0080479afe31bc69101fa68a8d7
parentfb6c3cf716ad4b0d5c287ed05ba889d777681bdb (diff)
New upstream version 0.3.3upstream/0.3.3
-rw-r--r--.travis.yml19
-rw-r--r--VERSION2
-rw-r--r--appveyor.yml8
-rw-r--r--build.go6
-rw-r--r--doc/Manual.md29
-rw-r--r--src/cmds/restic-server/.gitignore24
-rw-r--r--src/cmds/restic-server/LICENSE24
-rw-r--r--src/cmds/restic-server/README.md29
-rw-r--r--src/cmds/restic-server/handlers.go194
-rw-r--r--src/cmds/restic-server/htpasswd.go97
-rw-r--r--src/cmds/restic-server/router.go137
-rw-r--r--src/cmds/restic-server/router_test.go74
-rw-r--r--src/cmds/restic-server/server.go73
-rw-r--r--src/cmds/restic/cleanup.go11
-rw-r--r--src/cmds/restic/cmd_backup.go5
-rw-r--r--src/cmds/restic/cmd_version.go4
-rw-r--r--src/cmds/restic/global.go31
-rw-r--r--src/cmds/restic/lock.go3
-rw-r--r--src/cmds/restic/main.go12
-rw-r--r--src/restic/repository/master_index.go13
-rw-r--r--src/restic/repository/packer_manager.go2
21 files changed, 88 insertions, 709 deletions
diff --git a/.travis.yml b/.travis.yml
index 9fb471b..a70d48d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,8 +2,9 @@ language: go
sudo: false
go:
- - 1.6.3
- - 1.7.1
+ - 1.6.4
+ - 1.7.4
+ - tip
os:
- linux
@@ -16,16 +17,23 @@ env:
matrix:
exclude:
- os: osx
- go: 1.6.3
+ go: 1.6.4
+ - os: osx
+ go: tip
- os: linux
- go: 1.7.1
+ go: 1.7.4
include:
- os: linux
- go: 1.7.1
+ go: 1.7.4
sudo: true
env:
RESTIC_TEST_FUSE=1
+ allow_failures:
+ - go: tip
+branches:
+ only:
+ - master
notifications:
irc:
@@ -46,5 +54,4 @@ script:
- go run run_integration_tests.go
after_success:
- - GOPATH=$PWD:$PWD/vendor goveralls -coverprofile=all.cov -service=travis-ci -repotoken "$COVERALLS_TOKEN"
- bash <(curl -s https://codecov.io/bash) -f all.cov
diff --git a/VERSION b/VERSION
index d15723f..1c09c74 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.3.2
+0.3.3
diff --git a/appveyor.yml b/appveyor.yml
index b7f5049..49bbbaf 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -3,6 +3,10 @@ clone_folder: c:\restic
environment:
GOPATH: c:\gopath
+branches:
+ only:
+ - master
+
init:
- ps: >-
$app = Get-WmiObject -Class Win32_Product -Filter "Vendor = 'http://golang.org'"
@@ -13,8 +17,8 @@ init:
install:
- rmdir c:\go /s /q
- - appveyor DownloadFile https://storage.googleapis.com/golang/go1.7.windows-amd64.msi
- - msiexec /i go1.7.windows-amd64.msi /q
+ - appveyor DownloadFile https://storage.googleapis.com/golang/go1.7.4.windows-amd64.msi
+ - msiexec /i go1.7.4.windows-amd64.msi /q
- go version
- go env
- appveyor DownloadFile http://sourceforge.netcologne.de/project/gnuwin32/tar/1.13-1/tar-1.13-1-bin.zip -FileName tar.zip
diff --git a/build.go b/build.go
index 04a65d1..8406492 100644
--- a/build.go
+++ b/build.go
@@ -12,7 +12,6 @@ import (
"path/filepath"
"runtime"
"strings"
- "time"
)
var (
@@ -33,8 +32,6 @@ var config = struct {
Tests: []string{"restic/...", "cmds/..."}, // tests to run
}
-const timeFormat = "2006-01-02 15:04:05"
-
// specialDir returns true if the file begins with a special character ('.' or '_').
func specialDir(name string) bool {
if name == "." {
@@ -392,8 +389,7 @@ func main() {
output := filepath.Join(cwd, outputFilename)
version := getVersion()
- compileTime := time.Now().Format(timeFormat)
- constants := Constants{`main.compiledAt`: compileTime}
+ constants := Constants{}
if version != "" {
constants["main.version"] = version
}
diff --git a/doc/Manual.md b/doc/Manual.md
index 2a16a90..350201d 100644
--- a/doc/Manual.md
+++ b/doc/Manual.md
@@ -448,6 +448,35 @@ You can also specify a relative (read: no slash (`/`) character at the
beginning) directory, in this case the dir is relative to the remote user's
home directory.
+# Create a REST server repository
+
+In order to backup data to the remote server via HTTP or HTTPS protocol,
+you must first set up a remote [REST server](https://github.com/restic/rest-server)
+instance. Once the server is configured, accessing it is achieved by changing the
+URL scheme like this:
+
+```console
+$ restic -r rest:http://host:8000/
+```
+
+Depending on your REST server setup, you can use HTTPS protocol, password
+protection, or multiple repositories. Or any combination of those features, as
+you see fit. TCP/IP port is also configurable. Here are some more examples:
+
+```console
+$ restic -r rest:https://host:8000/
+$ restic -r rest:https://user:pass@host:8000/
+$ restic -r rest:https://user:pass@host:8000/my_backup_repo/
+```
+
+If you use TLS, make sure your certificates are signed, 'cause restic client
+will refuse to communicate otherwise. It's easy to obtain such certificates
+today, thanks to free certificate authorities like [Let’s
+Encrypt](https://letsencrypt.org/).
+
+REST server uses exactly the same directory structure as local backend, so you
+should be able to access it both locally and via HTTP, even simultaneously.
+
# Create an Amazon S3 repository
Restic can backup data to any Amazon S3 bucket. However, in this case, changing the URL scheme is not enough since Amazon uses special security credentials to sign HTTP requests. By consequence, you must first setup the following environment variables with the credentials you obtained while creating the bucket.
diff --git a/src/cmds/restic-server/.gitignore b/src/cmds/restic-server/.gitignore
deleted file mode 100644
index daf913b..0000000
--- a/src/cmds/restic-server/.gitignore
+++ /dev/null
@@ -1,24 +0,0 @@
-# Compiled Object files, Static and Dynamic libs (Shared Objects)
-*.o
-*.a
-*.so
-
-# Folders
-_obj
-_test
-
-# Architecture specific extensions/prefixes
-*.[568vq]
-[568vq].out
-
-*.cgo1.go
-*.cgo2.c
-_cgo_defun.c
-_cgo_gotypes.go
-_cgo_export.*
-
-_testmain.go
-
-*.exe
-*.test
-*.prof
diff --git a/src/cmds/restic-server/LICENSE b/src/cmds/restic-server/LICENSE
deleted file mode 100644
index c50bca0..0000000
--- a/src/cmds/restic-server/LICENSE
+++ /dev/null
@@ -1,24 +0,0 @@
-Copyright (c) 2015, Bertil Chapuis
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
-* Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
diff --git a/src/cmds/restic-server/README.md b/src/cmds/restic-server/README.md
deleted file mode 100644
index aa5d33e..0000000
--- a/src/cmds/restic-server/README.md
+++ /dev/null
@@ -1,29 +0,0 @@
-# Restic Server
-
-Restic Server is a sample server that implement restic's rest backend api.
-It has been developed for demonstration purpose and is not intented to be used in production.
-
-## Getting started
-
-By default the server persists backup data in `/tmp/restic`.
-Build and start the server with a custom persistence directory:
-
-```
-go build
-./restic-server -path /user/home/backup
-```
-
-The server use an `.htpasswd` file to specify users. You can create such a file at the root of the persistence directory by executing the following command. In order to append new user to the file, just omit the `-c` argument.
-
-```
-htpasswd -s -c .htpasswd username
-```
-
-By default the server uses http. This is not very secure since with Basic Authentication, username and passwords will be present in every request. In order to enable TLS support just add the `-tls` argument and add a private and public key at the root of your persistence directory.
-
-Signed certificate are required by the restic backend but if you just want to test the feature you can generate unsigned keys with the following commands:
-
-```
-openssl genrsa -out private_key 2048
-openssl req -new -x509 -key private_key -out public_key -days 365
-```
diff --git a/src/cmds/restic-server/handlers.go b/src/cmds/restic-server/handlers.go
deleted file mode 100644
index 3351fdc..0000000
--- a/src/cmds/restic-server/handlers.go
+++ /dev/null
@@ -1,194 +0,0 @@
-// +build go1.4
-
-package main
-
-import (
- "encoding/json"
- "fmt"
- "io"
- "io/ioutil"
- "net/http"
- "os"
- "path/filepath"
- "strings"
- "time"
-
- "restic/fs"
-)
-
-// Context contains repository meta-data.
-type Context struct {
- path string
-}
-
-// AuthHandler wraps h with a http.HandlerFunc that performs basic
-// authentication against the user/passwords pairs stored in f and returns the
-// http.HandlerFunc.
-func AuthHandler(f *HtpasswdFile, h http.Handler) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- username, password, ok := r.BasicAuth()
- if !ok {
- http.Error(w, "401 unauthorized", 401)
- return
- }
- if !f.Validate(username, password) {
- http.Error(w, "401 unauthorized", 401)
- return
- }
- h.ServeHTTP(w, r)
- }
-}
-
-// CheckConfig returns a http.HandlerFunc that checks whether
-// a configuration exists.
-func CheckConfig(c *Context) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- config := filepath.Join(c.path, "config")
- st, err := os.Stat(config)
- if err != nil {
- http.Error(w, "404 not found", 404)
- return
- }
- w.Header().Add("Content-Length", fmt.Sprint(st.Size()))
- }
-}
-
-// GetConfig returns a http.HandlerFunc that allows for a
-// config to be retrieved.
-func GetConfig(c *Context) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- config := filepath.Join(c.path, "config")
- bytes, err := ioutil.ReadFile(config)
- if err != nil {
- http.Error(w, "404 not found", 404)
- return
- }
- w.Write(bytes)
- }
-}
-
-// SaveConfig returns a http.HandlerFunc that allows for a
-// config to be saved.
-func SaveConfig(c *Context) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- config := filepath.Join(c.path, "config")
- bytes, err := ioutil.ReadAll(r.Body)
- if err != nil {
- http.Error(w, "400 bad request", 400)
- return
- }
- errw := ioutil.WriteFile(config, bytes, 0600)
- if errw != nil {
- http.Error(w, "500 internal server error", 500)
- return
- }
- w.Write([]byte("200 ok"))
- }
-}
-
-// ListBlobs returns a http.HandlerFunc that lists
-// all blobs of a given type in an arbitrary order.
-func ListBlobs(c *Context) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- vars := strings.Split(r.RequestURI, "/")
- dir := vars[1]
- path := filepath.Join(c.path, dir)
- files, err := ioutil.ReadDir(path)
- if err != nil {
- http.Error(w, "404 not found", 404)
- return
- }
- names := make([]string, len(files))
- for i, f := range files {
- names[i] = f.Name()
- }
- data, err := json.Marshal(names)
- if err != nil {
- http.Error(w, "500 internal server error", 500)
- return
- }
- w.Write(data)
- }
-}
-
-// CheckBlob reutrns a http.HandlerFunc that tests whether a blob exists
-// and returns 200, if it does, or 404 otherwise.
-func CheckBlob(c *Context) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- vars := strings.Split(r.RequestURI, "/")
- dir := vars[1]
- name := vars[2]
- path := filepath.Join(c.path, dir, name)
- st, err := os.Stat(path)
- if err != nil {
- http.Error(w, "404 not found", 404)
- return
- }
- w.Header().Add("Content-Length", fmt.Sprint(st.Size()))
- }
-}
-
-// GetBlob returns a http.HandlerFunc that retrieves a blob
-// from the repository.
-func GetBlob(c *Context) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- vars := strings.Split(r.RequestURI, "/")
- dir := vars[1]
- name := vars[2]
- path := filepath.Join(c.path, dir, name)
- file, err := fs.Open(path)
- if err != nil {
- http.Error(w, "404 not found", 404)
- return
- }
- defer file.Close()
- http.ServeContent(w, r, "", time.Unix(0, 0), file)
- }
-}
-
-// SaveBlob returns a http.HandlerFunc that saves a blob to the repository.
-func SaveBlob(c *Context) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- vars := strings.Split(r.RequestURI, "/")
- dir := vars[1]
- name := vars[2]
- path := filepath.Join(c.path, dir, name)
- tmp := path + "_tmp"
- tf, err := fs.OpenFile(tmp, os.O_CREATE|os.O_WRONLY, 0600)
- if err != nil {
- http.Error(w, "500 internal server error", 500)
- return
- }
- if _, err := io.Copy(tf, r.Body); err != nil {
- http.Error(w, "400 bad request", 400)
- tf.Close()
- os.Remove(tmp)
- return
- }
- if err := tf.Close(); err != nil {
- http.Error(w, "500 internal server error", 500)
- }
- if err := os.Rename(tmp, path); err != nil {
- http.Error(w, "500 internal server error", 500)
- return
- }
- w.Write([]byte("200 ok"))
- }
-}
-
-// DeleteBlob returns a http.HandlerFunc that deletes a blob from the
-// repository.
-func DeleteBlob(c *Context) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- vars := strings.Split(r.RequestURI, "/")
- dir := vars[1]
- name := vars[2]
- path := filepath.Join(c.path, dir, name)
- err := os.Remove(path)
- if err != nil {
- http.Error(w, "500 internal server error", 500)
- return
- }
- w.Write([]byte("200 ok"))
- }
-}
diff --git a/src/cmds/restic-server/htpasswd.go b/src/cmds/restic-server/htpasswd.go
deleted file mode 100644
index 6ec6704..0000000
--- a/src/cmds/restic-server/htpasswd.go
+++ /dev/null
@@ -1,97 +0,0 @@
-// +build go1.4
-
-package main
-
-/*
-Copied from: github.com/bitly/oauth2_proxy
-
-MIT License
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-import (
- "crypto/sha1"
- "encoding/base64"
- "encoding/csv"
- "io"
- "log"
-
- "restic/fs"
-)
-
-// lookup passwords in a htpasswd file
-// The entries must have been created with -s for SHA encryption
-
-// HtpasswdFile is a map for usernames to passwords.
-type HtpasswdFile struct {
- Users map[string]string
-}
-
-// NewHtpasswdFromFile reads the users and passwords from a htpasswd
-// file and returns them. If an error is encountered, it is returned, together
-// with a nil-Pointer for the HtpasswdFile.
-func NewHtpasswdFromFile(path string) (*HtpasswdFile, error) {
- r, err := fs.Open(path)
- if err != nil {
- return nil, err
- }
- defer r.Close()
- return NewHtpasswd(r)
-}
-
-// NewHtpasswd reads the users and passwords from a htpasswd
-// datastream in file and returns them. If an error is encountered,
-// it is returned, together with a nil-Pointer for the HtpasswdFile.
-func NewHtpasswd(file io.Reader) (*HtpasswdFile, error) {
- cr := csv.NewReader(file)
- cr.Comma = ':'
- cr.Comment = '#'
- cr.TrimLeadingSpace = true
-
- records, err := cr.ReadAll()
- if err != nil {
- return nil, err
- }
- h := &HtpasswdFile{Users: make(map[string]string)}
- for _, record := range records {
- h.Users[record[0]] = record[1]
- }
- return h, nil
-}
-
-// Validate returns true if password matches the stored password
-// for user. If no password for user is stored, or the password
-// is wrong, false is returned.
-func (h *HtpasswdFile) Validate(user string, password string) bool {
- realPassword, exists := h.Users[user]
- if !exists {
- return false
- }
- if realPassword[:5] == "{SHA}" {
- d := sha1.New()
- d.Write([]byte(password))
- if realPassword[5:] == base64.StdEncoding.EncodeToString(d.Sum(nil)) {
- return true
- }
- } else {
- log.Printf("Invalid htpasswd entry for %s. Must be a SHA entry.", user)
- }
- return false
-}
diff --git a/src/cmds/restic-server/router.go b/src/cmds/restic-server/router.go
deleted file mode 100644
index c482039..0000000
--- a/src/cmds/restic-server/router.go
+++ /dev/null
@@ -1,137 +0,0 @@
-// +build go1.4
-
-package main
-
-import (
- "log"
- "net/http"
- "strings"
-)
-
-// Route is a handler for a path that was already split.
-type Route struct {
- path []string
- handler http.Handler
-}
-
-// Router maps HTTP methods to a slice of Route handlers.
-type Router struct {
- routes map[string][]Route
-}
-
-// NewRouter creates a new Router and returns a pointer to it.
-func NewRouter() *Router {
- return &Router{make(map[string][]Route)}
-}
-
-// Options registers handler for path with method "OPTIONS".
-func (router *Router) Options(path string, handler http.Handler) {
- router.Handle("OPTIONS", path, handler)
-}
-
-// OptionsFunc registers handler for path with method "OPTIONS".
-func (router *Router) OptionsFunc(path string, handler http.HandlerFunc) {
- router.Handle("OPTIONS", path, handler)
-}
-
-// Get registers handler for path with method "GET".
-func (router *Router) Get(path string, handler http.Handler) {
- router.Handle("GET", path, handler)
-}
-
-// GetFunc registers handler for path with method "GET".
-func (router *Router) GetFunc(path string, handler http.HandlerFunc) {
- router.Handle("GET", path, handler)
-}
-
-// Head registers handler for path with method "HEAD".
-func (router *Router) Head(path string, handler http.Handler) {
- router.Handle("HEAD", path, handler)
-}
-
-// HeadFunc registers handler for path with method "HEAD".
-func (router *Router) HeadFunc(path string, handler http.HandlerFunc) {
- router.Handle("HEAD", path, handler)
-}
-
-// Post registers handler for path with method "POST".
-func (router *Router) Post(path string, handler http.Handler) {
- router.Handle("POST", path, handler)
-}
-
-// PostFunc registers handler for path with method "POST".
-func (router *Router) PostFunc(path string, handler http.HandlerFunc) {
- router.Handle("POST", path, handler)
-}
-
-// Put registers handler for path with method "PUT".
-func (router *Router) Put(path string, handler http.Handler) {
- router.Handle("PUT", path, handler)
-}
-
-// PutFunc registers handler for path with method "PUT".
-func (router *Router) PutFunc(path string, handler http.HandlerFunc) {
- router.Handle("PUT", path, handler)
-}
-
-// Delete registers handler for path with method "DELETE".
-func (router *Router) Delete(path string, handler http.Handler) {
- router.Handle("DELETE", path, handler)
-}
-
-// DeleteFunc registers handler for path with method "DELETE".
-func (router *Router) DeleteFunc(path string, handler http.HandlerFunc) {
- router.Handle("DELETE", path, handler)
-}
-
-// Trace registers handler for path with method "TRACE".
-func (router *Router) Trace(path string, handler http.Handler) {
- router.Handle("TRACE", path, handler)
-}
-
-// TraceFunc registers handler for path with method "TRACE".
-func (router *Router) TraceFunc(path string, handler http.HandlerFunc) {
- router.Handle("TRACE", path, handler)
-}
-
-// Connect registers handler for path with method "Connect".
-func (router *Router) Connect(path string, handler http.Handler) {
- router.Handle("Connect", path, handler)
-}
-
-// ConnectFunc registers handler for path with method "Connect".
-func (router *Router) ConnectFunc(path string, handler http.HandlerFunc) {
- router.Handle("Connect", path, handler)
-}
-
-// Handle registers a http.Handler for method and uri
-func (router *Router) Handle(method string, uri string, handler http.Handler) {
- routes := router.routes[method]
- path := strings.Split(uri, "/")
- routes = append(routes, Route{path, handler})
- router.routes[method] = routes
-}
-
-func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- method := r.Method
- uri := r.RequestURI
- path := strings.Split(uri, "/")
-
- log.Printf("%s %s", method, uri)
-
-ROUTE:
- for _, route := range router.routes[method] {
- if len(route.path) != len(path) {
- continue
- }
- for i := 0; i < len(route.path); i++ {
- if !strings.HasPrefix(route.path[i], ":") && route.path[i] != path[i] {
- continue ROUTE
- }
- }
- route.handler.ServeHTTP(w, r)
- return
- }
-
- http.Error(w, "404 not found", 404)
-}
diff --git a/src/cmds/restic-server/router_test.go b/src/cmds/restic-server/router_test.go
deleted file mode 100644
index d4da184..0000000
--- a/src/cmds/restic-server/router_test.go
+++ /dev/null
@@ -1,74 +0,0 @@
-// +build go1.4
-
-package main
-
-import (
- "io/ioutil"
- "net/http"
- "net/http/httptest"
- "strings"
- "testing"
-)
-
-func TestRouter(t *testing.T) {
- router := NewRouter()
-
- getConfig := []byte("GET /config")
- router.GetFunc("/config", func(w http.ResponseWriter, r *http.Request) {
- w.Write(getConfig)
- })
-
- postConfig := []byte("POST /config")
- router.PostFunc("/config", func(w http.ResponseWriter, r *http.Request) {
- w.Write(postConfig)
- })
-
- getBlobs := []byte("GET /blobs/")
- router.GetFunc("/blobs/", func(w http.ResponseWriter, r *http.Request) {
- w.Write(getBlobs)
- })
-
- getBlob := []byte("GET /blobs/:sha")
- router.GetFunc("/blobs/:sha", func(w http.ResponseWriter, r *http.Request) {
- w.Write(getBlob)
- })
-
- server := httptest.NewServer(router)
- defer server.Close()
-
- getConfigResp, _ := http.Get(server.URL + "/config")
- getConfigBody, _ := ioutil.ReadAll(getConfigResp.Body)
- if getConfigResp.StatusCode != 200 {
- t.Fatalf("Wanted HTTP Status 200, got %d", getConfigResp.StatusCode)
- }
- if string(getConfig) != string(getConfigBody) {
- t.Fatalf("Config wrong:\nWanted '%s'\nGot: '%s'", string(getConfig), string(getConfigBody))
- }
-
- postConfigResp, _ := http.Post(server.URL+"/config", "binary/octet-stream", strings.NewReader("post test"))
- postConfigBody, _ := ioutil.ReadAll(postConfigResp.Body)
- if postConfigResp.StatusCode != 200 {
- t.Fatalf("Wanted HTTP Status 200, got %d", postConfigResp.StatusCode)
- }
- if string(postConfig) != string(postConfigBody) {
- t.Fatalf("Config wrong:\nWanted '%s'\nGot: '%s'", string(postConfig), string(postConfigBody))
- }
-
- getBlobsResp, _ := http.Get(server.URL + "/blobs/")
- getBlobsBody, _ := ioutil.ReadAll(getBlobsResp.Body)
- if getBlobsResp.StatusCode != 200 {
- t.Fatalf("Wanted HTTP Status 200, got %d", getBlobsResp.StatusCode)
- }
- if string(getBlobs) != string(getBlobsBody) {
- t.Fatalf("Config wrong:\nWanted '%s'\nGot: '%s'", string(getBlobs), string(getBlobsBody))
- }
-
- getBlobResp, _ := http.Get(server.URL + "/blobs/test")
- getBlobBody, _ := ioutil.ReadAll(getBlobResp.Body)
- if getBlobResp.StatusCode != 200 {
- t.Fatalf("Wanted HTTP Status 200, got %d", getBlobResp.StatusCode)
- }
- if string(getBlob) != string(getBlobBody) {
- t.Fatalf("Config wrong:\nWanted '%s'\nGot: '%s'", string(getBlob), string(getBlobBody))
- }
-}
diff --git a/src/cmds/restic-server/server.go b/src/cmds/restic-server/server.go
deleted file mode 100644
index bce9914..0000000
--- a/src/cmds/restic-server/server.go
+++ /dev/null
@@ -1,73 +0,0 @@
-// +build go1.4
-
-package main
-
-import (
- "flag"
- "log"
- "net/http"
- "os"
- "path/filepath"
-)
-
-const (
- defaultHTTPPort = ":8000"
- defaultHTTPSPort = ":8443"
-)
-
-func main() {
- // Parse command-line args
- var path = flag.String("path", "/tmp/restic", "specifies the path of the data directory")
- var tls = flag.Bool("tls", false, "turns on tls support")
- flag.Parse()
-
- // Create the missing directories
- dirs := []string{
- "data",
- "snapshots",
- "index",
- "locks",
- "keys",
- "tmp",
- }
- for _, d := range dirs {
- os.MkdirAll(filepath.Join(*path, d), 0700)
- }
-
- // Define the routes
- context := &Context{*path}
- router := NewRouter()
- router.HeadFunc("/config", CheckConfig(context))
- router.GetFunc("/config", GetConfig(context))
- router.PostFunc("/config", SaveConfig(context))
- router.GetFunc("/:dir/", ListBlobs(context))
- router.HeadFunc("/:dir/:name", CheckBlob(context))
- router.GetFunc("/:type/:name", GetBlob(context))
- router.PostFunc("/:type/:name", SaveBlob(context))
- router.DeleteFunc("/:type/:name", DeleteBlob(context))
-
- // Check for a password file
- var handler http.Handler
- htpasswdFile, err := NewHtpasswdFromFile(filepath.Join(*path, ".htpasswd"))
- if err != nil {
- log.Println("Authentication disabled")
- handler = router
- } else {
- log.Println("Authentication enabled")
- handler = AuthHandler(htpasswdFile, router)
- }
-
- // start the server
- if !*tls {
- log.Printf("start server on port %s\n", defaultHTTPPort)
- http.ListenAndServe(defaultHTTPPort, handler)
- } else {
- privateKey := filepath.Join(*path, "private_key")
- publicKey := filepath.Join(*path, "public_key")
- log.Println("TLS enabled")
- log.Printf("private key: %s", privateKey)
- log.Printf("public key: %s", publicKey)
- log.Printf("start server on port %s\n", defaultHTTPSPort)
- http.ListenAndServeTLS(defaultHTTPSPort, publicKey, privateKey, handler)
- }
-}
diff --git a/src/cmds/restic/cleanup.go b/src/cmds/restic/cleanup.go
index f75d8ee..8e35e33 100644
--- a/src/cmds/restic/cleanup.go
+++ b/src/cmds/restic/cleanup.go
@@ -62,8 +62,13 @@ func CleanupHandler(c <-chan os.Signal) {
for s := range c {
debug.Log("signal %v received, cleaning up", s)
fmt.Printf("%sInterrupt received, cleaning up\n", ClearLine())
- RunCleanupHandlers()
- fmt.Println("exiting")
- os.Exit(0)
+ Exit(0)
}
}
+
+// Exit runs the cleanup handlers and then terminates the process with the
+// given exit code.
+func Exit(code int) {
+ RunCleanupHandlers()
+ os.Exit(code)
+}
diff --git a/src/cmds/restic/cmd_backup.go b/src/cmds/restic/cmd_backup.go
index aa3f3cc..c8e3933 100644
--- a/src/cmds/restic/cmd_backup.go
+++ b/src/cmds/restic/cmd_backup.go
@@ -289,7 +289,7 @@ func readLinesFromFile(filename string) ([]string, error) {
}
func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error {
- target, err := readLinesFromFile(opts.FilesFrom)
+ fromfile, err := readLinesFromFile(opts.FilesFrom)
if err != nil {
return err
}
@@ -297,11 +297,12 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error {
// merge files from files-from into normal args so we can reuse the normal
// args checks and have the ability to use both files-from and args at the
// same time
- args = append(args, target...)
+ args = append(args, fromfile...)
if len(args) == 0 {
return errors.Fatalf("wrong number of parameters")
}
+ target := make([]string, 0, len(args))
for _, d := range args {
if a, err := filepath.Abs(d); err == nil {
d = a
diff --git a/src/cmds/restic/cmd_version.go b/src/cmds/restic/cmd_version.go
index 1bc7b99..9290af0 100644
--- a/src/cmds/restic/cmd_version.go
+++ b/src/cmds/restic/cmd_version.go
@@ -15,8 +15,8 @@ The "version" command prints detailed information about the build environment
and the version of this software.
`,
Run: func(cmd *cobra.Command, args []string) {
- fmt.Printf("restic %s\ncompiled at %s with %v on %v/%v\n",
- version, compiledAt, runtime.Version(), runtime.GOOS, runtime.GOARCH)
+ fmt.Printf("restic %s\ncompiled with %v on %v/%v\n",
+ version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
},
}
diff --git a/src/cmds/restic/global.go b/src/cmds/restic/global.go
index b4e172d..fdedeee 100644
--- a/src/cmds/restic/global.go
+++ b/src/cmds/restic/global.go
@@ -10,8 +10,6 @@ import (
"strings"
"syscall"
- "github.com/spf13/cobra"
-
"restic/backend/local"
"restic/backend/rest"
"restic/backend/s3"
@@ -26,19 +24,6 @@ import (
)
var version = "compiled manually"
-var compiledAt = "unknown time"
-
-func parseEnvironment(cmd *cobra.Command, args []string) {
- repo := os.Getenv("RESTIC_REPOSITORY")
- if repo != "" {
- globalOptions.Repo = repo
- }
-
- pw := os.Getenv("RESTIC_PASSWORD")
- if pw != "" {
- globalOptions.password = pw
- }
-}
// GlobalOptions hold all global options for restic.
type GlobalOptions struct {
@@ -58,8 +43,13 @@ var globalOptions = GlobalOptions{
}
func init() {
+ pw := os.Getenv("RESTIC_PASSWORD")
+ if pw != "" {
+ globalOptions.password = pw
+ }
+
f := cmdRoot.PersistentFlags()
- f.StringVarP(&globalOptions.Repo, "repo", "r", "", "repository to backup to or restore from (default: $RESTIC_REPOSITORY)")
+ f.StringVarP(&globalOptions.Repo, "repo", "r", os.Getenv("RESTIC_REPOSITORY"), "repository to backup to or restore from (default: $RESTIC_REPOSITORY)")
f.StringVarP(&globalOptions.PasswordFile, "password-file", "p", "", "read the repository password from a file")
f.BoolVarP(&globalOptions.Quiet, "quiet", "q", false, "do not outputcomprehensive progress report")
f.BoolVar(&globalOptions.NoLock, "no-lock", false, "do not lock the repo, this allows some operations on read-only repos")
@@ -132,7 +122,7 @@ func Printf(format string, args ...interface{}) {
_, err := fmt.Fprintf(globalOptions.stdout, format, args...)
if err != nil {
fmt.Fprintf(os.Stderr, "unable to write to stdout: %v\n", err)
- os.Exit(100)
+ Exit(100)
}
}
@@ -175,18 +165,19 @@ func Warnf(format string, args ...interface{}) {
_, err := fmt.Fprintf(globalOptions.stderr, format, args...)
if err != nil {
fmt.Fprintf(os.Stderr, "unable to write to stderr: %v\n", err)
- os.Exit(100)
+ Exit(100)
}
}
-// Exitf uses Warnf to write the message and then calls os.Exit(exitcode).
+// Exitf uses Warnf to write the message and then terminates the process with
+// the given exit code.
func Exitf(exitcode int, format string, args ...interface{}) {
if format[len(format)-1] != '\n' {
format += "\n"
}
Warnf(format, args...)
- os.Exit(exitcode)
+ Exit(exitcode)
}
// readPassword reads the password from the given reader directly.
diff --git a/src/cmds/restic/lock.go b/src/cmds/restic/lock.go
index 13f4c2d..81bdafb 100644
--- a/src/cmds/restic/lock.go
+++ b/src/cmds/restic/lock.go
@@ -36,6 +36,7 @@ func lockRepository(repo *repository.Repository, exclusive bool) (*restic.Lock,
if err != nil {
return nil, err
}
+ debug.Log("create lock %p (exclusive %v)", lock, exclusive)
globalLocks.Lock()
if globalLocks.cancelRefresh == nil {
@@ -88,7 +89,7 @@ func unlockRepo(lock *restic.Lock) error {
globalLocks.Lock()
defer globalLocks.Unlock()
- debug.Log("unlocking repository")
+ debug.Log("unlocking repository with lock %p", lock)
if err := lock.Unlock(); err != nil {
debug.Log("error while unlocking: %v", err)
return err
diff --git a/src/cmds/restic/main.go b/src/cmds/restic/main.go
index 2e55ba4..fed711b 100644
--- a/src/cmds/restic/main.go
+++ b/src/cmds/restic/main.go
@@ -20,9 +20,8 @@ var cmdRoot = &cobra.Command{
restic is a backup program which allows saving multiple revisions of files and
directories in an encrypted repository stored on different backends.
`,
- SilenceErrors: true,
- SilenceUsage: true,
- PersistentPreRun: parseEnvironment,
+ SilenceErrors: true,
+ SilenceUsage: true,
}
func init() {
@@ -49,9 +48,10 @@ func main() {
fmt.Fprintf(os.Stderr, "%+v\n", err)
}
- RunCleanupHandlers()
-
+ var exitCode int
if err != nil {
- os.Exit(1)
+ exitCode = 1
}
+
+ Exit(exitCode)
}
diff --git a/src/restic/repository/master_index.go b/src/restic/repository/master_index.go
index b037ac2..165bf60 100644
--- a/src/restic/repository/master_index.go
+++ b/src/restic/repository/master_index.go
@@ -119,16 +119,14 @@ func (mi *MasterIndex) Remove(index *Index) {
}
}
-// Current returns an index that is not yet finalized, so that new entries can
-// still be added. If all indexes are finalized, a new index is created and
-// returned.
-func (mi *MasterIndex) Current() *Index {
+// Store remembers the id and pack in the index.
+func (mi *MasterIndex) Store(pb restic.PackedBlob) {
mi.idxMutex.RLock()
-
for _, idx := range mi.idx {
if !idx.Final() {
mi.idxMutex.RUnlock()
- return idx
+ idx.Store(pb)
+ return
}
}
@@ -137,9 +135,8 @@ func (mi *MasterIndex) Current() *Index {
defer mi.idxMutex.Unlock()
newIdx := NewIndex()
+ newIdx.Store(pb)
mi.idx = append(mi.idx, newIdx)
-
- return newIdx
}
// NotFinalIndexes returns all indexes that have not yet been saved.
diff --git a/src/restic/repository/packer_manager.go b/src/restic/repository/packer_manager.go
index 499abd9..c686eff 100644
--- a/src/restic/repository/packer_manager.go
+++ b/src/restic/repository/packer_manager.go
@@ -133,7 +133,7 @@ func (r *Repository) savePacker(p *pack.Packer) error {
// update blobs in the index
for _, b := range p.Blobs() {
debug.Log(" updating blob %v to pack %v", b.ID.Str(), id.Str())
- r.idx.Current().Store(restic.PackedBlob{
+ r.idx.Store(restic.PackedBlob{
Blob: restic.Blob{
Type: b.Type,
ID: b.ID,