Ubuntu System Backup

Source: Internet
Author: User
Tags gz file root access

1. Backup System

How can I back up my Ubuntu system? It's easy to use tar just like backing up or compressing other things. Unlike windows, Linux does not limit root access to anything. You can throw everything in the partition to a tar file!

First become a root user:
$ Sudo Su

Then enter the root directory of the file system (if you do not want to back up the entire file system, you can also enter the directory you want to back up, including the remote directory or the directory on the mobile hard disk ):
# Cd/

The following is the complete command used to back up the system:
# Tar cvpzf backup. tgz-exclude =/proc-exclude =/lost + found-exclude =/backup. tgz-exclude =/mnt-exclude =/sys/

Let's take a simple look at this command:

"Tar" is of course the program used by the backup system.

"Cvpfz" is the tar option, which means "create a file", "retain Permissions" (Retain the original permissions for everything), and "use gzip to reduce the file size ".

“Backup.gz "is the file name of the file to be obtained.

"/" Is the directory to be backed up. Here it is the entire file system.

The directory that must be excluded from the backup is provided between the file name "backbackup.gz" and the directory name "/" to be backed up. Some directories are useless, such as "/proc", "/lost + found", and "/sys ". Of course, the “backup.gz file must be excluded, otherwise you may get some results beyond common sense. If "/mnt" is not excluded, other partitions mounted on "/mnt" will also be backed up. In addition, make sure that "/Media" does not mount anything (such as a CD or a mobile hard disk). If there is a mount, "/Media" must also be excluded.

Some people may suggest you exclude the "/dev" directory, but I think this is very inappropriate. The specific reason is not discussed here.

Before executing the BACKUP command, check whether the command you typed is what you want. It may take a short time to execute the BACKUP command.

After the backup is complete, a file named "backup. tgz" will be generated in the root directory of the file system. The file size may be very large. Now you can burn it to a DVD or put it somewhere you think is safe.

At the end of the Backup command, you may see the following prompt: 'tar: Error exit delayed from previous errors ', which can be ignored in most cases.

You can also use Bzip2 to compress files. Bzip2 has a higher compression ratio than gzip, but it is slower. If the compression rate is important to you, you should use Bzip2, replace "Z" in the command with "J", and give the file a correct extension "bz2 ". The complete command is as follows:
# Tar cvpjf backup.tar.bz2-exclude =/proc-exclude =/lost + found-exclude =/backup.tar.bz2-exclude =/mnt-exclude =/sys/

2. Restore the system

Be careful when restoring the system! If you do not know what you are doing, you may lose important data. Be careful!

Next, we use the example above. Switch to the root user and copy the file "backup. tgz" to the root directory of the partition.

One wonderful thing in Linux is that you can restore the system in a running system without using boot-CD for special guidance. Of course, if your system has crashed and cannot be started, you can use live CD to start it. The effect is the same. You can also use a command to kill all files in Linux. Of course, I am not going to give this command here!

Run the following command to restore the system:
# Tar xvpfz backup. tgz-C/

If your archive file is compressed using Bzip2, use:
# Tar xvpfj backup.tar.bz2-C/

Note: The preceding command overwrites all files in the partition with files in the archive file.

Before executing the recovery command, check whether the command you typed is what you want. It may take a short time to execute the recovery command.

At the end of the recovery command, your work has not been completed. Do not forget to recreate the directories excluded during Backup:
# Mkdir proc
# Mkdir lost + found
# Mkdir mnt
# Mkdir sys
And so on.

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.