Use Dump and Restore for Linux Backup

I have always been a proponent of using the proper backup tool for the each problem. In Linux, you have many, many options from cp, rsync, tar, cpio, dd, gzip, etc… and each has its place, benefits, and drawbacks. Coming a bit from an old school, I learned about the dump command ages ago. The “dump” will archive all of your files together into a single file like tar, but it also gives you a very simple way to recover individual files more surgically than the other options do. This article is an example of how to use Dump and Restore for Linux Backup and we will specifically use the “dump” and “restore” commands to backup and recover files from a CentOS machine.

Example of Linux Dump Command

In this example, I have a local directory named “mydirectory” which is storing 99 individual files.

$ pwd
/home/jstaten/mydirectory
$ ls
file1   file20  file31  file42  file53  file64  file75  file86  file97
file10  file21  file32  file43  file54  file65  file76  file87  file98
file11  file22  file33  file44  file55  file66  file77  file88  file99
file12  file23  file34  file45  file56  file67  file78  file89
file13  file24  file35  file46  file57  file68  file79  file9
file14  file25  file36  file47  file58  file69  file8   file90
file15  file26  file37  file48  file59  file7   file80  file91
file16  file27  file38  file49  file6   file70  file81  file92
file17  file28  file39  file5   file60  file71  file82  file93
file18  file29  file4   file50  file61  file72  file83  file94
file19  file3   file40  file51  file62  file73  file84  file95
file2   file30  file41  file52  file63  file74  file85  file96

Because dump is a lower-level backup that requires access to the filesystem block devices, you need to have sudo privileges to perform a dump.  There are many options that you can use with dump.  The number specifies the dump level.  A dump level 0 means backup everything.  The “-a” option is for “auto-size”.  This option is from the old days when one would normally be writing to tape and would specify the length of the tape so that dump would span multipe tapes.  In this example, we are dumping to a local file and are not worried about the dump taking up too much space.  We will use the “-a” option.  Finally, the -f option specifies the location where the dump file will be written.

$ sudo /sbin/dump -0a -f $HOME/mydirectory.dump mydirectory
DUMP: Date of this level 0 dump: Fri Nov  1 16:13:35 2013
DUMP: Dumping /dev/vda (/ (dir home/mary/mydirectory)) to /home/mary/mydirectory.dump
DUMP: Label: none
DUMP: Writing 10 Kilobyte records
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 855 blocks.
DUMP: Volume 1 started with block 1 at: Fri Nov  1 16:13:35 2013
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing /home/jstaten/mydirectory.dump
DUMP: Volume 1 completed at: Fri Nov  1 16:13:35 2013
DUMP: Volume 1 840 blocks (0.82MB)
DUMP: 840 blocks (0.82MB) on 1 volume(s)
DUMP: finished in less than a second
DUMP: Date of this level 0 dump: Fri Nov  1 16:13:35 2013
DUMP: Date this dump completed:  Fri Nov  1 16:13:35 2013
DUMP: Average transfer rate: 0 kB/s
DUMP: DUMP IS DONE

$ ls -l /home/mary/mydirectory.dump
-rw-r–r– 1 root root 860160 Nov  1 16:13 /home/mary/mydirectory.dump

I could now easily rsync, scp or copy this file off to another location.  In this case, I will be recovering lost files.

Suddenly, I am missing all of my file5* files!

$ rm -f file5*

I now need to recover them!

Example of Linux Restore Command

There are lots of options for the restore command and I don’t have time to do them all justice, but we will still recover our files.  We will be using the interactive restore option for this example.In an interactive restore, cd, ls, and pwd will help you maneuver, list files and see where you are at.The Big GotchaThe Big Gotcha is that it will want to restore to the path that was dumped.  As the restore point is relative to your location (see “pwd”).  In my case, I want to be in the / filesystem so that it will restore to /home/mary/mydirectory instead of to /home/mary/home/mary/mydirectory.I will use 2 options with the “restore” command below.  “-i” is for interactive and “-f” specifies the next parameter as the dump file to recover from.

$ pwd
/
$ /sbin/restore -i -f /home/mary/mydirectory.dump
/sbin/restore > pwd
/
/sbin/restore > cd /home/mary/mydirectory/
/sbin/restore > ls file5*
file5
file50
file51
file52
file53
file54
file55
file56
file57
file58
file59

It looks like my deleted files are available for recovery from the mydirectory.dump file that we made earlier.Use the “add” command to add files to restore. Use the extract command to recover the files. It will ask for a volume number –type 1. It will ask to set owner/mode, type “n”.

/sbin/restore > add file5*
/sbin/restore: ./home: File exists
/sbin/restore: ./home/mary: File exists
/sbin/restore: ./home/mary/mydirectory: File exists
/sbin/restore > ls file5*
*file5
*file50
*file51
*file52
*file53
*file54
*file55
*file56
*file57
*file58
*file59

I received the “file exists” messages above because the directories still existed.  The “add” option added the “*” to the files to mark them as being files that will be restored.Now, we are ready to recover (or “extract” rather) the files!

/sbin/restore > extract
You have not read any volumes yet.
Unless you know which volume your file(s) are on you should start
with the last volume and work towards the first.
Specify next volume # (none if no more volumes): 1
set owner/mode for ‘.’? [yn] n
/sbin/restore > quit$ ls /home/mary/mydirectory/file5*
/home/mary/mydirectory/file5   /home/mary/mydirectory/file55
/home/mary/mydirectory/file50  /home/mary/mydirectory/file56
/home/mary/mydirectory/file51  /home/mary/mydirectory/file57
/home/mary/mydirectory/file52  /home/mary/mydirectory/file58
/home/mary/mydirectory/file53  /home/mary/mydirectory/file59
/home/mary/mydirectory/file54

As you can see above, our file5* files are all recovered.  You can see from this example how simple it is to surgically recover individual files when using the “dump” and “restore” commands in linux.

 

Use Linux Dump and Restore Commands for Linux Backups

Use Linux Dump and Restore Commands for Linux Backups

The following two tabs change content below.
Jeff has 20 years of professional IT experience, having done nearly everything in his roles of IT consultant, Systems Integrator, Systems Engineer, CNOC Engineer, Systems Administrator, Network Systems Administrator, and IT Director. If there is one thing he knows for sure, it is that there is always a simple answer to every IT problem and that downtime begins with complexity. Seasoned IT professional by day, Jeff hopes to help other IT professionals by blogging about his experiences at night on his blog: http://uptimemadeeasy.com. You can find Jeff on or LinkedIn at: LinkedIn or Twitter at: Twitter

Latest posts by Jeff Staten (see all)

3 comments for “Use Dump and Restore for Linux Backup

  1. krishna
    September 15, 2014 at 2:56 am

    Dear sir,

    Thanks for sharing this article.

    could you please inform to me
    what is different beetween tar and dump backups?

    Thanks.
    krishna

  2. September 16, 2014 at 8:38 pm

    Krishna,
    Tar and dump are just 2 different ways to do the same task. With Dump, it is easier to interactively restore individual files. With tar, it is easier for simple directory backup, movement and untag. To really understand each, you will want to try them each out a couple times to get it.
    Jeff

  3. ahmed ali
    March 14, 2017 at 1:29 am

    thankyou so match
    tis very nice topic

Leave a Reply

Your email address will not be published. Required fields are marked *