]> arthur.barton.de Git - bup.git/commitdiff
Add restore from remote: "bup restore -r host:path ..."
authorRob Browning <rlb@defaultvalue.org>
Sun, 24 Sep 2017 16:26:29 +0000 (11:26 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 8 Oct 2017 17:26:54 +0000 (12:26 -0500)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
README.md
cmd/restore-cmd.py
t/test-save-restore

index 31bb2bfefb79e379d88408b1b9e295c0c5e1f4ff..dd5455096e5ace64e8919c713af87358d583b012 100644 (file)
--- a/README.md
+++ b/README.md
@@ -246,9 +246,15 @@ Using bup
         bup index /etc
         bup save -r SERVERNAME:path/to/remote-bup-dir -n local-etc /etc
 
- - Restore a backup from a remote server.  (FAIL: unfortunately,
-   unlike "bup join", "bup restore" does not yet support remote
-   restores.  See both "bup join" and "Things that are stupid" below.)
+ - Make a remote backup to ~/.bup on SERVER:
+
+        bup index /etc
+        bup save -r SERVER: -n local-etc /etc
+
+ - Restore the remote backup to ./dest:
+
+        bup restore -r SERVER: -C ./dest local-etc/latest/etc
+        ls -l dest/etc
 
  - Defend your backups from death rays (OK fine, more likely from the
    occasional bad disk block).  This writes parity information
@@ -288,11 +294,12 @@ Using bup
  
         GIT_DIR=~/.bup git log local-etc
        
- - Make a backup on a remote server:
+ - Save a tar archive to a remote server (without tar -z to facilitate
+   deduplication):
    
         tar -cvf - /etc | bup split -r SERVERNAME: -n local-etc -vv
  
- - Try restoring the remote backup tarball:
+ - Restore the archive:
  
         bup join -r SERVERNAME: local-etc | tar -tf -
        
@@ -430,16 +437,6 @@ Things that are stupid for now but which we'll fix later
 Help with any of these problems, or others, is very welcome.  Join the
 mailing list (see below) if you'd like to help.
 
- - 'bup restore' can't pull directly from a remote server.
-
-    So in one sense "save -r" is a dead-end right now.  Obviously you
-    can use "ssh SERVER bup restore -C ./dest..." to create a tree you
-    can transfer elsewhere via rsync/tar/whatever, but that's *lame*.
-
-    Until we fix it, you may be able to mount the remote BUP_DIR via
-    sshfs and then restore "normally", though that hasn't been
-    officially tested.
-
  - 'bup save' and 'bup restore' have immature metadata support.
  
     On the plus side, they actually do have support now, but it's new,
index 23a0d4d8a6223a9f233197139e6056df906e61ac..3308f3ffd815841b4f3e5ece6ac165ee28afe20e 100755 (executable)
@@ -15,12 +15,13 @@ from bup.compat import wrap_main
 from bup.helpers import (add_error, chunkyreader, die_if_errors, handle_ctrl_c,
                          log, mkdirp, parse_rx_excludes, progress, qprogress,
                          saved_errors, should_rx_exclude_path, unlink)
-from bup.repo import LocalRepo
+from bup.repo import LocalRepo, RemoteRepo
 
 
 optspec = """
-bup restore [-C outdir] </branch/revision/path/to/dir ...>
+bup restore [-r host:path] [-C outdir] </branch/revision/path/to/dir ...>
 --
+r,remote=   remote repository path
 C,outdir=   change to given outdir before extracting files
 numeric-ids restore numeric IDs (user, group, etc.) rather than names
 exclude-rx= skip paths matching the unanchored regex (may be repeated)
@@ -237,7 +238,7 @@ def main():
         mkdirp(opt.outdir)
         os.chdir(opt.outdir)
 
-    repo = LocalRepo()
+    repo = RemoteRepo(opt.remote) if opt.remote else LocalRepo()
     top = os.getcwd()
     hardlinks = {}
     for path in extra:
index d1007ab7bf9324d302b366c5a9f9368fdf43040e..e022243093f47bfd0c27ede6cb3782f33a4dceb5 100755 (executable)
@@ -11,12 +11,22 @@ export BUP_DIR="$tmpdir/bup"
 
 bup() { "$top/bup" "$@"; }
 
+validate-local-and-remote-restore()
+{
+    local src="$1" dest="$2" cmp_src="$3" cmp_dest="$4"
+    force-delete "$dest"
+    WVPASS bup restore -C "$dest" "$src"
+    WVPASS "$top/t/compare-trees" "$cmp_src" "$cmp_dest"
+    force-delete "$dest"
+    WVPASS bup restore -r ":$BUP_DIR" -C "$dest" "$src"
+    WVPASS "$top/t/compare-trees" "$cmp_src" "$cmp_dest"
+}
+
+
 WVPASS cd "$tmpdir"
 
 WVSTART "init"
-
 WVPASS bup init
-
 D=bupdata.tmp
 WVPASS force-delete $D
 WVPASS mkdir $D
@@ -29,6 +39,7 @@ WVPASS touch $D/d/z
 WVPASS bup index $D
 WVPASS bup save -t $D
 
+
 WVSTART "restore"
 WVPASS force-delete buprestore.tmp
 WVFAIL bup restore boink
@@ -46,6 +57,7 @@ WVPASS echo -n "" | WVPASS bup split -n split_empty_string.tmp
 WVPASS bup restore -C buprestore.tmp split_empty_string.tmp/latest/
 WVPASSEQ "$(cat buprestore.tmp/data)" ""
 
+
 (
     tmp=testrestore.tmp
     WVPASS force-delete $tmp
@@ -59,37 +71,39 @@ WVPASSEQ "$(cat buprestore.tmp/data)" ""
     WVPASS bup save --strip -n foo $tmp/src
 
     WVSTART "restore /foo/latest"
-    WVPASS bup restore -C $tmp/restore /foo/latest
-    WVPASS "$top/t/compare-trees" $tmp/src/ $tmp/restore/latest/
-
-    WVSTART "restore /foo/latest/"
-    WVPASS force-delete "$tmp/restore"
-    WVPASS bup restore -C $tmp/restore /foo/latest/
-    for x in $tmp/src/*; do
-        WVPASS "$top/t/compare-trees" $x/ $tmp/restore/$(basename $x);
-    done
+    validate-local-and-remote-restore \
+        /foo/latest  "$tmp/restore" \
+        "$tmp/src/" "$tmp/restore/latest/"
 
     WVSTART "restore /foo/latest/."
     WVPASS force-delete "$tmp/restore"
-    WVPASS bup restore -C $tmp/restore /foo/latest/.
-    WVPASS "$top/t/compare-trees" $tmp/src/ $tmp/restore/
+    validate-local-and-remote-restore \
+        /foo/latest/.  "$tmp"/restore \
+        "$tmp"/src/ "$tmp"/restore
 
     WVSTART "restore /foo/latest/x"
     WVPASS force-delete "$tmp/restore"
-    WVPASS bup restore -C $tmp/restore /foo/latest/x
-    WVPASS "$top/t/compare-trees" $tmp/src/x/ $tmp/restore/x/
+    validate-local-and-remote-restore \
+        /foo/latest/x  "$tmp"/restore \
+        "$tmp"/src/x/ "$tmp"/restore/x/
 
     WVSTART "restore /foo/latest/x/"
-    WVPASS force-delete "$tmp/restore"
-    WVPASS bup restore -C $tmp/restore /foo/latest/x/
-    for x in $tmp/src/x/*; do
-        WVPASS "$top/t/compare-trees" $x/ $tmp/restore/$(basename $x);
+    WVPASS force-delete "$tmp/restore"  
+    WVPASS bup restore -C "$tmp"/restore /foo/latest/x/
+    for x in "$tmp"/src/x/*; do
+        WVPASS "$top/t/compare-trees" "$x/" "$tmp/restore/$(basename $x)"
+    done
+    WVPASS force-delete "$tmp/restore"  
+    WVPASS bup restore -r ":$BUP_DIR" -C "$tmp"/restore /foo/latest/x/
+    for x in "$tmp"/src/x/*; do
+        WVPASS "$top/t/compare-trees" "$x/" "$tmp/restore/$(basename $x)"
     done
 
     WVSTART "restore /foo/latest/x/."
     WVPASS force-delete "$tmp/restore"
-    WVPASS bup restore -C $tmp/restore /foo/latest/x/.
-    WVPASS "$top/t/compare-trees" $tmp/src/x/ $tmp/restore/
+    validate-local-and-remote-restore \
+        /foo/latest/x/.  "$tmp"/restore \
+        "$tmp"/src/x/ "$tmp"/restore/
 ) || exit $?
 
 
@@ -104,6 +118,7 @@ WVSTART "save (no index)"
     WVPASS rm -r "$tmp"
 ) || exit $?
 
+
 WVSTART "save disjoint top-level directories"
 (
     # Resolve any symlinks involving the top top-level dirs.
@@ -138,4 +153,6 @@ WVSTART "save disjoint top-level directories"
     WVPASSEQ "$actual" "$expected"
 ) || exit $?
 
+
+WVPASS cd "$top"
 WVPASS rm -rf "$tmpdir"