MAN page from Fedora 28 safecopy-1.7-12.fc28.i686.rpm
Section: SAFECOPY (1)
- rescue data from a source that causes IO errors
]... SOURCE DEST
safecopytries to get as much data from SOURCE as possible, even resorting to devicespecific low level operations if applicable.
This is achieved by identifying problematic or damaged areas, skipping overthem and continuing reading afterwards. The corresponding area in thedestination file is either skipped (on initial creation that means padded withzeros) or deliberately filled with a recognizable pattern to later findaffected files on a corrupted device.
Safecopy uses an incremental algorithm to identify the exact beginning and endof bad areas, allowing the user to trade minimum accesses to bad areas forthorough data resurrection.
Multiple passes over the same file are possible, to first retrieve as much datafrom a device as possible with minimum harm, and then trying to retrieve someof the remaining data with increasingly aggressive read attempts.
For this to work, the source device or file has to be seekable. For unseekabledevices (like tapes) you can try to use an external script to execute acontrolled skip over the damaged part for you.
(For example by using "mt seek" and "mt tell" on an SCSI tape device)See the "-S <seekscript>" parameter for details.
Performance and success of this tool depend extremely on the device driver,firmware and underlying hardware.
Currently safecopy supports RAW access to CDROM drives to read data directly ofa CD, bypassing some driver dependant error correction. This can speed up dataretrieval from CDs and reduce system load during recovery, as well asincrease the success rate. Safecopy uses the disc status syscall to determinesector size and addressing of CDs. This fails on mixed-mode or multi-sessionCDs, since the sector layout can change within the disk, but would still workon the the big majority of disks. Other disks can still be recovered usingnormal high level data access. Safecopy auto-detects the disk type involvedduring scan for disk and block size.
Some CD/DVD drives are known to cause the ATAPI bus to crash on errors, causingthe device driver to freeze for times up to and beyond a minute per error. Tryto avoid using such drives for media recovery. Using safecopys low level accessfeatures might help under some circumstances.
Some drives can read bad media better than others. Be sure to attempt datarecovery of CDs and DVDs on several different drives and computers.You can use safecopys incremental recovery feature to read previouslyunreadable sectors only.
Data recovery from damaged media is a delicate task, in the worst case itssuccess or failure can safe or ruin whole companies and seal affected peoplespersonal fate. It is paramount that any tools written for that purpose arereliable and trustworthy.
A user needs to know what exactly the software is doing to his hardware anddata. The outcome of any operation needs to be both understandable andpredictable.
An "intelligent data resurrection wizard" with unknown complex internalbehaviour may be a nifty tool, but does not meet the above requirements ofpredictable outcome, nor will the user know in advance what is done to hisdata.
The operation sequence of safecopy has been kept relatively simple to assurethis predictability. Unfortunately feature additions have risen the complexityand lead to undefined outcome in the past when include and exclude lists hadbeen mixed, especially when mixing different block sizes. In the worst casethis could have lead to overwritten data in the destination file on a laterincremental run with the mark (-M) option.
From version 1.3 on, safecopy ships with a test suite that can be used to verifysafecopys behaviour in a set of test cases, simulating the combination of badblocks in input with different include and exclude lists, both with and withoutmarking. Releases are only made if safecopy passes those test cases accordingto the specification.
This textual specification of behaviour of safecopy can be found in the filespecification.txt shipped with safecopy.
- Preset to rescue most of the data fast,using no retries and avoiding bad areas.
- Presets: -f 10% -r 10% -R 1 -Z 0 -L 2 -M BaDbLoCk -o stage1.badblocks
- Preset to rescue more data, using no retriesbut searching for exact ends of bad areas.
- Presets: -f 128* -r 1* -R 1 -Z 0 -L 2 -I stage1.badblocks -o stage2.badblocks
- Preset to rescue everything that can be rescuedusing maximum retries, head realignment tricksand low level access.
- Presets: -f 1* -r 1* -R 4 -Z 1 -L 2 -I stage2.badblocks -o stage3.badblocks
All stage presets can be overridden by individual options.
- -b <size>
- Blocksize for default read operations.Set this to the physical sectorsize of your media.
- Default: 1*
Hardware block size if reported by OS, otherwise 4096
- -f <size>
- Blocksize in bytes when skipping over badblocks.Higher settings put less strain on your hardware,but you might miss good areas in between two bad ones.
- Default: 16*
- -r <size>
- Resolution in bytes when searching for the exact beginning or end of a badarea.If you read data directly from a device there is no need to set this lower thanthe hardware blocksize. On mounted filesystems however, read blocks andphysical blocks could be misaligned.Smaller values lead to very thorough attempts to read data at the edge ofdamaged areas, but increase the strain on the damaged media.
- Default: 1*
- -R <number>
- At least that many read attempts are made on the first bad block of a damagedarea with minimum resolution. More retries can sometimes recover a weaksector, but at the cost of additional strain.
- Default: 3
- -Z <number>
- On each error, force seek the read head from start to end of the source deviceas often as specified. That takes time, creates additional strain and mightnot be supported by all devices or drivers.
- Default: 1
- -L <mode>
- Use low level device calls as specified:
- 0 Do not use low level device calls
1 Attempt low level device calls
for error recovery only
2 Always use low level device calls
- Supported low level features in this version are:
- SYSTEM DEVICE TYPE FEATURE
Linux cdrom/dvd bus/device reset
Linux cdrom read sector in raw mode
Linux floppy controller reset, twaddle
- Default: 1
- Use synchronized read calls (disable driver buffering).Safecopy will use O_DIRECT if supported by the OS and O_SYNC otherwise.
- Default: Asynchronous read buffering by the OS is allowed
- Keep trying to reopen the source after a read erreruseful for USB drives that go away temporarily.
- Warning:This can cause safecopy to hang until aborted manually!
- Default: Abort on fopen() error
- -s <blocks>
- Start position where to start reading.Will correspond to position 0 in the destination file.
- Default: block 0
- -l <blocks>
- Maximum length of data to be read.
- Default: Entire size of input file
- -I <badblockfile>
- Incremental mode. Assume the target file already exists and has holes specifiedin the badblockfile. It will be attempted to retrieve more data from thelisted blocks or from beyond the file size of the target file only.
- Warning:Without this option, the destination file will be emptied prior to writing.Use -I /dev/null if you want to continue a previous run of safecopy without abadblock list.
- Implies: -c 0 if -c is not specified
- Default: none ( /dev/null if -c is given )
- -i <bytes>
- Blocksize to interpret the badblockfile given with -I.
- Default: Blocksize as specified by -b
- -c <blocks>
- Continue copying at this position.This allows continuing if the output is a block devicewith a fixed size as opposed to a growable file,where safecopy cannot determine how far it already got.The blocksize used is the same as for the -I option.
-c 0 will continue at the current destination size.
- Implies: -I /dev/null if -I is not specified
- Default: none ( 0 if -I is given )
- -X <badblockfile>
- Exclusion mode. If used together with -I, excluded blocks override includedblocks. Safecopy will not read or write any data from areas covered by excludeblocks.
- Default: none
- -x <bytes>
- Blocksize to interpret the badblockfile given with -X.
- Default: Blocksize as specified by -b
- -o <badblockfile>
- Write a badblocks/e2fsck compatible bad block file.
- Default: none
- -S <seekscript>
- Use external script for seeking in input file.(Might be useful for tape devices and similar).Seekscript must be an executable that takes the number of blocks to be skippedas argv1 (1-64) the blocksize in bytes as argv2 and the current position (inbytes) as argv3. Return value needs to be the number of blocks successfullyskipped, or 0 to indicate seek failure. The external seekscript will only beused if lseek() fails and we need to skip over data.
- Default: none
- -M <string>
- Mark unrecovered data with this string instead of skipping it. This helps inlater finding corrupted files on rescued file system images. The default is tozero unreadable data on creation of output files, and leaving the data as it ison any later run.
- Warning:When used in combination with incremental mode (-I) this may overwrite data inany block that occurs in the -I file. Blocks not in the -I file, or coveredby the file specified with -X are save from being overwritten.
- Default: none
- --debug <level>
- Enable debug output. Level is a bit field, add values together for more information:
program flow: 1
IO control: 2
badblock marking: 4
incremental mode: 16
exclude mode: 32
or for all debug output: 255
- Default: 0
- -T <timingfile>
- Write sector read timing information into this file for later analysis.
- Default: none
- -h, --help
- Show the program help text.
valid parameters for -f -r -b <size>
- Amount in bytes - i.e. 1024
- Percentage of whole file/device size - e.g. 10%
- -b only, number times blocksize reported by OS
- -f and -r only, number times the value of -b
description of output symbols:
- Between 1 and 1024 blocks successfully read.
- Read of block was incomplete. (possibly end of file) The blocksize is nowreduced to read the rest.
- Seek failed, source can only be read sequentially.
- Read failed, reducing blocksize to read partial data.
- A low level error on read attempt of smallest allowed size leads to a retryattempt.
- Current block and number of bytes continuously read successfully up to thispoint.
- Read failed on a block with minimum blocksize and is skipped.Unrecoverable error, destination file is padded with zeros.Data is now skipped until end of the unreadable area is reached.
- Successful read after the end of a bad area causes backtracking with smallerblocksizes to search for the first readable data.
- current block and number of bytes of recent continuous unreadable data.
How do I...
- - resurrect a file from a mounted but damaged media, that copy will fail on:
- safecopy/path/to/problemfile ~/saved-file
- - create an filesystem image of a damaged disk/cdrom:
- safecopy/dev/device ~/diskimage
- - resurrect data as thoroughly as possible?
- safecopysource dest -f 1* -R 8 -Z 2
(assuming logical misalignment of blocks to sectors)
- safecopysource dest -f 1* -r 1 -R 8 -Z 2
- - resurrect data as fast as possible, or
- - resurrect data with low risk of damaging the media further:
- (you can use even higher values for -f and -r)
- safecopysource dest -f 10% -R 0 -Z 0
- - resurrect some data fast, then read more data thoroughly later:
- safecopysource dest -f 10% -R 0 -Z 0 -o badblockfile
safecopysource dest -f 1* -R 8 -Z 2 -I badblockfile
- Alternate approach using the new preset features:
- safecopysource dest --stage1
- safecopysource dest --stage2
- safecopysource dest --stage3
- - utilize some friends CD-ROM drives to complete the data from my damaged CD:
- safecopy/dev/mydrive imagefile <someoptions> -b <myblocksize> -o myblockfile
safecopy/dev/otherdrive imagefile <someoptions> -b <otherblocksize> -I myblockfile -i <myblocksize> -o otherblockfile
safecopy/dev/anotherdrive imagefile <someoptions> -b <anotherblocksize> -I otherblockfile -i <otherblocksize>
- - interrupt and later resume a data rescue operation:
- safecopysource dest
safecopysource dest -I /dev/null
- - interrupt and later resume a data rescue operation with correct badblocks output:
- safecopysource dest <options> -o badblockfile
safecopysource dest -I /dev/null -o badblockfile
- - interrupt and resume in incremental mode:
(this needs a bit of bash scripting to get the correct badblock lists)
safecopysource dest <options> -o badblockfile1
safecopysource dest <options> -I badblockfile1 -o badblockfile2
latest=$( tail -n 1 badblockfile2 )
if [ -z $latest ]; then latest=-1; fi;
cat badblockfile1 | while read block; do
[ $block -gt $latest ] && echo $block >>badblockfile2;
safecopysource dest <options> -I badblockfile2 -o badblockfile3
- - find the corrupted files on a partially successful rescued file system:
- safecopy/dev/filesystem image -M CoRrUpTeD
mount-o loop image /mnt/mountpoint
grep-R /mnt/mountpoint "CoRrUpTeD"
(hint: this might not find all affected files if the unreadableparts are smaller in size than your marker string)
- - exclude the previously known badblocks list of a filesystem from filesystem image creation:
- dumpe2fs-b /dev/filesystem >badblocklist
safecopy/dev/filesystem image -X badblocklist -x <blocksize of your fs>
- - create an image of a device that starts at X and is Y in size:
- safecopy/dev/filesystem -b <bsize> -s <X/bsize> -l <Y/bsize>
- - combine two partial images of rescued data without access to the actual (damaged) source data:
- (This is a bit tricky. You need to get badblocks lists for both files somehowto make safecopy know where the missing data is. If you used the -M (mark)feature you might be able to automatically compute these, however this featureis not provided by safecopy. Lets assume you have two badblocks files.
- you have:
- The file size of image1 needs to be greater or equal to that of image2. (Ifnot, swap them))
- cpimage2.dat combined.dat
safecopyimage1.dat combined.dat -I image2.badblocks -i blocksize2 -X image1.badblocks -x blocksize1
(This gets you the combined data, but no output badblocklist.The resulting badblocks list would be the badblocks that are
a: in both badblocks lists, or
b: in image1.badblocks and beyond the file size of image2 It should bereasonably easy to solve this logic in a short shell script. One day this mightbe shipped with safecopy, until then consider this your chance to contribute toa random open source project.)
- - rescue data of a tape device:
- If the tape device driver supports lseek(), treat it as any file,otherwise utilize the "-S" option of safecopy with a to beself-written script to skip over the bad blocks.(for example using "mt seek")Make sure your tape device doesn't auto-rewind on close.Send me feedback if you had any luck doing so, so I can updatethis documentation.
- Why create this tool if there already is something like dd-rescue andother tools for that purpose?
- Because I didn't know of dd(-)rescue when I started, and I felt like it. Also Ithink safecopy suits the needs of a user in data loss peril better due to morereadable output and more understandable options than some of the other tools.(Then again I am biased. Compare them yourself)Meanwhile safecopy supports low level features other tools don't.
- What exactly does the -Z option do?
- Remember back in MS-DOS times when a floppy would make a "neek nark" sound 3times every time when running into a read error? This happened when the BIOSor DOS disk driver moved the IO head to its boundaries to possibly correctsmall cylinder misalignment, before it tried again. Linux doesn't do that bydefault, neither do common CDROM drives or drivers. Nevertheless forcing thisbehaviour can increase your chance of reading bad sectors from a CD __BIG__time. (Unlike floppies where it usually has little effect)
- Whats my best chance to resurrect a CD that has become unreadable?
- Try making a backup image on many different computers and drives. Theabilities to read from bad media vary extremely. I have a 6 year old Lite OnCDRW drive, that even reads deeply and purposely scratched CDs (as in with mykey, to make it unreadable) flawlessly. A CDRW drive of the same age at workdoesn't read any data from that part of the CD at all, while most DVD and combodrives have bad blocks every couple hundred bytes. Make full use of safecopysRAW access features if applicable. (-L 2 option)
- As a general guideline:-CDRW drives usually do better than read-only CD drives.
-CD only drives sometimes do better on CDs than DVD drives.
-PC drives are sometimes better than laptop ones.
-A drive with a clean lens does better than a dirtball.
-Cleaning up CDs helps.
-Unless you use chemicals.
-Using sticky tape on a CD will rip of the reflective layer permanentlyrendering the disk unreadable.
- Whats my best chance to resurrect a floppy that became unreadable?
- Again try different floppy drives. Keep in mind that it might be easier tofurther damage data on a bad floppy than on a CD. (Don't overdo read attempts)
- What about BlueRay/HDDVD disks?
- Hell if I knew, but generally they should be similar to DVDs. It probablydepends how the drives firmware acts up.
- My hard drive suddenly has many bad sectors, what should I do?
- Speed is an essential factor when rescuing data from a bad hard drive.Accesses to bad areas or even just time running can further damage thedrive and make formerly readable areas unreadable, be it due totemperature rise, damaged heads scratching still good parts of thesurface, bearings degrading due to vibration, etc. Its advisable toshut the system down and remove the hard drive from the computer as soonas errors occur and as fast as possible without causing further damage.
- (Don't pull the plug! Press reset to force reboot and then power downvia power button/ACPI)
- Set up a rescue system with enough disk space to store all the datafrom the damaged drive (and possibly multiple copies of it). If youhave an external hard drive case that connects via USB SATA or SCSI,allowing a hot plug of the drive into a running system, use it. Thisallows you to prepare everything without the need for the drive to powerup and possibly BIOS or operating system involuntarily accessing it.You also get easier access to the drive to check temperature or noiseduring operation.
- When you rescue data, rescue good data first before attempting toaccess bad sectors. Safecopy allows you to skip known problem sectorsusing a badblock exclude file (-X) which you might be able to retrievefrom system logs or from the drive internal logs, via smartmontools orsimilar software. Be aware that you might possibly need to convertphysical sector numbers into logical block numbers depending on yoursource.
- Also you should tell safecopy to jump out of any problematic areas ASAPand continue somewhere else. Parameters "-f 10% -r 10% -R 0 -Z 0" woulddo the trick by making safecopy skip 10% of the device content andcontinue there without backtracking. You can always attempt to get thedata in between later, first get the supposedly good data on the restof the drive. Depending on the method of data recovery you plan onusing, it may make sense to mark the bad data with the "-M" option.This allows you to later find files affected by data corruption moreeasily. Use the "-o" option to make safecopy write a badblock listwith all blocks skipped or unreadable.
- When safecopy is done with this first run, you can attempt a second gotrying to get more data. Using smaller values for "-f" and allowingsafecopy to backtrack for the end of the affected area "-r 1*".Be sure to use incremental mode "-I" to only read the blocks skippedin the first run.
- It may make sense to let the drive cool down between runs.Once you got all the data from the "good" areas of the drive you canrisk more "thorough" access to it. Increase the numbers of retries"-R" in case of bad blocks, maybe together with a head realignment"-Z 1". "-f 1*" would make safecopy try to read on every single block,not skipping over bad areas at all.
- If your drive stops responding, power it down, let it cool down for awhile, then try again.
- (I heard from people who brought dead drives back to live for a shorttime by cooling them to low temperatures with ice-packs.)
- !!!If the data is really important, go to a professional data recovery specialistright away, before doing further damage to the drive.
safecopy returns 0 (zero) if there were no unrecoverable errors.
safecopy returns 1 if some data could not be recovered.
safecopy returns 2 in case the copying was aborted due to error or signal.
safecopy and its manpage have been designed and written by CorvusCorax.
Please use the project page on sourceforge<http://www.sf.net/projects/safecopy
> to get in contact with projectdevelopment if you encounter bugs or want to contribute to safecopy.
Copyright © 2009 CorvusCorax
This is free software. You may redistribute copies of it under the terms ofthe GNU General Public License version 2 or above.<http://www.gnu.org/licenses/gpl.html
>.There is NO WARRANTY, to the extent permitted by law.
Programs with a similar scope are among others
- ddrescue(1), dd-rescue(1), ...
- EXIT STATUS
- SEE ALSO
This document was created byman2html,using the manual pages.