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 -o stage1.bad‐
104              blocks
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 -I stage1.badblocks -o
111              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 -I stage2.badblocks -o
118              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).  Safe‐
180              copy will use O_DIRECT if supported by the OS and O_SYNC  other‐
181              wise.
182
183              Default: Asynchronous read buffering by the OS is allowed
184
185       --forceopen
186              Keep  trying  to reopen the source after a read errer useful for
187              USB drives that go away temporarily.
188
189              Warning: This can cause safecopy to hang until aborted manually!
190
191              Default:  Abort on fopen() error
192
193       -s <blocks>
194              Start position where to start reading.  Will correspond to posi‐
195              tion 0 in the destination file.
196
197              Default: block 0
198
199       -l <blocks>
200              Maximum length of data to be read.
201
202              Default: Entire size of input file
203
204       -I <badblockfile>
205              Incremental  mode. Assume the target file already exists and has
206              holes specified in the badblockfile.  It will  be  attempted  to
207              retrieve  more  data  from  the listed blocks or from beyond the
208              file size of the target file only.
209
210              Warning: Without this option, the destination file will be  emp‐
211              tied prior to writing.  Use -I /dev/null if you want to continue
212              a previous run of safecopy without a badblock list.
213
214              Implies: -c 0 if -c is not specified
215
216              Default: none ( /dev/null if -c is given )
217
218       -i <bytes>
219              Blocksize to interpret the badblockfile given with -I.
220
221              Default: Blocksize as specified by -b
222
223       -c <blocks>
224              Continue copying at this position.  This  allows  continuing  if
225              the  output  is a block device with a fixed size as opposed to a
226              growable file,  where  safecopy  cannot  determine  how  far  it
227              already  got.   The  blocksize  used  is  the same as for the -I
228              option.
229              -c 0 will continue at the current destination size.
230
231              Implies: -I /dev/null if -I is not specified
232
233              Default: none ( 0 if -I is given )
234
235       -X <badblockfile>
236              Exclusion mode. If used together with -I, excluded blocks  over‐
237              ride  included  blocks. Safecopy will not read or write any data
238              from areas covered by exclude blocks.
239
240              Default: none
241
242       -x <bytes>
243              Blocksize to interpret the badblockfile given with -X.
244
245              Default: Blocksize as specified by -b
246
247       -o <badblockfile>
248              Write a badblocks/e2fsck compatible bad block file.
249
250              Default: none
251
252       -S <seekscript>
253              Use external script for seeking in input file.  (Might be useful
254              for tape devices and similar).  Seekscript must be an executable
255              that takes the number of blocks to be skipped  as  argv1  (1-64)
256              the  blocksize  in  bytes  as argv2 and the current position (in
257              bytes) as argv3.  Return value needs to be the number of  blocks
258              successfully skipped, or 0 to indicate seek failure.  The exter‐
259              nal seekscript will only be used if lseek() fails and we need to
260              skip over data.
261
262              Default: none
263
264       -M <string>
265              Mark  unrecovered  data with this string instead of skipping it.
266              This helps in later finding corrupted files on rescued file sys‐
267              tem  images.  The default is to zero unreadable data on creation
268              of output files, and leaving the data as it is on any later run.
269
270              Warning: When used in combination  with  incremental  mode  (-I)
271              this may overwrite data in any block that occurs in the -I file.
272              Blocks not in the -I file, or covered by the file specified with
273              -X are save from being overwritten.
274
275              Default: none
276
277       --debug <level>
278              Enable  debug  output. Level is a bit field, add values together
279              for more information:
280                   program flow:       1
281                   IO control:         2
282                   badblock marking:   4
283                   seeking:            8
284                   incremental mode:   16
285                   exclude mode:       32
286              or for all debug output: 255
287
288              Default: 0
289
290       -T <timingfile>
291              Write sector read timing information into this  file  for  later
292              analysis.
293
294              Default: none
295
296       -h, --help
297              Show the program help text.
298
299

PARAMETERS

301       valid parameters for -f -r -b <size> options are:
302
303       <integer>
304              Amount in bytes - i.e. 1024
305
306       <percentage>%
307              Percentage of whole file/device size - e.g. 10%
308
309       <number>*
310              -b only, number times blocksize reported by OS
311
312       <number>*
313              -f and -r only, number times the value of -b
314
315

OUTPUT

317       description of output symbols:
318
319       .      Between 1 and 1024 blocks successfully read.
320
321       _      Read  of block was incomplete. (possibly end of file) The block‐
322              size is now reduced to read the rest.
323
324       |/|    Seek failed, source can only be read sequentially.
325
326       >      Read failed, reducing blocksize to read partial data.
327
328       !      A low level error on read attempt of smallest allowed size leads
329              to a retry attempt.
330
331       [xx](+yy){
332              Current block and number of bytes continuously read successfully
333              up to this point.
334
335       X      Read failed on a block with minimum blocksize  and  is  skipped.
336              Unrecoverable  error,  destination  file  is  padded with zeros.
337              Data is now skipped until end of the unreadable area is reached.
338
339       <      Successful read after the end of a bad area causes  backtracking
340              with smaller blocksizes to search for the first readable data.
341
342       }[xx](+yy)
343              current  block  and number of bytes of recent continuous unread‐
344              able data.
345
346

HOWTO

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

FAQ

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

EXIT STATUS

602       safecopy returns 0 (zero) if there were no unrecoverable errors.
603       safecopy returns 1 if some data could not be recovered.
604       safecopy returns 2 in case the copying was aborted due to error or sig‐
605       nal.
606
607

AUTHORS

609       safecopy and its manpage have been designed and written by CorvusCorax.
610
611

BUGS

613       Please      use      the      project      page      on     sourceforge
614       <http://www.sf.net/projects/safecopy> to get in  contact  with  project
615       development if you encounter bugs or want to contribute to safecopy.
616
617
619       Copyright © 2009 CorvusCorax
620       This  is  free  software.   You may redistribute copies of it under the
621       terms  of  the  GNU  General  Public  License  version  2   or   above.
622       <http://www.gnu.org/licenses/gpl.html>.   There  is NO WARRANTY, to the
623       extent permitted by law.
624
625

SEE ALSO

627       Programs with a similar scope are among others
628       ddrescue(1), dd-rescue(1), ...
629
630
631
632
633
634                                  2012-03-10                       SAFECOPY(1)
Impressum