Linux backup and restore (dump, restore commands)

  In server management, regular backup and recovery when necessary are necessary conditions to ensure the stable operation of the server. Let's get to know the knowledge of Linux backup and recovery.

Linux backup and recovery

Backup overview

 Backup object

In the Linux system, the important directories that need to be backed up are mainly:

table of Contents Description
/root Super User Home Directory
/home Home directory of ordinary users
/ var / spool / mail System mail directory (if any)
/etc Configuration file directory
/boot System startup related directories
/ var / log System log (for accident investigation)

In addition, there are some data important to the server (apache, mysql, etc.), which should also be backed up

 Backup method

  1. Full backup: Copy all the data that needs to be backed up to the backup at one time. The advantage is that the backup is relatively complete. The disadvantage is that the amount of data in a single backup is too large, which causes a large server load, a large space, and some problems.
  2. Incremental backup: After the original data is backed up, only the new data content will be backed up at regular intervals in the future. The advantage is that it takes up space and the load is small during backup. The disadvantage is that the recovery is more cumbersome (you need to restore each incremental part in turn Instead of restoring the whole at once)
  3. Differential backup: It is a compromise between the above two backup methods. On the basis of the original data backup, all new data compared to the original data is backed up at regular intervals. While combining the advantages of the above two methods, it also has its disadvantages to a certain extent

Common backup and recovery commands

dump command

Note that the dumpcommand is not installed by default in some distributions and needs to be installed manually

dump [options] target source
#选项见下,target为备份目标文件名,source为要备份的文件或目录

dumpCommand options:

Options Description
-level Backup level (level is a number)
-u After the backup is successful, write the backup time into the /etc/dumpdatesfile
-v View information in the process
-j Compress the backup file into a .bz2format
-w Display the backup level and backup time of the file system allowed to use this command to back up

 Backup level

  In the dump command backup, the backup level is a required option and is a number. Among them, it 0means a full backup, it 1-9is an incremental backup, and each level is based on the previous level to find an incremental backup. For example, backup level 1 compares the current state with level 0 (initial state), and incrementally backs up to a new file (the name should preferably include the backup level for easy management), and backup level 2 will compare the current state with level 1. Compare the status of the level...

restore command

restoreThe command is the dumpopposite of the command, it restores the backup file to the corresponding location.

restore [mode] [options]
#mode为恢复模式,只能选一种,options为附带选项

restoreCommand mode and options

mode Description
-C Compare the changes of the backup data with the current state
-i Enter interactive mode, manually select the files to be backed up
-t Check what data is in the backup file
-r Restore mode, restore the backup data to the corresponding location
Options Description
-f Specify the file name of the backup file

The target of the restore command is the working directory. It is recommended to create an empty directory for the restore operation before restoring to avoid damage. The backup file contains the backup level and does not need to be specified

Guess you like

Origin blog.csdn.net/Zheng__Huang/article/details/108325467