0%

When we talk about BMR (Bare Metal Recovery), we are talking about a solution to recovery the operating system, the configurations and the documents. Distinguished from fileset backup and restore, BMR is usually used as the last resort for disaster recovery. This blog shows an feasible solution for BMR on Linux system.

I implemented a volume backup utility mentioned in the article before: VolumeBackup. This utility can perform full backup and forever increment backup to generate a volume copy with a *.img format, which can be used to perform block level recovery from. Actually, some free software providing mature BMR solution, e.g., CloneZilla, peforms BMR via cloning full partition or even full disk. Block-level backup is much faster than file-level backup, thus proven to be an effective way for BMR.

阅读全文 »

虽然基于卷做的备份/恢复有较大局限性:对于文件系统使用率比较低的场景使用卷备份会导致副本存储空间利用率低,而备份的文件普遍比较大的场景下使用文件级备份也能获取不错的性能且能高效使用存储空间,但卷备份在特定场景下也有不小的优势:卷备份主机硬盘取证的领域都是常见的业务,通过备份整卷可以获得很高的备份/恢复速度,备份系统卷可以直接恢复操作系统。本文从介绍卷的基本概念出发,总结Windows/Linux平台下卷备份恢复及后续副本数据利用的几种方案。笔者基于本文提到的技术方案,自己实现了一套卷备份工具,实现了对于Windows/Linux下卷的全量备份和永久增量备份、卷副本的恢复以及卷副本的及时挂载。源码见:https://github.com/XUranus/VolumeBackup,本文可看作该项目的文档。

卷、分区、磁盘的基本概念

在开始描述卷的备份/恢复逻辑之前,先介绍一下什么是卷,因为卷(Volume)、分区(Partition)以及硬盘(Hard disk)是一组常常被混淆的概念。硬盘是物理上的概念,常用的硬盘有机械硬盘(Hard Disk Drive)和固态硬盘(Solid State Disk)等,有关硬件本文则不做详述。卷和分区都是数据的存储区域,两者相似但不相同:卷是一个拥有单一文件系统的可访问的存储区域,分区是一个硬盘上划分出的一部分。这句话意思是,分区往往是一个具体的概念,存在于具体磁盘上的某一连续的具体区域,分区可以不带文件系统(通常没有被初始化的RAW分区也算分区)。卷则是一个抽象的概念,它必须和单一文件系统强关联,且一个卷可能存在于一个或多个磁盘中。由于卷是逻辑的概念,对于Linux/Windows操作系统会表现出差异性,而物理分区则是构成逻辑卷的基础,所以欲深入理解卷又得先从分区谈起。

阅读全文 »

Although volume-based backup/restore has significant limitations: using volume backup in scenarios with low file system utilization will result in low copy storage space utilization. In scenarios where the backed-up files are generally large, file-level backup can achieve good performance and efficiently use storage space. However, volume backup also has advantages in specific scenarios: it is common in the field of forensic examination of host hard disks based on volume backup. Backup of the entire volume can achieve high backup/restore speed, and the system volume backup can directly restore the operating system. This article starts by introducing the basic concepts of volumes, summarizing several solutions for volume backup, recovery, and subsequent utilization of copy data on the Windows/Linux platforms. Based on the technical solutions mentioned in this article, the author has implemented a set of volume backup tools, achieving full backup and permanent incremental backup of volumes under Windows/Linux, as well as recovery and timely mounting of volume copies. The source code can be found at: https://github.com/XUranus/VolumeBackup, and this article can be considered as documentation for this project.

Basic Concepts of Volumes, Partitions, and Disks

Before describing the logic of volume backup/restore, let’s first introduce what a volume is because volume (Volume), partition (Partition), and hard disk (Hard disk) are often confused concepts. The hard disk is a physical concept, with commonly used hard disks such as Hard Disk Drive (HDD) and Solid State Disk (SSD), but this article does not go into detail about hardware. Volumes and partitions are both storage areas for data, similar but not the same: a volume is an accessible storage area with a single file system, and a partition is a part of a hard disk partitioned out. This means that a partition is often a specific concept, existing in a continuous specific area on a specific disk. A partition may not have a file system (typically an uninitialized RAW partition is also considered a partition). A volume, on the other hand, is an abstract concept that must be strongly associated with a single file system, and a volume may exist on one or more disks. Since a volume is a logical concept, it exhibits differences for Linux/Windows operating systems, and physical partitions are the basis for forming logical volumes, so to understand volumes deeply, we need to start with partitions.

阅读全文 »

函数式编程(Functional Programming)是一种将计算当成数学函数,并避免数据可变状态的编程范式(Programming Paradigm)。C++是一门多范式语言(Multi-paradigm)所以也对FP有一定程度的支持。本文将简述一些C++中FP的常见写法。

lambda表达式

C++11开始引入了lambda表达式:支持代码中使用使用匿名函数。本着FP中函数也是一等公民的原则,匿名函数也可以成为函数参数、被传递或者被返回。

常见的std::for_each写法:

std::vector<int> numbers = {1, 2, 3, 4, 5};
std::for_each(numbers.begin(), numbers.end(), [](int num) {
std::cout << num * 2 << " ";
});

std::function

在C中传递函数往往需要声明函数指针,函数指针一般用于在异步场景中被注册为回调函数。C++中可以使用一种通用的多态函数封装结构std::function来存储、拷贝、调用一个可被调用的结构 (lambda, 函数指针, 或函数)。使用函数式相关的功能往往需要引入<functional>头文件。例:

阅读全文 »