dd命令备份linux系统_Linux dd命令备份示例

dd命令备份linux系统

dd命令备份linux系统

Backup is important part of the Linux system administration. Without backups a system is not safe and also the system administrator position too 🙂 . There are different ways to take backup. Some tools provides user level backup operation like copying or sync files. Other backup tools provides more file system level backup operation. One part of the Linux operating system is low level. Simply it has a lot of low level applications those helps system administrators. In this tutorial we will look dd command or tool which can do low level raw disk operations.

备份是Linux系统管理的重要组成部分。 如果没有备份,系统将是不安全的,系统管理员的职位也将🙂。 有多种备份方法。 一些工具提供了用户级别的备份操作,例如复制或同步文件。 其他备份工具提供了更多的文件系统级别的备份操作。 Linux操作系统的一部分是低级的。 只是它具有许多可帮助系统管理员的低级应用程序。 在本教程中,我们将介绍可以执行低级原始磁盘操作的dd命令或工具。

警告 (Warning)

First of all dd command is low level command and use cautiously. While providing disk and partitions parameters use fdisk command to get disks path. Check twice before running command. You can find fdisk command tutorial below.

首先dd命令是低级命令,请谨慎使用。 提供磁盘和分区参数时,请使用fdisk命令获取磁盘路径。 运行命令前请检查两次。 您可以在下面找到fdisk命令教程。

Linux fdisk Tutorial With Examples

Linux fdisk教程示例

复制/备份整个硬盘(Copy/Backup Entire Hard Disk)

As we know Linux operating system provides raw access to the disk and partitions. These disks and partitions are provided in /dev/ path. So in order to use dd we will provide exact disk and partition file names. This operations also called as clone because a single is copied as a whole into another disk without a modification.

众所周知,Linux操作系统提供对磁盘和分区的原始访问。 这些磁盘和分区位于/dev/路径中。 因此,为了使用dd我们将提供确切的磁盘和分区文件名。 此操作也称为克隆,因为单个文件无需修改就可以整体复制到另一个磁盘中。

In this example we will create backup of vda to the disk sda . Before starting backup or copy operations be sure that sda size is bigger than vda .

在此示例中,我们将创建vda备份到磁盘sda 。 在开始备份或复制操作之前,请确保sda大小大于vda

$ sudo dd if=/dev/vda of=/dev/sda
  • if provides the source hard disk

    if提供源硬盘

  • of provides the destination hard disk

    of提供目标硬盘

Copying operation duration can be changed according to write performance of the destination disk and read performance of source disk.

可以根据目标磁盘的写入性能和源磁盘的读取性能来更改复制操作的持续时间。

LEARN MORE  How To Use Cpio In Linux?
了解更多如何在Linux中使用Cpio?

设置字节大小 (Set Byte Size)

dd copy operations reads some bytes at a time and write to new disk. If we want to make operation faster and know that our disks are performative. We can change the a time copy size with bs parameter. bs size is provided by byte but following suffixes can be used too.

dd复制操作一次读取一些字节并写入新磁盘。 如果我们想使操作更快并且知道我们的磁盘具有性能。 我们可以使用bs参数更改时间复制大小。 bs大小由字节提供,但也可以使用以下后缀。

  • kB=1000 byte

    kB = 1000字节

  • K = 1024 byte

    K = 1024字节

  • MB = 1000 * 1000 byte

    MB = 1000 * 1000字节

  • M = 1024*1024 byte

    M = 1024 * 1024字节

  • GB = 1000*1000*1000 byte

    GB = 1000 * 1000 * 1000字节

  • G = 1024*1024*1024 byte

    G = 1024 * 1024 * 1024字节

In this example we will set the byte size as 5M for copy operation.

在此示例中,我们将字节大小设置为5M以进行复制操作。

$ sudo dd bs=5M if=/dev/vda of=/dev/sda

创建硬盘映像 (Create Hard Disk Image)

In previous examples we have copied the whole disk image into another disk. In most situations we generally use disk images for backup creation. We can write copied disk image as a file into another disk.

在前面的示例中,我们将整个磁盘映像复制到了另一个磁盘中。 在大多数情况下,我们通常使用磁盘映像进行备份创建。 我们可以将复制的磁盘映像作为文件写入另一个磁盘。

In this example we will create disk image as a file named sda.img into folder /mnt/backup/ which is mounted from other disk. Other or destination disk can be an NFS, DAS, NAS, SAN etc.

在此示例中,我们将磁盘映像作为名为sda.img的文件sda.img到文件夹/mnt/backup/ ,该文件夹是从其他磁盘装入的。 其他或目标磁盘可以是NFS,DAS,NAS,SAN等。

$ sudo dd if=/dev/vda  of=/mnt/backup/sda.img

创建软盘映像 (Create Floppy Image)

Once a time floppy images were very popular in IT. Event operation system was installed from Floppies and backing up them were important. Actually creating a floppy image is the same as disk image because all of the sources are same type.

曾经,软盘映像在IT中非常流行。 从软盘安装了事件操作系统,对其进行备份很重要。 实际上,创建软盘映像与磁盘映像相同,因为所有源都是同一类型。

In this example we assume the floppy device is named as fd0 and we will copy into ~/ home directory as floppy.img with the following command.

在此示例中,我们假设软盘设备名为fd0并使用以下命令将其作为floppy.img复制到~/主目录。

$ sudo dd if=/dev/fd0  of=~/floppy.img

复制/备份CDROM (Copy/Backup CDROM)

Another device popular used in Linux servers is CDROM. CDROM can provide data about Linux installation or other critical data. We can copy CDROM device too with dd command. But here we need to check one point. To make things without error we should unmount the CDROM if it is mounted.

在Linux服务器中流行的另一种设备是CDROM。 CDROM可以提供有关Linux安装的数据或其他关键数据。 我们也可以用dd命令复制CDROM设备。 但是这里我们需要检查一点。 为了使事情顺利进行,我们应该卸载已安装的CDROM。

LEARN MORE  Windows Performance Recorder (wpr) Command Tutorial with Examples To Record Performance Metrics
了解更多Windows Performance Recorder(wpr)命令教程,并带有记录性能指标的示例

In this example the cdrom device name is cdrom and the backup name is linux.iso .

在此示例中,cdrom设备名称为cdrom ,备份名称为linux.iso

$ sudo dd if=/dev/cdrom  of=~/linux.iso

复制/备份分区 (Copy/Backup A Partition)

Up to now we have copied who disks or devices. But generally we need to copy only a single partition of a hard disk. Actually there is no difference for copying disk partitions. Disk partitions generally named by numbering the partitions index and disk index. For example first partition of the disk named vda will vda0 and second partition will be named vda1 etc.

到目前为止,我们已经复制了谁的磁盘或设备。 但是通常我们只需要复制一个硬盘分区。 实际上,复制磁盘分区没有区别。 磁盘分区通常通过对分区索引和磁盘索引编号来命名。 例如,名为vda的磁盘的第一个分区将为vda0 ,第二个分区的名称vda1等。

In this example we will copy or backup the second partition of the disk vda to a file named back.img

在此示例中,我们将磁盘vda的第二个分区复制或备份到名为back.img的文件中

$ sudo dd if=/dev/vda1  of=/mnt/backup/back.img

重定向和压缩DD备份 (Redirect and Compress DD Backups)

While taking backups about the disk there will be a lot of data. This will make the size very big. There are different ways to lower the size of the backup image taken by dd command. What the dd command do is it reads from given source device and then we can compress the image before saving to a file.

在进行磁盘备份时,将会有很多数据。 这将使尺寸很大。 有多种方法可以减小dd命令获取的备用映像的大小。 dd命令的作用是从给定的源设备读取数据,然后我们可以在压缩图像之前将其保存到文件中。

In this example we will backup the device vda1 and save as back.img.gz . We will redirect dd output with | pipe to the gzip command.

在此示例中,我们将备份设备vda1并另存为back.img.gz 我们将用|重定向dd输出| 管道到gzip命令。

$ sudo dd if=/dev/vda1  | gzip /mnt/backup/back.img.gz

In this example we have used gzip but also use other compression formats and applications 7z , xz  , … as is.

在此示例中,我们使用了gzip,但也使用了其他压缩格式和应用程序7z,xz…。

用零填充硬盘 (Fill Hard Disk with Zeros)

dd provides low level operations. We can also write specified hard disk with a given data source. If we want to delete all data resides on the disk we can use dd too. In Linux operation systems devices named zero exists which is psedeu devices. This devices creates zeros as stream. In order to fill a hard disk device with zero we will read this devices and write the destination devices like below.

dd提供低级操作。 我们还可以使用给定的数据源写入指定的硬盘。 如果要删除磁盘上所有的数据,也可以使用dd 。 在Linux操作系统中,存在名为psedeu设备的名zero设备。 该设备将零创建为流。 为了用零填充硬盘设备,我们将读取该设备并写入目标设备,如下所示。

$ sudo dd if=/dev/zero  of=/dev/vda

用随机数据填充硬盘 (Fill Hard Disk with Random Data)

Filling whole disk with zero is an option. But there is also other option which is more secure. We can use random device of Linux operating system. This device will generate random numbers and we will write these into the destination hard disk or device.

可以用零填充整个磁盘。 但是,还有其他更安全的选择。 我们可以使用Linux操作系统的random设备。 该设备将生成随机数,我们会将其写入目标硬盘或设备。

LEARN MORE  Linux System Activity Reporter (SAR) Command Tutorial With Examples
了解更多Linux系统活动报告程序(SAR)命令教程及示例

In this example we will write random data device named vda.

在此示例中,我们将编写名为vda随机数据设备。

$ sudo dd if=/dev/random  of=/dev/vda

翻译自: https://www.poftut.com/linux-dd-command-backup-examples/

dd命令备份linux系统

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值