Linux is a stable operating system. There is a rare strong operating system foundation. But critical errors have occurs rarely too. Or they may be some hardware-related problems. If your Linux system got down where your database resides what will happen? If you have a backup is not so big problem. We can simply recover from a backup. What if we have no backup?
Linux是稳定的操作系统。 有一个罕见的强大操作系统基础。 但是严重错误也很少发生。 或者它们可能是一些与硬件相关的问题。 如果您Linux系统崩溃了,数据库将驻留在哪里? 如果您有备份不是那么大的问题。 我们可以简单地从备份中恢复。 如果我们没有备份怎么办?
dd备份分区 (Backup Partition With dd)
dd
is a very useful tool. It is simple operation is convert and copy but this function can be used for different purposes like back up.
dd
是一个非常有用的工具。 转换和复制是简单的操作,但是此功能可用于不同目的,例如备份。
$ sudo dd if=/dev/vda1 of=/mnt/backup.dd
dd operation requires root privileges so we use sudo
dd操作需要root特权,因此我们使用sudo
if=/dev/vda1 is input file where vda disk first partition
if = / dev / vda1是输入文件,其中vda磁盘是第一个分区
of=/mnt/backup.dd is out output file where we create a new file named backup.dd
of = / mnt / backup.dd是输出文件,我们在其中创建一个名为backup.dd的新文件
This operation will take some time because the whole partition will be backed up.
此操作将花费一些时间,因为将备份整个分区。
带有dd的备份引导加载程序(MBR) (Backup Boot Loader (MBR) with dd)
We can back up our boot loader sectors easily with dd. As we know dd work in the raw mode so it only knows sectors and segments and Master Boot Records resides in the first 512 byte we can use dd. This backup can be useful if we will install Windows or other operating-system other partitions and do not want to lose our MBR
我们可以使用dd轻松备份引导加载程序扇区。 我们知道dd在原始模式下工作,因此它仅知道扇区和段,并且主引导记录位于前512个字节中,因此我们可以使用dd。 如果我们将安装Windows或其他操作系统的其他分区并且不想丢失MBR,则此备份很有用。
$ dd if=/dev/sda of=/mnt/mbr.bak bs=512 count=1
if=/dev/sda is disk where MBR resides
if = / dev / sda是MBR所在的磁盘
of=/mnt/mbr.bak is our backup file
of = / mnt / mbr.bak是我们的备份文件
bs=512 provides how many bytes will be read at once
bs = 512提供了一次读取多少字节
count=1 specifies how many time will the read operation is done
count = 1指定将执行多少次读取操作
With bs
and count parameter we want to read 512 bytes for one time
使用bs
和count参数,我们希望一次读取512个字节
We can recover our backup like below
我们可以像下面那样恢复备份
$ dd if=/mnt/mbr.bak of=/dev/vda bs=512 count=1
As you see we have changed the input and output files.
如您所见,我们已经更改了输入和输出文件。
一些技巧 (Some Tips)
To continue even copy operation has error we can provide conf=noerror parameter.
要继续进行复制操作甚至会出错,我们可以提供conf = noerror参数。
To sync without buffering data with dd sync operation can be used.
可以使用不带数据同步的dd同步操作进行同步。