1SAFECOPY(1)                        SAFECOPY                        SAFECOPY(1)
2
3
4

NAME

6       safecopy - rescue data from a source that causes IO errors
7
8

SYNOPSIS

10       safecopy [OPTION]... SOURCE DEST
11
12

DESCRIPTION

14       safecopy  tries  to  get  as  much  data  from SOURCE as possible, even
15       resorting to device specific low level operations if applicable.
16
17       This is achieved by identifying problematic or damaged areas,  skipping
18       over  them and continuing reading afterwards. The corresponding area in
19       the destination file is either skipped (on initial creation that  means
20       padded  with  zeros) or deliberately filled with a recognizable pattern
21       to later find affected files on a corrupted device.
22
23       Safecopy uses an incremental algorithm to identify the exact  beginning
24       and  end  of  bad areas, allowing the user to trade minimum accesses to
25       bad areas for thorough data resurrection.
26
27       Multiple passes over the same file are possible, to first  retrieve  as
28       much  data from a device as possible with minimum harm, and then trying
29       to retrieve some of the remaining  data  with  increasingly  aggressive
30       read attempts.
31
32       For  this  to  work,  the source device or file has to be seekable. For
33       unseekable devices (like tapes) you can try to use an  external  script
34       to execute a controlled skip over the damaged part for you.
35
36       (For  example  by using "mt seek" and "mt tell" on an SCSI tape device)
37       See the "-S <seekscript>" parameter for details.
38
39       Performance and success of this tool depend  extremely  on  the  device
40       driver, firmware and underlying hardware.
41
42       Currently  safecopy  supports  RAW  access to CDROM drives to read data
43       directly of a CD, bypassing some  driver  dependant  error  correction.
44       This can speed up data retrieval from CDs and reduce system load during
45       recovery, as well as increase the success rate. Safecopy uses the  disc
46       status  syscall  to  determine  sector size and addressing of CDs. This
47       fails on mixed-mode or multi-session CDs, since the sector  layout  can
48       change within the disk, but would still work on the the big majority of
49       disks. Other disks can still be recovered using normal high level  data
50       access.  Safecopy  auto-detects  the disk type involved during scan for
51       disk and block size.
52
53       Some CD/DVD drives are known to cause the ATAPI bus to crash on errors,
54       causing the device driver to freeze for times up to and beyond a minute
55       per error. Try to avoid using such drives  for  media  recovery.  Using
56       safecopys  low  level  access  features  might  help under some circum‐
57       stances.
58
59       Some drives can read bad media better than others. Be sure  to  attempt
60       data  recovery  of CDs and DVDs on several different drives and comput‐
61       ers.  You can use safecopys incremental recovery feature to read previ‐
62       ously unreadable sectors only.
63
64

RELIABILITY

66       Data  recovery from damaged media is a delicate task, in the worst case
67       its success or failure can  safe  or  ruin  whole  companies  and  seal
68       affected  peoples personal fate. It is paramount that any tools written
69       for that purpose are reliable and trustworthy.
70
71       A user needs to know what exactly the software is doing to his hardware
72       and  data. The outcome of any operation needs to be both understandable
73       and predictable.
74
75       An "intelligent data resurrection wizard" with unknown complex internal
76       behaviour may be a nifty tool, but does not meet the above requirements
77       of predictable outcome, nor will the user know in advance what is  done
78       to his data.
79
80       The  operation  sequence of safecopy has been kept relatively simple to
81       assure this predictability. Unfortunately feature additions have  risen
82       the  complexity  and lead to undefined outcome in the past when include
83       and exclude lists had been  mixed,  especially  when  mixing  different
84       block sizes. In the worst case this could have lead to overwritten data
85       in the destination file on a later incremental run with the  mark  (-M)
86       option.
87
88       From  version 1.3 on, safecopy ships with a test suite that can be used
89       to verify safecopys behaviour in a set of test  cases,  simulating  the
90       combination  of  bad blocks in input with different include and exclude
91       lists, both with and without marking. Releases are only made  if  safe‐
92       copy passes those test cases according to the specification.
93
94       This textual specification of behaviour of safecopy can be found in the
95       file specification.txt shipped with safecopy.
96
97

OPTIONS

99       --stage1
100              Preset to rescue most of the data fast,  using  no  retries  and
101              avoiding bad areas.
102
103              Presets: -f 10% -r 10% -R 1 -Z 0 -L 2 -M BaDbLoCk \
104              -o stage1.badblocks
105
106       --stage2
107              Preset  to  rescue more data, using no retries but searching for
108              exact ends of bad areas.
109
110              Presets: -f 128* -r 1* -R 1 -Z 0 -L 2 \
111              -I stage1.badblocks -o stage2.badblocks
112
113       --stage3
114              Preset to rescue everything that can be  rescued  using  maximum
115              retries, head realignment tricks and low level access.
116
117              Presets: -f 1* -r 1* -R 4 -Z 1 -L 2 \
118              -I stage2.badblocks -o stage3.badblocks
119
120       All stage presets can be overridden by individual options.
121
122       -b <size>
123              Blocksize for default read operations.  Set this to the physical
124              sectorsize of your media.
125
126              Default: 1*
127              Hardware block size if reported by OS, otherwise 4096
128
129       -f <size>
130              Blocksize in bytes when skipping over  badblocks.   Higher  set‐
131              tings  put less strain on your hardware, but you might miss good
132              areas in between two bad ones.
133
134              Default: 16*
135
136       -r <size>
137              Resolution in bytes when searching for the  exact  beginning  or
138              end  of  a  bad  area.   If you read data directly from a device
139              there is no need to set this lower than the hardware  blocksize.
140              On  mounted filesystems however, read blocks and physical blocks
141              could be misaligned.   Smaller  values  lead  to  very  thorough
142              attempts to read data at the edge of damaged areas, but increase
143              the strain on the damaged media.
144
145              Default: 1*
146
147       -R <number>
148              At least that many read attempts are made on the first bad block
149              of  a  damaged  area  with minimum resolution.  More retries can
150              sometimes recover a weak sector, but at the cost  of  additional
151              strain.
152
153              Default: 3
154
155       -Z <number>
156              On each error, force seek the read head from start to end of the
157              source device as often as specified.  That takes  time,  creates
158              additional  strain  and might not be supported by all devices or
159              drivers.
160
161              Default: 1
162
163       -L <mode>
164              Use low level device calls as specified:
165
166              0    Do not use low level device calls
167              1    Attempt low level device calls for error recovery only
168              2    Always use low level device calls if available
169
170              Supported low level features in this version are:
171
172              SYSTEM  DEVICE TYPE   FEATURE
173              Linux   cdrom/dvd     bus/device reset
174              Linux   cdrom         read sector in raw mode
175              Linux   floppy        controller reset, twaddle
176
177              Default: 1
178
179       --sync Use synchronized read calls (disable driver buffering).
180
181              Default: Asynchronous read buffering by the OS is allowed
182
183       -s <blocks>
184              Start position where to start reading.  Will correspond to posi‐
185              tion 0 in the destination file.
186
187              Default: block 0
188
189       -l <blocks>
190              Maximum length of data to be read.
191
192              Default: Entire size of input file
193
194       -I <badblockfile>
195              Incremental  mode. Assume the target file already exists and has
196              holes specified in the badblockfile.  It will  be  attempted  to
197              retrieve  more  data  from  the listed blocks or from beyond the
198              file size of the target file only.
199
200              Warning: Without this option, the destination file will be  emp‐
201              tied prior to writing.  Use -I /dev/null if you want to continue
202              a previous run of safecopy without a badblock list.
203
204              Default: none
205
206       -i <bytes>
207              Blocksize to interpret the badblockfile given with -I.
208
209              Default: Blocksize as specified by -b
210
211       -X <badblockfile>
212              Exclusion mode. If used together with -I, excluded blocks  over‐
213              ride  included  blocks. Safecopy will not read or write any data
214              from areas covered by exclude blocks.
215
216              Default: none
217
218       -x <bytes>
219              Blocksize to interpret the badblockfile given with -X.
220
221              Default: Blocksize as specified by -b
222
223       -o <badblockfile>
224              Write a badblocks/e2fsck compatible bad block file.
225
226              Default: none
227
228       -S <seekscript>
229              Use external script for seeking in input file.  (Might be useful
230              for tape devices and similar).  Seekscript must be an executable
231              that takes the number of blocks to be skipped  as  argv1  (1-64)
232              the  blocksize  in  bytes  as argv2 and the current position (in
233              bytes) as argv3.  Return value needs to be the number of  blocks
234              successfully skipped, or 0 to indicate seek failure.  The exter‐
235              nal seekscript will only be used if lseek() fails and we need to
236              skip over data.
237
238              Default: none
239
240       -M <string>
241              Mark  unrecovered  data with this string instead of skipping it.
242              This helps in later finding corrupted files on rescued file sys‐
243              tem  images.  The default is to zero unreadable data on creation
244              of output files, and leaving the data as it is on any later run.
245
246              Warning: When used in combination  with  incremental  mode  (-I)
247              this may overwrite data in any block that occurs in the -I file.
248              Blocks not in the -I file, or covered by the file specified with
249              -X are save from being overwritten.
250
251              Default: none
252
253       -h, --help
254              Show the program help text.
255
256

PARAMETERS

258       valid parameters for -f -r -b <size> options are:
259
260       <integer>
261              Amount in bytes - i.e. 1024
262
263       <percentage>%
264              Percentage of whole file/device size - e.g. 10%
265
266       <number>*
267              -b only, number times blocksize reported by OS
268
269       <number>*
270              -f and -r only, number times the value of -b
271
272

OUTPUT

274       description of output symbols:
275
276       .      Between 1 and 1024 blocks successfully read.
277
278       _      Read  of block was incomplete. (possibly end of file) The block‐
279              size is now reduced to read the rest.
280
281       |/|    Seek failed, source can only be read sequentially.
282
283       >      Read failed, reducing blocksize to read partial data.
284
285       !      A low level error on read attempt of smallest allowed size leads
286              to a retry attempt.
287
288       [xx](+yy){
289              Current block and number of bytes continuously read successfully
290              up to this point.
291
292       X      Read failed on a block with minimum blocksize  and  is  skipped.
293              Unrecoverable  error,  destination  file  is  padded with zeros.
294              Data is now skipped until end of the unreadable area is reached.
295
296       <      Successful read after the end of a bad area causes  backtracking
297              with smaller blocksizes to search for the first readable data.
298
299       }[xx](+yy)
300              current  block  and number of bytes of recent continuous unread‐
301              able data.
302
303

HOWTO

305       How do I...
306
307       - resurrect a file from a mounted but damaged  media,  that  copy  will
308       fail on:
309              safecopy /path/to/problemfile ~/saved-file
310
311       - create an filesystem image of a damaged disk/cdrom:
312              safecopy /dev/device ~/diskimage
313
314       - resurrect data as thoroughly as possible?
315
316              safecopy source dest -f 1* -R 8 -Z 2
317              (assuming logical misalignment of blocks to sectors)
318
319              safecopy source dest -f 1* -r 1 -R 8 -Z 2
320
321       - resurrect data as fast as possible, or
322
323       - resurrect data with low risk of damaging the media further:
324              (you can use even higher values for -f and -r)
325
326              safecopy source dest -f 10% -R 0 -Z 0
327
328       - resurrect some data fast, then read more data thoroughly later:
329
330              safecopy source dest -f 10% -R 0 -Z 0 -o badblockfile
331              safecopy source dest -f 1* -R 8 -Z 2 -I badblockfile
332
333              Alternate approach using the new preset features:
334
335              safecopy source dest --stage1
336
337              safecopy source dest --stage2
338
339              safecopy source dest --stage3
340
341       -  utilize some friends CD-ROM drives to complete the data from my dam‐
342       aged CD:
343              safecopy /dev/mydrive imagefile <someoptions>  -b  <myblocksize>
344              -o myblockfile
345              safecopy /dev/otherdrive imagefile <someoptions> -b <otherblock‐
346              size> -I myblockfile -i <myblocksize> -o otherblockfile
347              safecopy /dev/anotherdrive imagefile  <someoptions>  -b  <anoth‐
348              erblocksize> -I otherblockfile -i <otherblocksize>
349
350       - interrupt and later resume a data rescue operation:
351              safecopy source dest
352              <CTRL+C> (safecopy aborts)
353              safecopy source dest -I /dev/null
354
355       -  interrupt and later resume a data rescue operation with correct bad‐
356       blocks output:
357              safecopy source dest <options> -o badblockfile
358              <CTRL+C> (safecopy aborts)
359              mv badblockfile savedbadblockfile
360              safecopy source dest -I /dev/null -o badblockfile
361              cat badblockfile >>savedbadblockfile
362
363       - interrupt and resume in incremental mode:
364              (this needs a bit of bash scripting to get the correct  badblock
365              lists)
366              safecopy source dest <options> -o badblockfile1
367              safecopy source dest <options> -I badblockfile1 -o badblockfile2
368              <CTRL+C> (safecopy aborts)
369              latest=$( tail -n 1 badblockfile2 )
370              if [ -z $latest ]; then latest=-1; fi;
371              cat badblockfile1 | while read block; do
372                   [ $block -gt $latest ] && echo $block >>badblockfile2;
373              done;
374              safecopy source dest <options> -I badblockfile2 -o badblockfile3
375
376       -  find the corrupted files on a partially successful rescued file sys‐
377       tem:
378              safecopy /dev/filesystem image -M CoRrUpTeD
379              fsck image
380              mount -o loop image /mnt/mountpoint
381              grep -R /mnt/mountpoint "CoRrUpTeD"
382              (hint: this might not find all affected files if the  unreadable
383              parts are smaller in size than your marker string)
384
385       -  exclude  the  previously  known  badblocks list of a filesystem from
386       filesystem image creation:
387              dumpe2fs -b /dev/filesystem >badblocklist
388              safecopy /dev/filesystem image -X badblocklist -x <blocksize  of
389              your fs>
390
391       - create an image of a device that starts at X and is Y in size:
392              safecopy /dev/filesystem -b <bsize> -s <X/bsize> -l <Y/bsize>
393
394       -  combine  two  partial  images  of rescued data without access to the
395       actual (damaged) source data:
396              (This is a bit tricky. You need to get badblocks lists for  both
397              files  somehow  to make safecopy know where the missing data is.
398              If you used the -M (mark) feature you might be able to automati‐
399              cally  compute  these,  however  this feature is not provided by
400              safecopy. Lets assume you have two badblocks files.
401
402              you have:
403              image1.dat
404              image1.badblocks (blocksize1)
405              image2.dat
406              image2.badblocks (blocksize2)
407
408              The file size of image1 needs to be greater or equal to that  of
409              image2. (If not, swap them) )
410
411              cp image2.dat combined.dat
412              safecopy  image1.dat  combined.dat -I image2.badblocks -i block‐
413              size2 -X image1.badblocks -x blocksize1
414              (This gets you the combined data, but  no  output  badblocklist.
415              The resulting badblocks list would be the badblocks that are
416              a: in both badblocks lists, or
417              b:  in  image1.badblocks  and  beyond the file size of image2 It
418              should be reasonably easy to solve this logic in a  short  shell
419              script.  One day this might be shipped with safecopy, until then
420              consider this your chance to contribute to a random open  source
421              project.)
422
423       - rescue data of a tape device:
424              If  the  tape  device  driver  supports lseek(), treat it as any
425              file, otherwise utilize the "-S" option of safecopy with a to be
426              self-written  script  to skip over the bad blocks.  (for example
427              using "mt seek") Make sure your tape device doesn't  auto-rewind
428              on  close.   Send me feedback if you had any luck doing so, so I
429              can update this documentation.
430
431

FAQ

433       Q:     Why create this tool if there already is something like  dd-res‐
434              cue and other tools for that purpose?
435
436       A:     Because  I didn't know of dd(-)rescue when I started, and I felt
437              like it. Also I think safecopy suits the needs of a user in data
438              loss  peril  better  due to more readable output and more under‐
439              standable options than some of the other tools.  (Then  again  I
440              am  biased.  Compare  them yourself) Meanwhile safecopy supports
441              low level features other tools don't.
442
443       Q:     What exactly does the -Z option do?
444
445       A:     Remember back in MS-DOS times when a floppy would make  a  "neek
446              nark"  sound  3 times every time when running into a read error?
447              This happened when the BIOS or DOS disk driver moved the IO head
448              to  its  boundaries to possibly correct small cylinder misalign‐
449              ment, before it tried again.  Linux doesn't do that by  default,
450              neither do common CDROM drives or drivers.  Nevertheless forcing
451              this behaviour can increase your chance of reading  bad  sectors
452              from  a  CD __BIG__ time.  (Unlike floppies where it usually has
453              little effect)
454
455       Q:     Whats my best chance to resurrect a CD that has  become  unread‐
456              able?
457
458       A:     Try  making  a  backup  image  on  many  different computers and
459              drives.  The abilities to read from bad media vary extremely.  I
460              have a 6 year old Lite On CDRW drive, that even reads deeply and
461              purposely scratched CDs (as in with my key, to make  it  unread‐
462              able)  flawlessly.  A CDRW drive of the same age at work doesn't
463              read any data from that part of the CD at all,  while  most  DVD
464              and  combo  drives  have  bad blocks every couple hundred bytes.
465              Make full use of safecopys RAW access  features  if  applicable.
466              (-L 2 option)
467
468              As  a  general  guideline:  -CDRW  drives usually do better than
469              read-only CD drives.
470              -CD only drives sometimes do better on CDs than DVD drives.
471              -PC drives are sometimes better than laptop ones.
472              -A drive with a clean lens does better than a dirtball.
473              -Cleaning up CDs helps.
474              -Unless you use chemicals.
475              -Using sticky tape on a CD will rip of the reflective layer per‐
476              manently rendering the disk unreadable.
477
478       Q:     Whats  my  best chance to resurrect a floppy that became unread‐
479              able?
480
481       A:     Again try different floppy drives. Keep in mind that it might be
482              easier  to  further  damage  data  on a bad floppy than on a CD.
483              (Don't overdo read attempts)
484
485       Q:     What about BlueRay/HDDVD disks?
486
487       A:     Hell if I knew, but generally they should be  similar  to  DVDs.
488              It probably depends how the drives firmware acts up.
489
490       Q:     My hard drive suddenly has many bad sectors, what should I do?
491
492       A:     Speed  is an essential factor when rescuing data from a bad hard
493              drive.  Accesses to bad areas or even just time running can fur‐
494              ther  damage  the drive and make formerly readable areas unread‐
495              able, be it due to temperature rise,  damaged  heads  scratching
496              still  good  parts  of  the  surface,  bearings degrading due to
497              vibration, etc.  Its advisable  to  shut  the  system  down  and
498              remove  the hard drive from the computer as soon as errors occur
499              and as fast as possible without causing further damage.
500
501              (Don't pull the plug! Press reset to force reboot and then power
502              down via power button/ACPI)
503
504              Set  up  a rescue system with enough disk space to store all the
505              data from the damaged drive (and  possibly  multiple  copies  of
506              it).   If you have an external hard drive case that connects via
507              USB SATA or SCSI, allowing a hot plug of the drive into  a  run‐
508              ning  system,  use  it.   This  allows you to prepare everything
509              without the need for the drive to power up and possibly BIOS  or
510              operating  system involuntarily accessing it.  You also get eas‐
511              ier access to the drive to check  temperature  or  noise  during
512              operation.
513
514              When  you  rescue data, rescue good data first before attempting
515              to access bad sectors. Safecopy allows you to skip known problem
516              sectors  using  a  badblock exclude file (-X) which you might be
517              able to retrieve from system logs or  from  the  drive  internal
518              logs,  via  smartmontools or similar software. Be aware that you
519              might possibly need to convert physical sector numbers into log‐
520              ical block numbers depending on your source.
521
522              Also  you  should  tell  safecopy to jump out of any problematic
523              areas ASAP and continue somewhere else. Parameters  "-f  10%  -r
524              10% -R 0 -Z 0" would do the trick by making safecopy skip 10% of
525              the device content and continue there without backtracking.  You
526              can  always  attempt to get the data in between later, first get
527              the supposedly good data on the rest of the drive. Depending  on
528              the method of data recovery you plan on using, it may make sense
529              to mark the bad data with the "-M" option.  This allows  you  to
530              later  find  files affected by data corruption more easily.  Use
531              the "-o" option to make safecopy write a badblock list with  all
532              blocks skipped or unreadable.
533
534              When  safecopy  is  done  with this first run, you can attempt a
535              second go trying to get more data. Using smaller values for "-f"
536              and  allowing  safecopy to backtrack for the end of the affected
537              area "-r 1*".  Be sure to use incremental mode "-I" to only read
538              the blocks skipped in the first run.
539
540              It may make sense to let the drive cool down between runs.  Once
541              you got all the data from the "good" areas of the drive you  can
542              risk  more  "thorough"  access  to  it.  Increase the numbers of
543              retries "-R" in case of bad blocks, maybe together with  a  head
544              realignment  "-Z  1". "-f 1*" would make safecopy try to read on
545              every single block, not skipping over bad areas at all.
546
547              If your drive stops responding, power it down, let it cool  down
548              for a while, then try again.
549
550              (I  heard from people who brought dead drives back to live for a
551              short time by cooling them to low temperatures with ice-packs.)
552
553              !!!  If the data is really important, go to a professional  data
554              recovery  specialist  right away, before doing further damage to
555              the drive.
556
557

EXIT STATUS

559       safecopy always returns 0 (zero)  regardless  of  success  rate  and/or
560       aborted execution.
561
562

AUTHORS

564       safecopy and its manpage have been designed and written by CorvusCorax.
565
566

BUGS

568       Please      use      the      project      page      on     sourceforge
569       <http://www.sf.net/projects/safecopy> to get in  contact  with  project
570       development if you encounter bugs or want to contribute to safecopy.
571
572
574       Copyright © 2009 CorvusCorax
575       This  is  free  software.   You may redistribute copies of it under the
576       terms      of      the      GNU      General       Public       License
577       <http://www.gnu.org/licenses/gpl.html>.   There  is NO WARRANTY, to the
578       extent permitted by law.
579
580

SEE ALSO

582       Programs with a similar scope are among others
583       ddrescue(1), dd-rescue(1), ...
584
585
586
587
588
589                                  2009-05-27                       SAFECOPY(1)
Impressum