Home  >  Article  >  Operation and Maintenance  >  How to back up linux system

How to back up linux system

王林
王林Original
2019-12-04 13:46:339034browse

How to back up linux system

1. Backup system

How should I back up my Ubuntu system? It's simple, use TAR just like you would back up or compress anything else. Unlike Windows, Linux does not restrict root access to anything. You can throw everything on the partition into a TAR file!

First become the root user:

$ sudo su

Then enter the root directory of the file system (of course, if you don’t 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 I used to back up the system:

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

Linux video tutorial recommendation: linux video tutorial

Command introduction:

"tar" is of course the program used by our backup system.

"cvpfz" is the option of tar, which means "create archive file", "preserve permissions" (retain the original permissions of everything), and "use gzip to reduce file size" .

"backup.gz" is the file name of the archive file we will get.

"/" is the directory we want to back up, in this case the entire file system.

The directory that must be excluded during backup is given between the archive file name "backup.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" archive file itself must be excluded, otherwise you may get some unexpected results. If "/mnt" is not excluded, other partitions mounted on "/mnt" will also be backed up. In addition, you need to confirm that nothing is mounted on "/media" (such as a CD, a mobile hard disk). If something is mounted, "/media" must also be excluded.

Before executing the backup command, please confirm whether the command you typed is what you want. Executing the backup command may take some time.

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

At the end of the backup command you may see a prompt like this: 'tar: Error exit delayed from previous errors', in most cases you can ignore it.

You can also use Bzip2 to compress files. Bzip2 has a higher compression rate than gzip, but is slower. If compression ratio is important to you, then you should use Bzip2, replacing "z" in the command with "j", and giving the archive a proper extension of "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 /

Recommended related articles and tutorials: linux tutorial

The above is the detailed content of How to back up linux system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn