-
Notifications
You must be signed in to change notification settings - Fork 83
/
duperemove.8
494 lines (494 loc) · 16.7 KB
/
duperemove.8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
.\" Automatically generated by Pandoc 2.17.1.1
.\"
.\" Define V font for inline verbatim, using C font in formats
.\" that render this, and otherwise B font.
.ie "\f[CB]x\f[]"x" \{\
. ftr V B
. ftr VI BI
. ftr VB B
. ftr VBI BI
.\}
.el \{\
. ftr V CR
. ftr VI CI
. ftr VB CB
. ftr VBI CBI
.\}
.TH "Duperemove" "8" "18 Nov 2023" "duperemove 0.14" "System Manager\[cq]s Manual"
.hy
.SH NAME
.PP
\f[V]duperemove\f[R] - Find duplicate regions in files and submit them
for deduplication
.SH SYNOPSIS
.PP
\f[B]duperemove\f[R] \f[I]options\f[R] \f[I]files\&...\f[R]
.SH DESCRIPTION
.PP
\f[V]duperemove\f[R] is a simple tool for finding duplicated regions in
files and submitting them for deduplication.
When given a list of files it will hash their contents and compare those
hashes to each other, finding and categorizing regions that match each
other.
When given the \f[V]-d\f[R] option, \f[V]duperemove\f[R] will submit
those regions for deduplication using the Linux kernel FIDEDUPERANGE
ioctl.
.PP
\f[V]duperemove\f[R] computes hashes for each files extents as well as
for the whole file\[cq]s content.
Optionally, per-block hashes can be computed.
.PP
\f[V]duperemove\f[R] can store the hashes it computes in a
\f[V]hashfile\f[R].
If given an existing hashfile, \f[V]duperemove\f[R] will only compute
hashes for those files which have changed since the last run.
Thus you can run \f[V]duperemove\f[R] repeatedly on your data as it
changes, without having to re-checksum unchanged data.
For more on hashfiles see the \f[V]--hashfile\f[R] option below as well
as the \f[V]Examples\f[R] section.
.PP
\f[V]duperemove\f[R] can also take input from the \f[V]fdupes\f[R]
program, see the \f[V]--fdupes\f[R] option below.
.SH GENERAL
.PP
Duperemove has two major modes of operation, one of which is a subset of
the other.
.SS Readonly / Non-deduplicating Mode
.PP
When run without \f[V]-d\f[R] (the default) duperemove will print out
one or more tables of matching extents it has determined would be ideal
candidates for deduplication.
As a result, readonly mode is useful for seeing what duperemove might do
when run with \f[V]-d\f[R].
.PP
Generally, duperemove does not concern itself with the underlying
representation of the extents it processes.
Some of them could be compressed, undergoing I/O, or even have already
been deduplicated.
In dedupe mode, the kernel handles those details and therefore we try
not to replicate that work.
.SS Deduping Mode
.PP
This functions similarly to readonly mode with the exception that the
duplicated extents found in our \[lq]read, hash, and compare\[rq] step
will actually be submitted for deduplication.
Extents that have already been deduped will be skipped.
An estimate of the total data deduplicated will be printed after the
operation is complete.
This estimate is calculated by comparing the total amount of shared
bytes in each file before and after the dedupe.
.SH OPTIONS
.SS Common options
.PP
\f[V]files\f[R] can refer to a list of regular files and directories or
be a hyphen (-) to read them from standard input.
If a directory is specified, all regular files within it will also be
scanned.
Duperemove can also be told to recursively scan directories with the
\f[V]-r\f[R] switch.
.TP
\f[B]-r\f[R]
Enable recursive dir traversal.
.TP
\f[B]-d\f[R]
De-dupe the results - only works on \f[V]btrfs\f[R] and \f[V]xfs\f[R].
Use this option twice to disable the check and try to run the ioctl
anyway.
.TP
\f[B]--hashfile\f[R]=\f[V]hashfile\f[R]
Use a file for storage of hashes instead of memory.
This option drastically reduces the memory footprint of duperemove and
is recommended when your data set is more than a few files large.
\f[V]Hashfiles\f[R] are also reusable, allowing you to further reduce
the amount of hashing done on subsequent dedupe runs.
.RS
.PP
If \f[V]hashfile\f[R] does not exist it will be created.
If it exists, \f[V]duperemove\f[R] will check the file paths stored
inside of it for changes.
Files which have changed will be rescanned and their updated hashes will
be written to the \f[V]hashfile\f[R].
Deleted files will be removed from the \f[V]hashfile\f[R].
.PP
New files are only added to the \f[V]hashfile\f[R] if they are
discoverable via the \f[V]files\f[R] argument.
For that reason you probably want to provide the same \f[V]files\f[R]
list and \f[V]-r\f[R] arguments on each run of \f[V]duperemove\f[R].
The file discovery algorithm is efficient and will only visit each file
once, even if it is already in the \f[V]hashfile\f[R].
.PP
Adding a new path to a hashfile is as simple as adding it to the
\f[V]files\f[R] argument.
.PP
When deduping from a hashfile, duperemove will avoid deduping files
which have not changed since the last dedupe.
.RE
.TP
\f[B]-B\f[R] \f[V]N\f[R], \f[B]--batchsize\f[R]=\f[V]N\f[R]
Run the deduplication phase every \f[V]N\f[R] files newly scanned.
This greatly reduces memory usage for large dataset, or when you are
doing partial extents lookup, but reduces multithreading efficiency.
.RS
.PP
Because of that small overhead, its value shall be selected based on the
average file size and \f[V]blocksize\f[R].
.PP
The default is a sane value for extents-only lookups, while you can go
as low as \f[V]1\f[R] if you are running \f[V]duperemove\f[R] on very
large files (like virtual machines etc).
.PP
By default, batching is set to 1024.
.RE
.TP
\f[B]-h\f[R]
Print numbers in human-readable format.
.TP
\f[B]-q\f[R]
Quiet mode.
Duperemove will only print errors and a short summary of any dedupe.
.TP
\f[B]-v\f[R]
Be verbose.
.TP
\f[B]--help\f[R]
Prints help text.
.SS Advanced options
.TP
\f[B]--fdupes\f[R]
Run in \f[V]fdupes\f[R] mode.
With this option you can pipe the output of \f[V]fdupes\f[R] to
duperemove to dedupe any duplicate files found.
When receiving a file list in this manner, duperemove will skip the
hashing phase.
.TP
\f[B]-L\f[R]
Print all files in the hashfile and exit.
Requires the \f[V]--hashfile\f[R] option.
Will print additional information about each file when run with
\f[V]-v\f[R].
.TP
\f[B]-R\f[R] \f[V]files ..\f[R]
Remove file from the db and exit.
Duperemove will read the list from standard input if a hyphen (-) is
provided.
Requires the \f[V]--hashfile\f[R] option.
.RS
.PP
\f[V]Note:\f[R] If you are piping filenames from another duperemove
instance it is advisable to do so into a temporary file first as running
duperemove simultaneously on the same hashfile may corrupt that
hashfile.
.RE
.TP
\f[B]--skip-zeroes\f[R]
Read data blocks and skip any zeroed blocks, useful for speedup
duperemove, but can prevent deduplication of zeroed files.
.TP
\f[B]-b\f[R] \f[V]size\f[R]
Use the specified block size for reading file extents.
Defaults to 128K.
.TP
\f[B]--io-threads\f[R]=\f[V]N\f[R]
Use N threads for I/O.
This is used by the file hashing and dedupe stages.
Default is automatically detected based on number of host cpus.
.TP
\f[B]--cpu-threads\f[R]=\f[V]N\f[R]
Use N threads for CPU bound tasks.
This is used by the duplicate extent finding stage.
Default is automatically detected based on number of host cpus.
.RS
.PP
\f[V]Note:\f[R] Hyperthreading can adversely affect performance of the
extent finding stage.
If duperemove detects an Intel CPU with hyperthreading it will use half
the number of cores reported by the system for cpu bound tasks.
.RE
.TP
\f[B]--dedupe-options\f[R]=\f[V]options\f[R]
Comma separated list of options which alter how we dedupe.
Prepend `no' to an option in order to turn it off.
.RS
.TP
\f[B][no]partial\f[R]
Duperemove can often find more dedupe by comparing portions of extents
to each other.
This can be a lengthy, CPU intensive task so it is turned off by
default.
Using \f[V]--batchsize\f[R] is recommended to limit the negative effects
of this option.
.RS
.PP
The code behind this option is under active development and as a result
the semantics of the \f[V]partial\f[R] argument may change.
.RE
.TP
\f[B][no]same\f[R]
Defaults to \f[V]on\f[R].
Allow dedupe of extents within the same file.
.TP
\f[B][no]only_whole_files\f[R]
Defaults to \f[V]off\f[R].
Duperemove will only work on full file.
Both extent-based and block-based deduplication will be disabled.
The hashfile will be smaller, some operations will be faster, but the
deduplication efficiency will indeed be reduced.
.RE
.TP
\f[B]--read-hashes\f[R]=\f[V]hashfile\f[R]
\f[B]This option is primarily for testing\f[R].
See the \f[V]--hashfile\f[R] option if you want to use hashfiles.
.RS
.PP
Read hashes from a hashfile.
A file list is not required with this option.
Dedupe can be done if duperemove is run from the same base directory as
is stored in the hash file (basically duperemove has to be able to find
the files).
.RE
.TP
\f[B]--write-hashes\f[R]=\f[V]hashfile\f[R]
\f[B]This option is primarily for testing\f[R].
See the \f[V]--hashfile\f[R] option if you want to use hashfiles.
.RS
.PP
Write hashes to a hashfile.
These can be read in at a later date and deduped from.
.RE
.TP
\f[B]--debug\f[R]
Print debug messages, forces \f[V]-v\f[R] if selected.
.TP
\f[B]--hash-threads\f[R]=\f[V]N\f[R]
Deprecated, see \f[V]--io-threads\f[R] above.
.TP
\f[B]--exclude\f[R]=\f[V]PATTERN\f[R]
You can exclude certain files and folders from the deduplication
process.
This might be benefical for skipping subvolume snapshot mounts, for
instance.
Unless you provide a full path for exclusion, the exclude will be
relative to the current working directory.
Another thing to keep in mind is that shells usually expand glob pattern
so the passed in pattern ought to also be quoted.
Taking everything into consideration the correct way to pass an
exclusion pattern is
\f[V]duperemove --exclude \[dq]/path/to/dir/file*\[dq] /path/to/dir\f[R]
.SH EXAMPLES
.SS Simple Usage
.PP
Dedupe the files in directory /foo, recurse into all subdirectories.
You only want to use this for small data sets:
.IP
.nf
\f[C]
duperemove -dr /foo
\f[R]
.fi
.PP
Use duperemove with fdupes to dedupe identical files below directory
foo:
.IP
.nf
\f[C]
fdupes -r /foo | duperemove --fdupes
\f[R]
.fi
.SS Using Hashfiles
.PP
Duperemove can optionally store the hashes it calculates in a hashfile.
Hashfiles have two primary advantages - memory usage and re-usability.
When using a hashfile, duperemove will stream computed hashes to it,
instead of main memory.
.PP
If Duperemove is run with an existing hashfile, it will only scan those
files which have changed since the last time the hashfile was updated.
The \f[V]files\f[R] argument controls which directories duperemove will
scan for newly added files.
In the simplest usage, you rerun duperemove with the same parameters and
it will only scan changed or newly added files - see the first example
below.
.PP
Dedupe the files in directory foo, storing hashes in foo.hash.
We can run this command multiple times and duperemove will only checksum
and dedupe changed or newly added files:
.IP
.nf
\f[C]
duperemove -dr --hashfile=foo.hash foo/
\f[R]
.fi
.PP
Don\[cq]t scan for new files, only update changed or deleted files, then
dedupe:
.IP
.nf
\f[C]
duperemove -dr --hashfile=foo.hash
\f[R]
.fi
.PP
Add directory bar to our hashfile and discover any files that were
recently added to foo:
.IP
.nf
\f[C]
duperemove -dr --hashfile=foo.hash foo/ bar/
\f[R]
.fi
.PP
List the files tracked by foo.hash:
.IP
.nf
\f[C]
duperemove -L --hashfile=foo.hash
\f[R]
.fi
.SH FAQ
.SS Is duperemove safe for my data?
.PP
Yes.
To be specific, duperemove does not deduplicate the data itself.
It simply finds candidates for dedupe and submits them to the Linux
kernel FIDEDUPERANGE ioctl.
In order to ensure data integrity, the kernel locks out other access to
the file and does a byte-by-byte compare before proceeding with the
dedupe.
.SS Is is safe to interrupt the program (Ctrl-C)?
.PP
Yes.
The Linux kernel deals with the actual data.
On Duperemove\[cq] side, a transactional database engine is used.
The result is that you should be able to ctrl-c the program at any point
and re-run without experiencing corruption of your hashfile.
In case of a bug, your hashfile may be broken, but your data never will.
.SS I got two identical files, why are they not deduped?
.PP
Duperemove by default works on extent granularity.
What this means is if there are two files which are logically identical
(have the same content) but are laid out on disk with different extent
structure they won\[cq]t be deduped.
For example if 2 files are 128k each and their content are identical but
one of them consists of a single 128k extent and the other of 2 * 64k
extents then they won\[cq]t be deduped.
This behavior is dependent on the current implementation and is subject
to change as duperemove is being improved.
.SS What is the cost of deduplication?
.PP
Deduplication will lead to increased fragmentation.
The blocksize chosen can have an effect on this.
Larger blocksizes will fragment less but may not save you as much space.
Conversely, smaller block sizes may save more space at the cost of
increased fragmentation.
.SS How can I find out my space savings after a dedupe?
.PP
Duperemove will print out an estimate of the saved space after a dedupe
operation for you.
.PP
You can get a more accurate picture by running `btrfs fi df' before and
after each duperemove run.
.PP
Be careful about using the `df' tool on btrfs - it is common for space
reporting to be `behind' while delayed updates get processed, so an
immediate df after deduping might not show any savings.
.SS Why is the total deduped data report an estimate?
.PP
At the moment duperemove can detect that some underlying extents are
shared with other files, but it can not resolve which files those
extents are shared with.
.PP
Imagine duperemove is examining a series of files and it notes a shared
data region in one of them.
That data could be shared with a file outside of the series.
Since duperemove can\[cq]t resolve that information it will account the
shared data against our dedupe operation while in reality, the kernel
might deduplicate it further for us.
.SS Why are my files showing dedupe but my disk space is not shrinking?
.PP
This is a little complicated, but it comes down to a feature in Btrfs
called \f[I]bookending\f[R].
The Btrfs wiki (http://en.wikipedia.org/wiki/Btrfs#Extents) explains
this in detail.
.PP
Essentially though, the underlying representation of an extent in Btrfs
can not be split (with small exception).
So sometimes we can end up in a situation where a file extent gets
partially deduped (and the extents marked as shared) but the underlying
extent item is not freed or truncated.
.SS Is there an upper limit to the amount of data duperemove can process?
.PP
Duperemove is fast at reading and cataloging data.
Dedupe runs will be memory limited unless the \f[V]--hashfile\f[R]
option is used.
\f[V]--hashfile\f[R] allows duperemove to temporarily store duplicated
hashes to disk, thus removing the large memory overhead and allowing for
a far larger amount of data to be scanned and deduped.
Realistically though you will be limited by the speed of your disks and
cpu.
In those situations where resources are limited you may have success by
breaking up the input data set into smaller pieces.
.PP
When using a hashfile, duperemove will only store duplicate hashes in
memory.
During normal operation then the hash tree will make up the largest
portion of duperemove memory usage.
As of Duperemove v0.11 hash entries are 88 bytes in size.
If you know the number of duplicate blocks in your data set you can get
a rough approximation of memory usage by multiplying with the hash entry
size.
.PP
Actual performance numbers are dependent on hardware - up to date
testing information is kept on the duperemove wiki (see below for the
link).
.SS How large of a hashfile will duperemove create?
.PP
Hashfiles are essentially sqlite3 database files with several tables,
the largest of which are the files and extents tables.
Each extents table entry is about 72 bytes though that may grow as
features are added.
The size of a files table entry depends on the file path but a good
estimate is around 270 bytes per file.
The number of extents in a data set is directly proportional to file
fragmentation level.
.PP
If you know the total number of extents and files in your data set then
you can calculate the hashfile size as:
.IP
.nf
\f[C]
Hashfile Size = Num Hashes * 72 + Num Files * 270
\f[R]
.fi
.PP
Using a real world example of 1TB (8388608 128K blocks) of data over
1000 files:
.IP
.nf
\f[C]
8388608 * 72 + 270 * 1000 = 755244720 or about 720MB for 1TB spread over 1000 files.
\f[R]
.fi
.PP
\f[V]Note that none of this takes database overhead into account.\f[R]
.SH NOTES
.PP
Deduplication is currently only supported by the \f[V]btrfs\f[R] and
\f[V]xfs\f[R] filesystem.
.PP
The Duperemove project page can be found on
github (https://github.com/markfasheh/duperemove)
.PP
There is also a wiki (https://github.com/markfasheh/duperemove/wiki)
.SH SEE ALSO
.IP \[bu] 2
\f[V]hashstats(8)\f[R]
.IP \[bu] 2
\f[V]filesystems(5)\f[R]
.IP \[bu] 2
\f[V]btrfs(8)\f[R]
.IP \[bu] 2
\f[V]xfs(8)\f[R]
.IP \[bu] 2
\f[V]fdupes(1)\f[R]
.IP \[bu] 2
\f[V]ioctl_fideduprange(2)\f[R]