Advertisement
v1ral_ITS

data recovery [terminal]

Jun 28th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.14 KB | None | 0 0
  1.  
  2. Get Your Data Back with Linux-Based Data Recovery Tools
  3.  
  4. Data is the crucial bit in our personal and professional existence. Without data we would be lost in a vast expanse of nothingness. Spreadsheets, email, documents, contacts, databases, files, folders … the list goes on and on. In a perfect world, every byte of local storage would be backed up to an external hard drive or cloud storage service.
  5.  
  6. We don’t always live in a perfect world.
  7.  
  8. Sometimes data has to be recovered. When that tragedy strikes, it’s good to know you have the tools on hand to get the job done. Thankfully, Linux is no stranger to data recovery. In fact, there are a number of solid tools you can use to get back lost data. I want to introduce you to a few tools that do a great job of recovering data.
  9.  
  10. Of course, as with any instance of recovering lost data ─ nothing is perfect. You can try any of the various tools available only to find the data simply not recoverable. That is the nature of the digital age. To that end, always make sure you have a solid, recent backup available in the event your system goes down hard.
  11. SystemRescueCD
  12.  
  13. Let’s first start with tools to help you recover data from a downed machine (say a machine with file system or partition issues). These tend to be the easiest to work with as they are all-inclusive tools. My favorite of these tools is SystemRescueCD. This particular rescue CD supports most of the known partition formats and includes all the tools you need to recover data (including sfdisk, Gparted, TestDisk, PhotoRec, FSArchiver, and much more) and includes plenty of tools to work with.
  14.  
  15. Like most rescue disks, SystemRescueCD works by booting your system from either the CD or USB drive and then uses the tools to work with your file system. Unlike a lot of other rescue tools of this nature, SystemRescueCD offers a full-blown graphical environment to aid you in the task of recovering data (Figure 1).
  16.  
  17.  systemrescuecd
  18.  
  19. If you are rescuing data from one machine to another, you will need to attach an external hard drive to the system in order to move the rescued data (or you can use the built-in Samba support and copy data to a networked location). If the idea is to recover or repair a partition table, I strongly suggest copying sensitive data over over anyway ─ on the chance the partition table or file system is further damaged.
  20.  
  21. There are other rescue systems available that are similar in both intent and style as SystemRescueCD. Each has its pros and cons but, in the end, will get the job done. Some of my favorite Linux data/system recovery distributions include:
  22.  
  23.     Trinity Rescue Kit
  24.  
  25.     Knoppix
  26.  
  27.     Ultimate Boot CD.
  28.  
  29. Individual rescue tools
  30.  
  31. Once you get beyond a full-blown distribution, you start looking at purpose-driven tools geared toward recovering data. Linux has just about any tool you need for this task. Let’s take a look at some of them.
  32.  
  33. Ddrescue
  34.  
  35. If you’re looking for the command line tool that will copy data from one file or block device to another, it’s Ddrescue that you need. There are a few things you should know about using the Ddrescue:
  36.  
  37.     Never use this tool on a read/write mounted drive or partition.
  38.  
  39.     Do not try to repair a file system with I/O errors.
  40.  
  41.     Destination will be overwritten ─ so make sure destination is free of important data.
  42.  
  43. This tool is great for recovering data from a failing drive to an external source. You would first need to install the tool on your working system, attach both the failing drive and a destination drive, via USB, and use the tool to extract the necessary data.
  44.  
  45. Installing the tool on an Ubuntu system can be done with a single command:
  46.  
  47. sudo apt-get install gddrescue
  48.  
  49. The command structure of Ddrescue is:
  50.  
  51. ddrescue [options] infile outfile [logfile]
  52.  
  53. Let’s use Ddrescue to copy a partition from drive /dev/sdg to drive /dev/sdb. The command (run on a system that works with sudo) would look like:
  54.  
  55. sudo ddrescue /dev/sdg /dev/sdb
  56.  
  57. The above command would copy everything from the failing source to the healthy target. Data recovered!
  58.  
  59. Testdisk
  60.  
  61. This particular data recovery tool doesn’t actually try to copy data. Instead it attempts to correct partition-level issues that might be preventing you from accessing or recovering your data. Testdisk can:
  62.  
  63.     Recover lost partitions
  64.  
  65.     Make disks bootable again
  66.  
  67.     Fix a partition table
  68.  
  69.     Restore the master boot record
  70.  
  71.     Restore boot sectors
  72.  
  73.     Restore filesystem tables
  74.  
  75.     Undelete files from NTFS, FAT, exFAT, and ext2 filesystems
  76.  
  77.     Copy files from deleted NTFS, FAT, exFAT, and ext2/3/4 filesystems.
  78.  
  79. Testdisk is an ncurses tool that runs within a terminal (Figure 2).
  80.  
  81. testdisk
  82.  
  83. To install Testdisk on an Ubuntu system, issue the command:
  84.  
  85. sudo apt-get install testdisk
  86.  
  87. Run the tool with sudo testdisk and walk through the easy-to-use wizard for working with your externally attached drive.
  88.  
  89. Photorec
  90.  
  91. If you’re looking to recover lost files, photos, videos, etc. Photorec is what you want. This tool is part of Testdisk, so once you’ve installed Testdisk, Photorec is ready to serve. This particular tool completely ignores the file system and looks directly at the underlying data. This means, if your file system is damaged, there’s a chance the data can still be recovered.
  92.  
  93. To start Photorec, issue the command:
  94.  
  95. sudo photorec
  96.  
  97. The interface for Photorec is similar to that of Testdisk. As Photorec works, it will display, in real time, what types of files it has recovered (Figure 3).
  98.  
  99. photorec
  100.  
  101. You do want to make sure the destination partition has enough space to contain the rescued data (you can copy the data to internal storage or external storage).
  102.  
  103. If you are looking for tools to help you recover data on a Linux system, there are plenty to be had. This post offers you a look into what is available for admins to use ─ from full-blown disk recovery suites to individual tools. There are plenty of other tools ready to aid you in your quest to recover data.
  104.  
  105. For more information on such tools, check out the Linux.com System Management Forum, where you can interact with your peers and learn even more about data recovery.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement