Linux系统备份工具 REAR (RELAX-AND-RECOVER)
LINUX系统备份工具 REAR
HTTP://RELAX-AND-RECOVER.ORG/DOWNLOAD/
HTTPS://ACCESS.REDHAT.COM/DOCUMENTATION/EN-US/RED_HAT_ENTERPRISE_LINUX/7/HTML/SYSTEM_ADMINISTRATORS_GUIDE/CH-RELAX-AND-RECOVER_REAR
CHAPTER 28. RELAX-AND-RECOVER (REAR)
-
booting a rescue system on the new hardware
-
replicating the original storage layout
-
restoring user and system files
rear recover
command, which starts the recovery process. During this process, ReaR replicates
the partition layout and filesystems, prompts for restoring user and system files from the backup created by backup software, and finally installs the boot loader. By default, the rescue system created by ReaR only restores the storage layout and the boot
loader, but not the actual user and system files.28.1. Basic ReaR Usage
28.1.1. Installing ReaR
~]# yum install rear genisoimage syslinux
28.1.2. Configuring ReaR
/etc/rear/local.conf
file.
Specify the rescue system configuration by adding these lines:OUTPUT=output format OUTPUT_URL=output location
ISO
for
an ISO disk image or USB
for a bootable USB.file:///mnt/rescue_system/
for
a local filesystem directory orsftp://backup:aaa@qq.com/
for an SFTP directory.Example 28.1. Configuring Rescue System Format and Location
/mnt/rescue_system/
directory,
add these lines to the /etc/rear/local.conf
file:OUTPUT=ISO OUTPUT_URL=file:///mnt/rescue_system/
ISO-specific Configuration
-
/var/lib/rear/output/
-rear
's default output location -
/mnt/rescue_system/HOSTNAME/rear-localhost.iso
- output location specified inOUTPUT_URL
/etc/rear/local.conf
:OUTPUT=ISO
BACKUP=NETFS
OUTPUT_URL=null
BACKUP_URL="iso:///backup"
ISO_DIR="output location"
28.1.3. Creating a Rescue System
~]# rear -v mkrescue
Relax-and-Recover 1.17.2 / Git
Using log file: /var/log/rear/rear-rhel7.log
mkdir: created directory '/var/lib/rear/output'
Creating disk layout
Creating root filesystem layout
TIP: To login as root via ssh you need to set up /root/.ssh/authorized_keys or SSH_ROOT_PASSWORD in your configuration file
Copying files and directories
Copying binaries and libraries
Copying kernel modules
Creating initramfs
Making ISO image
Wrote ISO image: /var/lib/rear/output/rear-rhel7.iso (124M)
Copying resulting files to file location
/mnt/rescue_system/
.
Because the system's host name is rhel7
, the backup location now contains directory rhel7/
with
the rescue system and auxiliary files:~]# ls -lh /mnt/rescue_system/rhel7/
total 124M
-rw-------. 1 root root 202 Jun 10 15:27 README
-rw-------. 1 root root 166K Jun 10 15:27 rear.log
-rw-------. 1 root root 124M Jun 10 15:27 rear-rhel7.iso
-rw-------. 1 root root 274 Jun 10 15:27 VERSION
28.1.4. Scheduling ReaR
/etc/crontab
file:minute hour day_of_month month day_of_week root /usr/sbin/rear mkrescue
Example 28.2. Scheduling ReaR
/etc/crontab
file:0 22 * * 1-5 root /usr/sbin/rear mkrescue
28.1.5. Performing a System Rescue
-
Boot the rescue system on the new hardware. For example, burn the ISO image to a DVD and boot from the DVD.
-
In the console interface, select the "Recover" option:
Figure 28.1. Rescue system: menu
-
You are taken to the prompt:
-
Figure 28.2. Rescue system: prompt
Warning
Once you have started recovery in the next step, it probably cannot be undone and you may lose anything stored on the physical disks of the system. -
Run the
rear recover
command to perform the restore or migration. The rescue system then recreates the partition layout and filesystems:Figure 28.3. Rescue system: running "rear recover"
-
Restore user and system files from the backup into the
/mnt/local/
directory.Example 28.3. Restoring User and System Files
In this example, the backup file is a tar archive created per instructions inSection 28.2.1.1, “Configuring the Internal Backup Method”. First, copy the archive from its storage, then unpack the files into/mnt/local/
, then delete the archive:~]#
scp aaa@qq.com:/srv/backup/rhel7/backup.tar.gz /mnt/local/
~]#tar xf /mnt/local/backup.tar.gz -C /mnt/local/
~]#rm -f /mnt/local/backup.tar.gz
The new storage has to have enough space both for the archive and the extracted files. -
Verify that the files have been restored:
~]#
ls /mnt/local/
Figure 28.4. Rescue system: restoring user and system files from the backup
-
Ensure that SELinux relabels the files on the next boot:
~]#
touch /mnt/local/.autorelabel
Otherwise you may be unable to log in the system, because the/etc/passwd
file may have the incorrect SELinux context. -
Finish the recovery by entering
exit
. ReaR will then reinstall the boot loader. After that, reboot the system:Figure 28.5. Rescue system: finishing recovery
Upon reboot, SELinux will relabel the whole filesystem. Then you will be able to log in to the recovered system.
-
28.2. INTEGRATING REAR WITH BACKUP SOFTWARE
28.2.1. The Built-in Backup Method
-
a rescue system and a full-system backup can be created using a single
rear mkbackup
command -
the rescue system restores files from the backup automatically
28.2.1.1. Configuring the Internal Backup Method
/etc/rear/local.conf
:BACKUP=NETFS
BACKUP_URL=backup location
tar
command.
Substitute backup location with one of the options from the "Backup Software Integration" section of the rear(8) man page. Make sure that the backup location has enough space.Example 28.4. Adding tar Backups
/srv/backup/
directory:OUTPUT=ISO OUTPUT_URL=file:///mnt/rescue_system/ BACKUP=NETFS BACKUP_URL=file:///srv/backup/
-
To keep old backup archives when new ones are created, add this line:
NETFS_KEEP_OLD_BACKUP_COPY=y
-
By default, ReaR creates a full backup on each run. To make the backups incremental, meaning that only the changed files are backed up on each run, add this line:
BACKUP_TYPE=incremental
This automatically setsNETFS_KEEP_OLD_BACKUP_COPY
toy
. -
To ensure that a full backup is done regularly in addition to incremental backups, add this line:
FULLBACKUPDAY="Day"
Substitute "Day" with one of the "Mon", "Tue", "Wed", "Thu". "Fri", "Sat", "Sun". -
ReaR can also include both the rescue system and the backup in the ISO image. To achieve this, set the
BACKUP_URL
directive toiso:///backup/
:BACKUP_URL=iso:///backup/
This is the simplest method of full-system backup, because the rescue system does not need the user to fetch the backup during recovery. However, it needs more storage. Also, single-ISO backups cannot be incremental.Example 28.5. Configuring Single-ISO Rescue System and Backups
This configuration creates a rescue system and a backup file as a single ISO image and puts it into the/srv/backup/
directory:OUTPUT=ISO OUTPUT_URL=file:///srv/backup/ BACKUP=NETFS BACKUP_URL=iso:///backup/
Note
The ISO image might be large in this scenario. Therefore, Red Hat recommends creating only one ISO image, not two. For details, see the section called “ISO-specific Configuration”. -
To use
rsync
instead oftar
, add this line:BACKUP_PROG=rsync
Note that incremental backups are only supported when usingtar
.
28.2.1.2. Creating a Backup Using the Internal Backup Method
BACKUP=NETFS
set, ReaR can create either
a rescue system, a backup file, or both.-
To create a rescue system only, run:
rear mkrescue
-
To create a backup only, run:
rear mkbackuponly
-
To create a rescue system and a backup, run:
rear mkbackup
Note
BACKUP=NETFS
setting
expects the backup to be present before executing rear recover
. Hence, once the rescue
system boots, copy the backup file into the directory specified inBACKUP_URL
, unless using
a single ISO image. Only then runrear recover
.~]# rear checklayout ~]# echo $?
Important
rear checklayout
command does not check
whether a rescue system is currently present in the output location, and can return 0 even if it is not there. So it does not guarantee that a rescue system is available, only that the layout has not changed since the last rescue system has been created.Example 28.6. Using rear checklayout
~]# rear checklayout || rear mkrescue
28.2.2. Supported Backup Methods
28.2.3. Unsupported Backup Methods
-
The rescue system prompts the user to manually restore the files. This scenario is the one described in "Basic ReaR Usage", except for the backup file format, which may take a different form than a tar archive.
-
ReaR executes the custom commands provided by the user. To configure this, set the
BACKUP
directive toEXTERNAL
. Then specify the commands to be run during backing up and restoration using theEXTERNAL_BACKUP
andEXTERNAL_RESTORE
directives. Optionally, also specify theEXTERNAL_IGNORE_ERRORS
andEXTERNAL_CHECK
directives. See/usr/share/rear/conf/default.conf
for an example configuration.
28.2.4. Creating Multiple Backups
-
BACKUP=NETFS
(internal method) -
BACKUP=BORG
(external method)
-C
option
of the rear
command. The argument is a basename of the additional backup configuration file in the /etc/rear/
directory.
The method, destination, and the options for each specific backup are defined in the specific configuration file, not in the main configuration file.Procedure 28.1. Basic recovery of the system
-
Create the ReaR recovery system ISO image together with a backup of the files of the basic system:
~]#
rear -C basic_system mkbackup
-
Back the files up in the
/home
directories:~]#
rear -C home_backup mkbackuponly
/boot
, /root
,
and/usr
.Procedure 28.2. Recovery of the system in the rear recovery shell
-
~]#
rear -C basic_system recover
-
~]#
rear -C home_backup restoreonly
上一篇: pip install urllib2不能安装的解决方法
下一篇: 觉得眼前一黑
推荐阅读
-
使用linux系统性能监控工具KSysguard监控远端主机介绍
-
Linux系统中vim工具常用命令大全
-
linux系统mysql自动备份并使用ftp上传的方法
-
Linux系统中的gdb程序调试工具的命令知识介绍
-
VMware Workstation/Fusion 中安装 Fedora 23/24 及其他 Linux 系统时使用 Open VM Tools 代替 VMware Tools 增强工具的方法
-
16个 Linux系统方面的在线工具类网站
-
linux系统下ubuntu 中截图工具及快捷键设置
-
Linux系统对网站数据定期自动备份与删除
-
Linux系统IO分析工具之iotop参数详解(查看IO占用)
-
linux vmstat命令详解和使用实例(linux系统监控工具)