Article Directory
Preface
If you only implement a complete backup, you can pack and compress with tar, copy with the cp command, and then write a backup script to back up my important data, and then run this script at a specified time on a regular task to achieve a complete backup. .
But if you want to achieve incremental backup, it will be very troublesome to do it by writing scripts yourself. How to solve the whole problem? ? ? You can use the backup tool dump and restore tool restore commands to achieve.
1. dump command
command: dump [选项] 备份之后的文件名 原文件或目录
Options:
-level 0-9 is a backup level
-f file name Specify the file name
after the backup -u After the backup is successful, record the backup time in the /etc/dumpdates file
-v Show more output information during the backup
-j call The bzlib library compresses the backup files, in fact, it compresses the backup files into .bz2 format
-w Displays the backup level and backup time of the partitions that are allowed to be dumped
1.1 Install dump tool
The dump command is not installed by default and needs to be installed manually
1.2 Backup partition
Start experiment:
(1) In order to do experiments, you can back up the /boot/ partition. Generally, the /boot/ partition does not need to be backed up in actual work. As long as the version is the same, the contents of the /boot/ partition are the same.
Command: dump -0uj -f /root/boot.bak.bz2 /boot`
Function: Backup command, first execute full backup in turn, and compress and update the backup time
Command: cat /etc/dumpdates
Function: View the backup time file
(2) Copy the install.log file to the /boot/ directory, and perform an incremental backup, and see whether the dump command will back up the entire /boot/ directory completely, or Only back up new data. It is best not to do too many operations on the boot partition. If the partition is full, it will not start. The whole is just an experiment and it will be deleted. After the copy is in, go and execute it again, a level of incremental backup.
Command: cp install.log /boot/
Function: Copy the log file to the /boot partition
Command: dump -1uj -f /root/boot.bak1.bz2 /boot
Role: incremental backup /boot/ partition, and compression
Command: dump -W
Function: Query the backup time and backup level of the partition
1.3 Back up files or directories
Everything is a file in Linux
Command: dump -0j -f /root/etc.dump.bz2 /etc/
Function: Full backup of the /etc/ directory, only a few times of 0 can be used for full backup, and incremental backup is not supported
Note: If you are backing up a directory, you can only use level 0 to perform a full backup. Only when you back up partitions can you perform incremental backups.
2. The restore command
command: restore [模式选项] [选项]
Mode options: There are the following four modes commonly used by the restore command. These four modes cannot be mixed, only one can be selected.
-C Compare the changes of the backup data and the actual data
-i Enter the interactive mode, manually select the file to be restored
-t View mode, used to view what data is in the backup file.
-r restore mode, used for data restoration
Options
-f specifies the file name of the backup file
2.1 View the contents of the backup file
Command: restore -t -f boot.bak.bz2
Function: -t View mode to view which files are in the backup file.
2.2 Restore partition backup
(1) Restore the boot.bak.bz2 partition backup, first restore the full backup data
Command: mkdir boot.test
Command: cd boot.test/
Function: Create a new directory, restore the file to the entire file, and restore it everywhere.
Command: restore -r -f /root/boot.bak.bz2
Function: restore backup, -r restore mode
(2) Restore incremental backup data
Command: restore -r -f /root/boot.bak1.bz2
Role: Restore incremental backup data
2.3 Restore the backup of the directory
(1) Restore the backup of the /etc/ directory etc.dump.bz2
Command: restore -r -f etc.dump.bz2
Role: Restore etc.dump.bz2 backup
2.4 Compare the changes of backup data and actual data
(1) Change the name of the kernel image file in the /boo/ directory to compare the existing file with the backup file. What changes are there?
Note: This is just an experiment. After the name of the kernel is changed, it must be changed back, otherwise the kernel will disappear and the system will not be able to get up after the next restart.