safecopy
safecopy is a data recovery tool which tries to extract as much data as possible from a problematic (i.e. damaged sectors) source - like floppy drives, hard disk partitions, CDs, tape devices, …, where other tools like dd would fail due to I/O errors.
Usage
Usage: safecopy [options] <source> <target>
| Option | Description |
|---|---|
--stage1 | 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 |
--stage2 | Preset to rescue more data, using no retries but searching for exact ends of bad areas. Presets: -f 128* -r 1* -R 1 -Z 0 -L 2 -I stage1.badblocks -o stage2.badblocks |
--stage3 | Preset to rescue everything that can be rescued using maximum retries, head realignment tricks and low level access. Presets: -f 1* -r 1* -R 4 -Z 1 -L 2 -I stage2.badblocks -o stage3.badblocks |
-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 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 bad area. If reading directly from device, no need to set lower than hardware blocksize. On mounted filesystems, read blocks and physical blocks could be misaligned. Smaller values lead to more thorough attempts but increase strain on damaged media. Default: 1* |
-R <number> | At least that many read attempts are made on the first bad block of a damaged area with minimum resolution. More retries can sometimes recover a weak sector, 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 device as often as specified. This takes time, creates additional strain and might not 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 if available Supported low level features include Linux cdrom/dvd bus/device reset, Linux cdrom read sector in raw mode, Linux floppy controller reset, twaddle. Default: 1 |
--sync | Use synchronized read calls (disable driver buffering). Safecopy will use O_DIRECT if supported by OS and O_SYNC otherwise. Default: Asynchronous read buffering by OS allowed |
--forceopen | Keep trying to reopen source after a read error, useful for USB drives that disconnect temporarily. Warning: Can cause safecopy to hang until aborted manually! Default: Abort on fopen() error |
-s <blocks> | Start position to begin reading. Corresponds 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. Assumes target file exists and has holes specified in badblockfile. Attempts to retrieve more data from listed blocks or beyond file size. Warning: Without this option, destination file will be emptied before writing. Use -I /dev/null to continue previous run without badblock list. Implies -c 0 if -c not specified. Default: none (/dev/null if -c is given) |
-i <bytes> | Blocksize to interpret badblockfile given with -I. Default: Blocksize as specified by -b |
-c <blocks> | Continue copying at this position. Useful if output is block device with fixed size. Blocksize used same as for -I. -c 0 continues at current destination size. Implies -I /dev/null if -I not specified. Default: none, 0 if -I specified |
-X <badblockfile> | Exclusion mode. Used with -I, excluded blocks override included blocks. Safecopy will not read/write data from excluded areas. Default: none (0 if -I given) |
-x <bytes> | Blocksize to interpret 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 (useful for tape devices etc.). Script must be executable taking number of blocks to skip (argv1), blocksize in bytes (argv2), current position in bytes (argv3). Return number of blocks skipped or 0 on failure. Used only if lseek() fails. Default: none |
-M <string> | Mark unrecovered data with this string instead of skipping it. Helps later find corrupted files on rescued filesystem images. Default is zero unreadable data on output file creation, and leave data as is on later runs. Warning: With incremental mode (-I) this may overwrite data in any block in the -I file, except those covered by -X. Default: none |
--debug <level> | Enable debug output. Level is bit field, add values: 1=program flow 2=IO control 4=badblock marking 8=seeking 16=incremental mode 32=exclude mode 255=all debug output Default: 0 |
-T <timingfile> | Write sector read timing info into this file for later analysis. Default: none |
Valid parameters for -f -r -b <size> options are:
<integer>: Amount in bytes - i.e. 1024<percentage>%: Percentage of whole file/device size - e.g. 10%<number>*:-bonly, number times blocksize reported by OS<number>*:-fand-ronly, number times the value of-b
Description of output:
.: Between 1 and 1024 blocks successfully read._: Read of block was incomplete. (possibly end of file). The blocksize is now reduced 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 retry attempt.[xx](+yy){: Current block and number of bytes continuously read successfully up to this point.X: 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 smaller blocksizes to search for the first readable data.}[xx](+yy): current block and number of bytes of recent continuous unreadable data.