Use Dump and Restore for Linux Backup


http://www.uptimemadeeasy.com/disaster-planning/dump-and-restore-for-linux-backup/


apt-get install dump


dump -0uan -f my_file /


Boot from your Ubuntu live CD/DVD/USB.


Install the dump utility.


Mount your hard drive.


cd /


Restore (i.e. restore -r -f my_file /my_mount).


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 > quitls /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.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值