Backup and restoration in Linux
Recently, we have been configuring centos servers. We all know that the configuration process may be complicated and sometimes there may be errors. If the configuration fails and cannot be recovered, reload the system, therefore, it is very important to back up the system.
Linux backup is actually to store all files in a uniform package. It will be fine to overwrite the original files with these files when recovery is required.
Backup:
Switch to the root directory (/) of the root user, which must be the root directory. Otherwise, some files will be missed. Use the following command to package:
tar cvpzf backup.tgz / --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys
Among them, backup. tgz is the backup name, followed by the root directory we want to back up. Next, we want to remove the Directory: We don't want to back up everything, because some directories are not very useful, and make sure you haven't 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.
Recovery:
Run the following command to enter the root directory/as the root user:
tar xvpfz backup.tgz -C /
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 and Write execution group: Read execution other: Read execution/mnt permission: file owner: root group: root owner: Read and Write execution group: Read execution other: Read execution/sys permission: file owner: root group: root owner: Read and Write execution group: read and execute others: read and execute
After you restart, everything will be exactly the same as what you back up.
Reference: http://blog.sina.com.cn/s/blog_628c3f9e0102v24j.html