From: Rob Browning Date: Sun, 24 Sep 2017 16:26:29 +0000 (-0500) Subject: Add restore from remote: "bup restore -r host:path ..." X-Git-Tag: 0.30~173 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=bup.git;a=commitdiff_plain;h=e5694a4dd6289d29d40e59ba3ca69bbb0cd2449d Add restore from remote: "bup restore -r host:path ..." Signed-off-by: Rob Browning Tested-by: Rob Browning --- diff --git a/README.md b/README.md index 31bb2bf..dd54550 100644 --- 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, diff --git a/cmd/restore-cmd.py b/cmd/restore-cmd.py index 23a0d4d..3308f3f 100755 --- a/cmd/restore-cmd.py +++ b/cmd/restore-cmd.py @@ -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] +bup restore [-r host:path] [-C outdir] -- +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: diff --git a/t/test-save-restore b/t/test-save-restore index d1007ab..e022243 100755 --- a/t/test-save-restore +++ b/t/test-save-restore @@ -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"