Dd backup and recovery

Source: Internet
Author: User

The Linux/Unix dd command is a good disk management command.

Dd command: a block of the specified size copies a file and converts the file at the same time to initialize the disk.


Explanation of DD Command Options

If = file --> input file name. The default value is standard input.

Of = file --> output file name. The default value is standard output.

IBS = bytes --> Read bytes at a time (that is, the size of a block is bytes)

Obs = bytes --> write bytes at a time (that is, the size of a block is bytes)

BS = bytes --> set the size of the read/write block to bytes, which can replace IBS and obs.

CBS = bytes --> converts bytes at a time, that is, the size of the conversion buffer.

Skip = blocks --> the blocks are skipped from the beginning of the input file and then copied.

Seek = blocks --> skip blocks from the beginning of the output file and then start copying. (Usually only valid when the output file is a disk or tape)

Count = blocks --> copy only blocks. The block size is equal to the number of bytes specified by IBS.

Conv = Conversion [, conversion...] --> convert the file with the specified parameter

ASCII --> convert ebcdic to ASCII

Ebcdic --> convert ASCII to ebcdic

IBM --> convert ASCII to alternate ebcdic

Block --> converts each row to a record with the length of CBS. The insufficient part is filled with spaces.

Unblock --> make each row have a length of CBS, and fill the deficiencies with spaces

Lcase --> converts uppercase to lowercase.

Ucase --> converts lowercase to uppercase.

Swab --> swap each pair of bytes

Noerror --> do not stop when an error occurs

Notrunc --> not truncating the output file

Sync --> Fill each input block into IBS bytes, and fill up the remaining parts with null (NUL) characters

Note: If the following column ends with a specified number, multiply it by the corresponding number: B = 512, c = 1, K = 1024, W = 2, XM = Number m, KB = 1000, K = 1024, MB = 1000*1000, M = 1024*1024, GB = 1000*1000*1000, G = 1024*1024*1024

========================================================== ========================================================== ========================

Create a file-based sswap partition:

A. dd If =/dev/Zero of =/project/swapfile BS = 1024 COUNT = 500000 => Generate a 5g file through the zero File

B. mkswap/project/swapfile => makes file usable for swapping generate the swap partition File

C. Swapon/project/swapfile => enables swapping to make swap partition take effect

D. swapoff/project/swapfile => disable the specified swap partition.

E. swapoff-A => disables all swapping for entries listed in:/etc/fstab disable swap partitions in all fstab instances.

========================================================== ========================================================== ========================

Backup:

[Root @ server ~] #Dd If =/dev/SDA of =/dev/SDB
=> Back up the entire disk to another disk

[Root @ server ~] #Dd If =/dev/SDB of = SDA. Bak =>Back up the entire disk as a file

[Root @ server ~] #Dd If =/dev/SDA | gzip> sda.bak.gz =>Back up and compress

[Root @ server ~] #Dd If =/dev/sdaof = DBT. Bak COUNT = 1 bs = 512 skip = 446

=>Skips the last 66 bytes of DPT information from the first 446 bytes of the backup disk to the specified file.


========================================================== ========================================================== ========================

Recovery:

[Root @ server ~] #Dd If =/dev/SDB of =/dev/SDA

[Root @ server ~] #Gzip-DC sda.bak.gz | dd OF =/dev/SDA

[Root @ server ~] # Dd If =/path/to/image of =/dev/hdx COUNT = 1 bs = 512 seek = 446
=> Write the backup DPT information to 66 bytes after MBR

========================================================== ========================================================== ========================


Destroy data:

[Root @ server ~] #Dd If =/dev/urandom of =/dev/sda1 =>Use random numbers to fill hard disk data to destroy data.

 

Compare the command execution time displayed in the DD command output (select the least time) to determine the optimal Block Size of the system.

Note: The disk must be mounted with the-O sync option. Otherwise, data will be written to the cache instead of the disk, leading to inaccurate testing.
Dd If =/dev/Zero BS = 1024 COUNT = 1000000 of =/root/1gb. File
Dd If =/dev/Zero BS = 2048 COUNT = 500000 of =/root/1gb. File
Dd If =/dev/Zero BS = 4096 COUNT = 250000 of =/root/1gb. File
Dd If =/dev/Zero BS = 8192 COUNT = 125000 of =/root/1gb. File

 

Test read/write speed

Note: The disk must be mounted with the-O sync option. Otherwise, data will be written to the cache instead of the disk, leading to inaccurate testing.
[Root @ server ~] #Mount-O sync, remount/

[Root @ server ~] #Mount | grep sync

/Dev/sda2 on/type ext4 (RW, sync)

[Root @ server ~] #Dd If =/dev/Zero of =/tmp/test. dd BS = 4096 COUNT = 5000 => test write speed

[Root @ server ~] #Dd If =/tmp/test. dd OF =/dev/null BS = 4096 COUNT = 5000 => read Test

========================================================== ========================================================== ========================

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.