Use the Find command in unix to back up the root file system

Source: Internet
Author: User
Article Title: Use the Find command in unix to back up the root file system. 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.

There are many commands in Unix to back up files. However, in Unix operating systems, the root file system is a special file. In general, if you back up such files, you must detach other file systems. Because the root file system is the ancestor of other file systems, if it is not uninstalled, files in other file systems will be backed up at the same time. However, if you detach another file system before backing up, it will be very troublesome. Therefore, the find command provides a very useful parameter to help us implement this function.

I. Importance of backup of the root file system and difficulties of backup.

When the system crashes, you can reinstall the operating system to restore it. However, this is a huge workload because you need to reinstall each external device. In Unix operating systems, installing and configuring the driver for each external device is very troublesome. If the system engineer can back up files in the root file system during normal work, even if the operating system needs to be re-installed in case of system failure, you only need to install the minimum set of Unix operating systems. Restore the configuration files in these root file systems, saving the trouble of configuring external devices.

However, when backing up the root file system, you may encounter a lot of trouble due to its special position. For example, the configuration file in the root file system changes no matter when an external device is added to the Unix operating system or when the external device is detached from the system. That is to say, the configuration files in the root file system are constantly changing. For this reason, the operating system should be able to identify the changed configuration files and then select to copy them. Otherwise, the backup workload will be increased. Secondly, because the root file system is the ancestor of other file systems, if you back up the root file system, the system will back up the contents of other file systems at the same time. This is undoubtedly not what we hope to achieve.

Ii. Optional mount function.

The find command has a-mount option. If the find/-mount command is used, the operating system will not find files from other file systems at the loading point. That is to say, you can use this option to back up only the root file system without detaching other file systems and accessing them. That is, the optional find command is used, and the search path is only in the root file system.

To this end, the common backup policy for the root file system is that when the system has been fully and correctly configured, the system engineer immediately uses the-mount option to perform a full backup of the root file system. Then, each time the configuration file in the root file system changes, you can perform Incremental backup on them. The-mount option can be used to solve the first problem encountered during the backup of the root file system.

  3. identify whether the file has changed.

To implement Incremental backup in the root file backup, the operating system must first determine which files have been updated after the last backup. To achieve this purpose, the Find command provides two processing mechanisms: the-newer parameter and the-mtime parameter.

1. Use newer options.

Using newer options to achieve this requirement is a little more troublesome, but relatively scientific. To use this option to implement this command, there are three steps.

Step 1: Create a zero-byte comparison file. System Engineers must first create a zero-byte file using VI or other tools. What is the purpose of this document? I will talk about it now. When newer can be used to determine which files have been modified after the last backup, this zero-byte file plays a key role in it. In fact, what we use is not the content of this file, but the time attribute in this file.

Step 2: Use the touch command to modify the time attribute. As we all know, files in Unix operating systems have many attributes, such as the creation time and modification time. These file attributes are required in many script programs. In this case, we need to use the modification time attribute in these file attributes. You can use the touch command to modify the event attributes of a file. If we use the touch file name, we can assign the current time of the system to the file modification time cut.

Step 3: Use the-newer parameter for comparison. We use the newer parameter to find the files changed after the last backup. The main idea is to cut the modification time of the zero-Byte File Created above into the backup time. Then, at the next backup, we can use the newer option to modify the Time of the file to be searched and the time of modification of the zero-byte file (the event after the last backup) attribute. At this time, the find command will only find the files updated at this time and back up them. Add the touch command to the find command, and then use the newer option to find the file updated after the last backup. Therefore, when writing a script program, you need to write the find command in front. The touch command can be used to modify the time attribute of a zero-byte file after the required file is backed up.

2. The mtime option is used.

In fact, the Find command in the Unix operating system contains an option-mtime. This option refers to the files that have been modified in a recent period of time. After you Find this option, the system compares the system modification time with the current system time. Compare the time difference with the time difference specified by the mtime option. For example, mtime 1 indicates that all the files changed in the last day (24 hours) are searched. This can also achieve the purpose of Incremental backup, but it may not be very scientific. If an important external device is installed, the system engineer manually executes the backup script. When the system performs automatic backup, the time parameter for searching the configuration file is the last day, instead of after the last backup. However, this usually does not affect the backup efficiency. To this end, if the system engineer does not understand the NEWER and TOUCH applications, the mtime option can also be used to fulfill this requirement. They are generic.

[1] [2] Next page

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.