Backup and restore of Ubuntu16.04 system

Source: Internet
Author: User
Tags bz2

The purpose of this paper is to record the backup and restore of Linux system in command line mode, although there are many kinds of backup methods, but this article only records the simplest and most rude one:

First become the root user:
$ sudo su

Then go to the root of the filesystem (of course, if you don't want to back up the entire file system, you can also go to the directory you want to back up, including the remote directory or the directory on your hard drive):
# CD/

Here is the complete command I 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 brief look at this command:

"Tar" is, of course, the program we use to back up our systems.

"CVPFZ" is the tar option, meaning "Create profile", "Keep permissions" (keep everything original), "Use gzip to reduce file size".

"Backup.gz" is the file name of the archive file we are going to get.

"/" is the directory we want to back up, here is the entire file system.

Directories that must be excluded from the backup are given between the file name "backup.gz" and the Directory Name "/" to be backed up. Some directories are useless, such as "/proc", "/lost+ found", "/sys". Of course, the "backup.gz" file itself must be excluded, otherwise you may get some out of the ordinary results. If you do not exclude "/mnt", other partitions that are mounted on "/mnt" will also be backed up. Also need to confirm that "/media" does not mount anything (such as CD-ROM, mobile hard disk), if there is a mount thing, must be "/media" also excluded.

One might suggest that you exclude the "/dev" directory, but I don't think it's a good idea to do this, but it's not discussed here.

Before you execute the backup command, confirm that the command you typed is what you want. The backup command may take a short time to execute.

After the backup is complete, a file named "Backup.tgz" will be generated at the root of the file system, and it may be very large in size. Now you can burn it to a DVD or put it where you think it's safe.

At the end of the backup command you may see a hint: ' Tar:error exit delayed from previous errors ', in most cases you can ignore it.

You can also use BZIP2 to compress files, BZIP2 is higher than gzip compression rate, but slower. If the compression ratio is important to you, then you should use BZIP2, "J" instead of "Z" in the command, 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. Recovery system

Be careful when you are working on a recovery system! If you don't know what you're doing, you may lose important data, so be careful!

Then the above example. Switch to the root user and copy the file "Backup.tgz" to the root directory of the partition.

One of the great things about Linux is that you can restore your system in a running system without having to use BOOT-CD to boot specifically. Of course, if your system has been hung up and cannot be started, you can use the live CD to start, the effect is the same. You can also kill all the files in the Linux system with one command, but I'm not going to give this command here!

Use the following command to restore the system:
# tar Xvpfz backup.tgz-c/

If your profile is compressed using BZIP2, you should use:
# tar XVPFJ backup.tar.bz2-c/

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

Before executing the RESTORE command, please confirm that the command you typed is what you want, and it may take a short time to execute the restore command.

At the end of the restore command, your work is not finished, and don't forget to recreate the directories that were excluded from the backup:
# mkdir Proc
# mkdir Lost+found
# mkdir MNT
# mkdir SYS
Wait a minute

When you restart your computer, you'll find everything back to what you did when you created your backup!

This article in the process of writing reference blog 52029407, here to express my thanks!

Before you execute the backup command, confirm that the command you typed is what you want. The backup command may take a short time to execute.

After the backup is complete, a file named "Backup.tgz" will be generated at the root of the file system, and it may be very large in size. Now you can burn it to a DVD or put it where you think it's safe.

At the end of the backup command you may see a hint: ' Tar:error exit delayed from previous errors ', in most cases you can ignore it.

You can also use BZIP2 to compress files, BZIP2 is higher than gzip compression rate, but slower. If the compression ratio is important to you, then you should use BZIP2, "J" instead of "Z" in the command, 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. Recovery system

Be careful when you are working on a recovery system! If you don't know what you're doing, you may lose important data, so be careful!

Then the above example. Switch to the root user and copy the file "Backup.tgz" to the root directory of the partition.

One of the great things about Linux is that you can restore your system in a running system without having to use BOOT-CD to boot specifically. Of course, if your system has been hung up and cannot be started, you can use the live CD to start, the effect is the same. You can also kill all the files in the Linux system with one command, but I'm not going to give this command here!

Backup and restore of Ubuntu16.04 system

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.