Centos system backup and recovery tutorials

Source: Internet
Author: User

Linux is not like windows. It does not restrict the root user to access anything. Therefore, you can put every file in a partition into a TAR file.

Use the root user to switch to the root directory

Then, use the following command to back up the complete system:

tar cvpzf backup.tgz / --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys

Note:

Tar is the software we will use.

'Cvpfz' is the option we add to tar, like "Create a compressed document" (this is obvious ), "Save Permissions" (so that each file has the same permissions) and "gzip" (reduce the size ). Next, we will get the name of the compressed document. In our example, It is backup. tgz.
Followed by the root directory we want to back up. Since we want to back up everything :/. Next we want to remove the Directory: We don't want to back up everything, because some directories are not very useful. At the same time, make sure that you have not added the backup file itself. Otherwise, you will get a weird result. You may not include the/mnt folder-if you mount other partitions there-otherwise you will back up those files. At the same time, make sure that you have nothing to attach to/media (that is, no cd or removable media is mounted ). Otherwise, remove/media.

At the end of the process, you may get a message saying "tar: there is an error due to the delay of the previous error" or something else, but you can ignore it in most cases.

You can use Bzip to compress your backup. This means a high compression ratio, but also a low speed. If the compression ratio is very important to you, you only need to replace "z" in the command with "j" and give the backup a corresponding extension. These will make the command like this:

tar cvpjf backup.tar.bz2 / --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys

Recovery:

If the system is destroyed, we can use the backed up tar package for recovery.

Backup. tgz file under the root directory of the partition

Make sure that you are the root user and the root directory of the backup file in the file system.

One of the highlights of Linux is that this job can even be done on a running system; there is no need to be confused by boot cd or anything. Of course, if you make your system unable to be guided. You may have no choice but to use only one live-cd, but the results are the same. You can even remove all the files in the Linux system when it is running. But I won't tell you that command!

Here is the command I want to use:

tar xvpfz backup.tgz -C /

If you use bz2:

tar xvpfj backup.tar.bz2 -C /

Warning: This will replace all the files in your partition with the files in the compressed file!

Make sure that you re-create the directory you excluded before you do anything else:

mkdir procmkdir lost+foundmkdir mntmkdir sys
  • /Proc permission: file owner: root group: root owner: Read execution group: Read execution others: Read execution
  • /Lost + found permission: file owner: root group: root owner: Read Write execution group: Read execution others: Read execution
  • /Mnt permission: file owner: root group: root owner: Read Write execution group: Read execution others: Read execution
  • /Sys permission: file owner: root group: root owner: Read Write execution group: Read execution others: Read execution

After you restart, everything will be exactly the same as what you back up.

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.