Use dump for backup and restore under Linux for backup and restore under UX

Source: Internet
Author: User
Tags rewind

For the system, we can have a lot of ways to back up (restore) the system or file, the reason is to do the backup, is to be in the system or file damage, the timely recovery, reduce the loss to a minimum. Of course, the importance of backup is important for enterprise servers. Let's discuss in detail today how to use dump and restore for backup and restoration in Linux.

One, the principle of dump, advantages and limitations

The dump and restore defaults are already installed in RHEL5, and if you're not using Linux, you can go to Google and download the installation yourself.

When you use the dump command, it creates a list of files that have been modified since the last backup operation, and then packages the files into a separate file. When doing a backup, you need to specify a backup level, which is an integer between 0-9. A dump of level n backs up all files that have been modified since the last dump operation with a level less than N, and level 0 is a full backup. In this way, you can easily implement incremental backups, differential backups, and even daily backups. For example, you can select level 0 for the first backup (see later), and you can use level 1, Level 2, Level 3, and so on every day to make incremental backups every day ... When you need to do a differential backup every day, you can choose level 0 to do a full backup, and then every day use the same level greater than 0, such as the next day with 5, the third day with 5, the fourth day is also the same.

Advantages of using Dump:

1, backups can span multiple volumes of tape

2, can back up any type of file, even the device

3, Backup, file permissions, hosts, host groups, modification time, etc. will be saved

4, the ability to correctly handle file blocks (hole files) that never contain any data

5, can do incremental, differential backup

It also has deficiencies:

1, each file system must be separately transferred to the reserve part

2, only the local computer's file system can be transferred to the reserve (Rdump,rrestore can be used to compensate for this deficiency)

Of course, using tar can also be used for backup and restore, but tar can only be used in Linux or UNIX environments, and for cross-platform environments, dump is more comfortable to use personally.

If there is a condition, dump can also store the backup on tape. Linux typically uses/DEV/ST0 to represent a rewind device, while a/dev/nst0 represents a non-rewind device that, when used with a rewind device, is automatically rewind and then stored when the tape is exhausted, overwriting the previous data so that there is a risk of previous data loss. We will not discuss this place in detail.

Two, dump format, common parameters and use

Format: Dump [-level#] [-ACMMNQSUV] [-A file] [-B Records] [-B blocksize]

[-D density] [-D file] [-e inode#,inode#,...] [-E File]

[-F file] [-H level] [-I NR errors] [-j Zlevel] [-Q file]

[-S feet] [-T Date] [-y] [-Z Zlevel] FileSystem

Common parameters Level: backup Levels 0-9

-B: Specifies the length of the tape to be backed up, in kilobytes (some tapes do not support the use of this parameter when judging by the end flag

-B: Specifies the block size, which defaults to 10

-D: Specify density, default is 1600BPI

-D: Sets the name and path of the storage database, default is/etc/dumpdates file

(-e,-e: Parameters related to the number of inodes of the backup file)

-F: Specify the path and name of the backup file

-U: Update database file/etc/dumpdates

-S: Statistics the space required for backups, typically done before backup, in case of insufficient tape or disk space

Example:

Dump–0s/dev/sda1

Full backup before/dev/sda1 count how much capacity you need

Dump-0u–f/tmp/boot.dump/boot

Back up the/boot partition to file/tmp/boot.dump as a full backup, and update the/etc/dumpdates database file. "0" represents the backup level as a full backup. "U" updates the database, which records information such as the date, storage level, file system, and so on. If you never use the-u parameter, all storage becomes level 0. Because the system does not have a record that previously backed up the current file system.

When you change the/boot later, such as after the kernel upgrade, if you want to back up again, you can do the following:

Dump-1u–f/tmp/boot1.dump/boot

This will only back up files that have changed after a full backup (level 1 is greater than 0).

If you want to do an incremental backup later, then use the level 2,3,4 ...

If you want to make a differential backup, always use Level 1. The difference between incremental and differential backups look, not in detail:

Third, view the files in the backup document and restore

Viewing files and restores in a backup document requires another tool, restore.

1. View the files in the backup document

The-t parameter is meant to be viewed, and-F is the specified backup file to view. With the above command, you can view which files are backed up in the backup file.

1. Restore Backup

There are two ways to restore a backup, one is a full restore, and the other is a selective partial restore.

Let's take a look at the previous example, if you have a damaged/boot partition file in front of you, and you want to restore it, you can follow these steps:

-R parameter indicates rebuild

If only a portion of the data is lost, then you can use the parameter-I interactively to achieve a selective restore of the file

This place I deliberately deleted a file initrd-2.6.18-53.el5.img

Use the parameter-I interactive and specify the backup file.

Pass? To view the commands you can use, LS is the contents of the backup file listed

Select the file to be recovered by add and mark it as * when the LS is selected

Restores the selected file by extract.

When prompted with "specify next volume" As 1, it means a backup on a single volume of tape (where I'm using disk space). The following line prompts you to select "n" to indicate that you are not restoring the entire file system, but rather a single file.

For an example of incremental backup on a Linux system

1. Dump/restore Incremental backup Note that this method only takes the entire partition backup

# Mount/dev/sdb1/mnt/sdb A new hard drive to mount it to/mnt/sdb
# LS/MNT/SDB
123 456 Aaa.zip F1
There are 4 files in the F1 directory.

The original image can now be backed up

#Dump-0u/dev/sdb1-f/backup/sdb1_0u_110210.dump
Dump:date of this level 0 Dump:thu Feb 10 23:21:40 2011
DUMP:DUMPING/DEV/SDB1 (/MNT/SDB) to/backup/sdb_0u_110210.dump
DUMP:Label:none
..... Middle omitted
Dump:average Transfer rate:5687 kb/s
Dump:dump is done
Backup complete

dump-0u: 0 for mirrored backup (full backup) 1-9 represents an incremental backup based on the previous level, respectively

The following incremental backup:
First delete the 123 file, add a file KKK and enter Hello man!

[[email protected] sdb]# ls
456 Aaa.zip F1 KKK
To start an incremental backup:
[email protected] sdb]# dump-1u/dev/sdb1-f/backup/sdb1_1u_110210.dump
Dump:average Transfer rate:0 kb/s
Dump:dump is done
Now there are two backups under the/backup.

[email protected] sdb]# Ls/backup
Sdb1_0u_110210.dump Sdb1_1u_110210.dump

In order to better understand we are adding a backup, back up before we change the files in the following partition
Modified 456 content for 456 modifiy Delete Aaa.zip
[[email protected] sdb]# ls
456 F1 KKK

Back up the second increment, here with 3u as long as it is larger than the previous, the recommended backup is 2u 4u 6u such a backup, or you all the numbers are used, 123456 if you want to re-2u on the basis of the backup is not possible, because 3 has been used, you can only back up in 6
[email protected] sdb]# dump-3u/dev/sdb1-f/backup/sdb1_3u_110210.dump

After the backup is complete, delete all the records inside.
And then start recovering now.
[[email protected] sdb]# restore-r-f/backup/sdb1_0u_110210.dump first restore 0u
[[email protected] sdb]# ls
123 456 Aaa.zip F1 restoresymtable
This time the first backup is restored, and then a restore
# restore-r-f/backup/sdb1_1u_110210.dump
# restore-r-f/backup/sdb1_3u_110210.dump
# ls
456 F1 KKK restoresymtable
Same as the last backup.

View the contents of the backup image
# restore-t-f/backup/sdb1_1u_110210.dump
Dump Date:thu Feb 10 23:28:38 2011
Dumped From:thu Feb 10 23:21:40 2011
Level 1 dump OF/MNT/SDB on MYSQL1.DOG.COM:/DEV/SDB1
Label:none
2.
/kkk.

extract the files in the image
[Email protected] sdb]# Restore-if/backup/sdb1_3u_110210.dump
Restore > ls
.:
3 f1/lost+found/restoresymtable
456 KKK NewFile

Restore > Add KKK
Restore > Extract
You haven't read any volumes yet.
Unless you know which volume your file (s) is 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
Restore > Quit

About the scenario for regular backups:
Make a full backup first
#dump-0u/dev/sdb1-f/backup/sdb1_0u_110210.dump
Monday: #dump-2u/dev/sdb1-f/backup/sdb1_1u_110210.dump
Tuesday:
#dump-2u/dev/sdb1-f/backup/sdb1_2u_110210.dump
Wednesday:#dump-2u/dev/sdb1-f/backup/sdb1_3u_110210.dump
。。。。。

----------------------------------------------------------------------------------------------------------- ---------
The following method is more flexible, directly with the tar backup

# CD/TEST/T1
# ls
Aaa.zip file1 file2 File3
There are three files
Perform a full backup first
# tar-g SNAPSHOT-ZCF backupp_full.tar.gz/test/t1
Then modify the file to add a file
To make an incremental backup:
# tar-g SNAPSHOT-ZCF backupp_incremental_1.tar.gz/test/t1
Modify
Incremental backup again
# tar-g SNAPSHOT-ZCF backupp_incremental_2.tar.gz/test/t1

Restores
Tar zxf backup_full.tar.gz-c/
Tar zxf backup_incremental_1.tar.gz-c/
Tar zxf backup_incremental_2.tar.gz-c/
Note that the modified files are subject to the incremental backup, the deleted files are not deleted, and the deleted files are restored when they are restored.

Another tar backup uses the-u parameter for incremental backups, and the deleted files are not synchronized

Backup data
Tar zcf backup.tar/test/t1

View Content
Tar ztf Backup.tar
File1 file2 File3

Add a file under/test/t1

Incremental backup
Tar uf backup.tar/test/t1

Restoring a backup is actually a direct decompression.
Tar zxf Backup.tar

If you need to compress an incremental backup, you need to unzip the original and then back it up in compression (the-u parameter is not automatically compressed)
Gunzip backup.tar.gz
Tar uf backup.tar test
Gzip Backup.tar

1, the dump command can be used to back up the file system in ext2 and ext3 formats, that is, you can back up the entire partition.
Brief parameter Description:
level# Usually when backed up with the dump command, the -0~-9 parameter is added, "0" full backup, " -1~-9" incremental backup (only the files that were changed after the last backup are backed up, and only the numbers that are smaller than the current backup number);
The following results The backup order is "0, 1, 2"


But it is usually not backed up using the method above, but instead is backed up in the order of "0, 2, 1";


-F: Can be used to specify where the backed up files are stored; Example: dump–f/dev/st0 Backup to tape;
-U: each time the dump command is executed, the level number of the backup is logged to the/etc/dumpdates file, which is the corresponding dump level number is updated to the/etc/dumpdates file each time the dump command is executed;
Example:
(1) dump–0–u–f ~/backup  /dev/sda1    Backup SDA1 partition the home directory in the backup file, and update/etc/dumpdates the current backup Level number to this file;
14. Use the Cpio command to back up the files
1, the Cpio command to unzip a packaged file or copy the file to a packaged file.
Common parameter description (you can use the man cpio command to view detailed instructions):
–d   can be used to create a directory;
–i    unzip;
–o   to package the files
–t   Lists the contents of the packaged file;
Note: When Cpio unzip a file, you must extract it to a directory that does not have the original file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.