Article Title: galloping in the Linux World-Linux System Management 6. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
File System Backup
One of the main tasks of the system administrator is to ensure the continuous integrity of the information stored in the system. One way to maintain integrity is to regularly back up data in the system.
System Backup is an important means to protect users from data corruption or loss. If an error occurs in the system hardware or important files are accidentally deleted, data may be damaged or lost, especially in the server application environment. Frequent data backup can minimize the loss caused by accidental damages, and ensure that the system recovers from the error state in the shortest time.
In Linux, there are multiple causes of data loss or data damage: the first reason is that the user misoperations forcibly delete or overwrite some important files; the second reason is hardware failure, which leads to data loss. The third reason is the failure of the software, which leads to data loss. The loss and damage of data in the system damage users' key data, and heavy data causes the system to fail to work normally. Therefore, regular backup of system and user data is the basic responsibility of the system administrator.
For backup, the administrator needs to consider the selection of backup media, backup policy, and backup tool. Currently, the commonly used backup media include floppy disks, tapes, discs, and hard disks. There are usually three backup policies: Full backup, Incremental backup, and update backup.
Backup Policy
1. Full backup
It is also called a simple backup, that is, a full backup of the system at a certain time, so that data is lost or damaged during the backup interval, you can use the last backup data to restore the system to the status of the last backup. However, each backup requires a large amount of storage space.
Therefore, it is impossible to perform such a system backup too frequently. A full backup can only be performed once every a long period of time (for example, one month. However, once data is lost during this relatively long interval (throughout the month), all updated system data cannot be recovered.
2. Incremental Backup
In this backup policy, a full backup is performed first, and then a backup is performed every short period of time, but only the data modified during this period of time is backed up. Then, after a long period of time, perform a full backup again and execute it repeatedly according to the cycle. Incremental Backup requires a small amount of work and can be performed frequently. For example, you can perform a full backup every month on a monthly basis, and perform incremental data backup on the day after work every day or when the business volume is small.
3. Update backup
This backup method is similar to Incremental backup. Perform a full backup at intervals, and then perform a daily data update backup. But the difference is that Incremental backup is the data changed on the day of backup, and update backup is the backup of all the data files changed since the last full backup. In the event of data loss, you can first restore the previous full backup, and then use the previous update backup to restore to the previous day.
The disadvantage of updating backups is that each small backup task requires more work than Incremental backup. However, the advantage is that Incremental Backup saves the backup data of the day on a daily basis and requires too much storage. The update backup only needs to save a full backup and an update backup. In addition, Incremental Backup must be restored multiple times in sequence during recovery, while Incremental Backup only needs to be restored twice. Therefore, it is relatively simple to update the backup.
Backup time
Backup needs to be performed on a regular basis. Generally, it should be performed when the system is relatively idle to avoid affecting the normal operation of the system. In this case, the data update frequency in the system is low. Generally, backup is performed after midnight. You can consider writing a script and adding it to the cron automatic task of the system. (For details about cron, use the man command to refer to the cron manual page ). However, it should be noted that the system backup scheme should be determined based on the specific system data updates and the user's usage of the system.
Backup tools
After the backup policy is selected, you can use tar, cpio, dump, and other backup tools to back up data. For general backup, tar is enough. The Command Format of tar backup is as follows:
Tar cvfpsz <生成的备份文件> <所需备份的目录>
When used for backup, you can use the tar command together with other commands. For example, you need to find the files updated in the past seven days, and use the tar-T parameter to specify the files to be backed up to perform the required backup:
In addition, you can use cpio commands similar to tar to back up data. Cpio compresses data more effectively than the tar command because it is designed to back up any file set, and the tar command is mainly designed to back up subdirectories; cpio can handle backups across multiple tapes, and can skip the bad section on the track to continue working, rather than tar.
Restore backup files
Generally, when backing up a file system, you only need to back up the content in the/etc,/root,/var,/home,/usr/local, and X11R6 directories. In addition, if you have customized some files and subdirectories, you also need to back up them.
In the future, when the system encounters some faults, it is necessary to restore the previously saved backup files. It is easy to restore the backup file. First, you must determine the location of the file to be restored. Run the tar-xp or cpio-im command. The-p option in tar and the-m option in cpio are used to ensure that all file attributes are restored together with the file. Because these commands are relatively simple, we will not give an example here. Note that when you use cpio to restore a directory, the-d option is used to create a subdirectory, And the tar command automatically creates the subdirectory.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service