]> arthur.barton.de Git - bup.git/blob - Documentation/bup-restore.md
Add support for "restore --sparse"
[bup.git] / Documentation / bup-restore.md
1 % bup-restore(1) Bup %BUP_VERSION%
2 % Avery Pennarun <apenwarr@gmail.com>
3 % %BUP_DATE%
4
5 # NAME
6
7 bup-restore - extract files from a backup set
8
9 # SYNOPSIS
10
11 bup restore [\--outdir=*outdir*] [\--exclude-rx *pattern*]
12 [\--exclude-rx-from *filename*] [-v] [-q] \<paths...\>
13
14 # DESCRIPTION
15
16 `bup restore` extracts files from a backup set (created
17 with `bup-save`(1)) to the local filesystem.
18
19 The specified *paths* are of the form
20 /_branch_/_revision_/_some/where_.  The components of the
21 path are as follows:
22
23 branch
24 :   the name of the backup set to restore from; this
25     corresponds to the `--name` (`-n`) option to `bup save`.
26
27 revision
28 :   the revision of the backup set to restore.  The
29     revision *latest* is always the most recent
30     backup on the given branch.  You can discover other
31     revisions using `bup ls /branch`.
32     
33 some/where
34 :   the previously saved path (after any stripping/grafting) that you
35     want to restore.  For example, `etc/passwd`.
36     
37 If _some/where_ names a directory, `bup restore` will restore that
38 directory and then recursively restore its contents.
39
40 If _some/where_ names a directory and ends with a slash (ie.
41 path/to/dir/), `bup restore` will restore the children of that
42 directory directly to the current directory (or the `--outdir`).  If
43 _some/where_ does not end in a slash, the children will be restored to
44 a subdirectory of the current directory.
45
46 If _some/where_ names a directory and ends in '/.' (ie.
47 path/to/dir/.), `bup restore` will do exactly what it would have done
48 for path/to/dir, and then restore _dir_'s metadata to the current
49 directory (or the `--outdir`).  See the EXAMPLES section.
50
51 Whenever path metadata is available, `bup restore` will attempt to
52 restore it.  When restoring ownership, bup implements tar/rsync-like
53 semantics.  It will normally prefer user and group names to uids and
54 gids when they're available, but it will not try to restore the user
55 unless running as root, and it will fall back to the numeric uid or
56 gid whenever the metadata contains a user or group name that doesn't
57 exist on the current system.  The use of user and group names can be
58 disabled via `--numeric-ids` (which can be important when restoring a
59 chroot, for example), and as a special case, a uid or gid of 0 will
60 never be remapped by name.  Additionally, some systems don't allow
61 setting a uid/gid that doesn't correspond with a known user/group.  On
62 those systems, bup will log an error for each relevant path.
63
64 The `--map-user`, `--map-group`, `--map-uid`, `--map-gid` options may
65 be used to adjust the available ownership information before any of
66 the rules above are applied, but note that due to those rules,
67 `--map-uid` and `--map-gid` will have no effect whenever a path has a
68 valid user or group.  In those cases, either `--numeric-ids` must be
69 specified, or the user or group must be cleared by a suitable
70 `--map-user foo=` or `--map-group foo=`.
71
72 Hardlinks will also be restored when possible, but at least currently,
73 no links will be made to targets outside the restore tree, and if the
74 restore tree spans a different arrangement of filesystems from the
75 save tree, some hardlink sets may not be completely restored.
76
77 Also note that changing hardlink sets on disk between index and save
78 may produce unexpected results.  With the current implementation, bup
79 will attempt to recreate any given hardlink set as it existed at index
80 time, even if all of the files in the set weren't still hardlinked
81 (but were otherwise identical) at save time.
82
83 Note that during the restoration process, access to data within the
84 restore tree may be more permissive than it was in the original
85 source.  Unless security is irrelevant, you must restore to a private
86 subdirectory, and then move the resulting tree to its final position.
87 See the EXAMPLES section for a demonstration.
88
89 # OPTIONS
90
91 -C, \--outdir=*outdir*
92 :   create and change to directory *outdir* before
93     extracting the files.
94
95 \--numeric-ids
96 :   restore numeric IDs (user, group, etc.) rather than names.
97
98 \--exclude-rx=*pattern*
99 :   exclude any path matching *pattern*, which must be a Python
100     regular expression (http://docs.python.org/library/re.html).  The
101     pattern will be compared against the full path rooted at the top
102     of the restore tree, without anchoring, so "x/y" will match
103     "ox/yard" or "box/yards".  To exclude the contents of /tmp, but
104     not the directory itself, use "^/tmp/.". (can be specified more
105     than once)
106
107     Note that the root of the restore tree (which matches '^/') is the
108     top of the archive tree being restored, and has nothing to do with
109     the filesystem destination.  Given "restore ... /foo/latest/etc/",
110     the pattern '^/passwd$' would match if a file named passwd had
111     been saved as '/foo/latest/etc/passwd'.
112
113     Examples:
114
115       * '/foo$' - exclude any file named foo
116       * '/foo/$' - exclude any directory named foo
117       * '/foo/.' - exclude the content of any directory named foo
118       * '^/tmp/.' - exclude root-level /tmp's content, but not /tmp itself
119
120 \--exclude-rx-from=*filename*
121 :   read --exclude-rx patterns from *filename*, one pattern per-line
122     (may be repeated).  Ignore completely empty lines.
123
124 \--sparse
125 :   write output data sparsely when reasonable.  Currently, reasonable
126     just means "at least whenever there are 512 or more consecutive
127     zeroes".
128
129 \--map-user *old*=*new*
130 :   for every path, restore the *old* (saved) user name as *new*.
131     Specifying "" for *new* will clear the user.  For example
132     "--map-user foo=" will allow the uid to take effect for any path
133     that originally had a user of "foo", unless countermanded by a
134     subsequent "--map-user foo=..." specification.  See DESCRIPTION
135     above for further information.
136
137 \--map-group *old*=*new*
138 :   for every path, restore the *old* (saved) group name as *new*.
139     Specifying "" for *new* will clear the group.  For example
140     "--map-group foo=" will allow the gid to take effect for any path
141     that originally had a group of "foo", unless countermanded by a
142     subsequent "--map-group foo=..." specification.  See DESCRIPTION
143     above for further information.
144
145 \--map-uid *old*=*new*
146 :   for every path, restore the *old* (saved) uid as *new*, unless
147     countermanded by a subsequent "--map-uid *old*=..." option.  Note
148     that the uid will only be relevant for paths with no user.  See
149     DESCRIPTION above for further information.
150
151 \--map-gid *old*=*new*
152 :   for every path, restore the *old* (saved) gid as *new*, unless
153     countermanded by a subsequent "--map-gid *old*=..." option.  Note
154     that the gid will only be relevant for paths with no user.  See
155     DESCRIPTION above for further information.
156
157 -v, \--verbose
158 :   increase log output.  Given once, prints every
159     directory as it is restored; given twice, prints every
160     file and directory.
161
162 -q, \--quiet
163 :   don't show the progress meter.  Normally, is stderr is
164     a tty, a progress display is printed that shows the
165     total number of files restored.
166
167 # EXAMPLES
168
169 Create a simple test backup set:
170     
171     $ bup index -u /etc
172     $ bup save -n mybackup /etc/passwd /etc/profile
173     
174 Restore just one file:
175     
176     $ bup restore /mybackup/latest/etc/passwd
177     Restoring: 1, done.
178     
179     $ ls -l passwd
180     -rw-r--r-- 1 apenwarr apenwarr 1478 2010-09-08 03:06 passwd
181
182 Restore etc to test (no trailing slash):
183     
184     $ bup restore -C test /mybackup/latest/etc
185     Restoring: 3, done.
186     
187     $ find test
188     test
189     test/etc
190     test/etc/passwd
191     test/etc/profile
192     
193 Restore the contents of etc to test (trailing slash):
194
195     $ bup restore -C test /mybackup/latest/etc/
196     Restoring: 2, done.
197     
198     $ find test
199     test
200     test/passwd
201     test/profile
202
203 Restore the contents of etc and etc's metadata to test (trailing
204 "/."):
205
206     $ bup restore -C test /mybackup/latest/etc/.
207     Restoring: 2, done.
208     
209     # At this point test and etc's metadata will match.
210     $ find test
211     test
212     test/passwd
213     test/profile
214
215 Restore a tree without risk of unauthorized access:
216
217     # mkdir --mode 0700 restore-tmp
218
219     # bup restore -C restore-tmp /somebackup/latest/foo
220     Restoring: 42, done.
221
222     # mv restore-tmp/foo somewhere
223
224     # rmdir restore-tmp
225     
226 Restore a tree, remapping an old user and group to a new user and group:
227
228     # ls -l /original/y
229     -rw-r----- 1 foo baz  3610 Nov  4 11:31 y
230     # bup restore -C dest --map-user foo=bar --map-group baz=bax /x/latest/y
231     Restoring: 42, done.
232     # ls -l dest/y
233     -rw-r----- 1 bar bax  3610 Nov  4 11:31 y
234
235 Restore a tree, remapping an old uid to a new uid.  Note that the old
236 user must be erased so that bup won't prefer it over the uid:
237
238     # ls -l /original/y
239     -rw-r----- 1 foo baz  3610 Nov  4 11:31 y
240     # ls -ln /original/y
241     -rw-r----- 1 1000 1007  3610 Nov  4 11:31 y
242     # bup restore -C dest --map-user foo= --map-uid 1000=1042 /x/latest/y
243     Restoring: 97, done.
244     # ls -ln dest/y
245     -rw-r----- 1 1042 1007  3610 Nov  4 11:31 y
246
247 An alternate way to do the same by quashing users/groups universally
248 with `--numeric-ids`:
249
250     # bup restore -C dest --numeric-ids --map-uid 1000=1042 /x/latest/y
251     Restoring: 97, done.
252
253 # SEE ALSO
254
255 `bup-save`(1), `bup-ftp`(1), `bup-fuse`(1), `bup-web`(1)
256
257 # BUP
258
259 Part of the `bup`(1) suite.