Article Title: use tar to back up linux systems. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
"What should I use to back up my system ?" You may ask. Just like backing up or compressing a file, TAR. Unlike Windows, Linux does not restrict root users to access anything. Therefore, you can put every file in a partition into a TAR file.
To implement this method, use this to become the root user:
Sudo su
Go to the root directory of your file system (in our example, we use it, but you can go anywhere you want to back up, including remote or removable drives .)
Cd/
Then, the following is the complete command that I used to back up my system:
Tar cvpzf backup. tgz/-- exclude =/proc -- exclude =/lost + found -- exclude =/backup. tgz -- exclude =/mnt -- exclude =/sys
Next, let's explain a little:
* Obviously, the 'tar 'part is the software we will use.
* 'Cvpfz' is an 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 file. 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 will 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.
If you want to exclude all other partitions, you can use the 'l' parameter instead of -- exclude. The preceding command looks like this:
Tar cvpzlf backup. tgz/-- exclude =/lost + found -- exclude =/backup. tgz
Press: kvidell recommends removing the/dev directory from the forum topic. However, I have other evidence that it is unwise to do so.
Well, if the command is suitable for you, press the OK key (or enter the key, whatever name it is), and then you don't have to do anything. Just relax. Backup may take some time.
After that, there will be a file named backup. tgz in the root directory of your file system-it may be quite large. Now you can burn it to a DVD or move it to another machine. You can do whatever you want.
Press 2: 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, however, 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
2.1. Network Backup
If there are too few blank file systems and you cannot mount other file systems to save backup files, you may use netcat to complete the backup.
On the receiver, you must set netcat to write backup files, as shown in the following code:
Nc-l-p 1024> backup.tar.bz2
Then you send the tar command without the 'F' parameter to the sender through netcat, as shown in the following code:
Tar cvpj/| nc-q 0 1024
In the above command, 1024 is just a random port number, and any port number from 1024 or above can work.
If you use network backup securely without relying on the file system to complete the backup, in fact, a real fast network is faster than writing backup files to the disk.
In the above description (because I was just in a daze, I cannot confirm that it is reliable) is the command:
Tar cvpj/| ssh "Cat> backup.tar.bz2"
3. Restore
Warning for God's sake, please be careful in this part. If you do not understand what you have done here, you may eventually destroy things that are important to you, so be careful. The example in the previous chapter is the 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!
Now, let's get down to the truth. 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!
Just press confirm/press enter/your brother/whatever, and then watch the fireworks. Similarly, it will take a while. After it is completed, you will have a fully recovered Ubuntu system! Just make sure that you re-create the directory you excluded before you do anything else:
Mkdir proc mkdir lost + found mkdir mnt mkdir sys etc...
After you restart, everything will be exactly the same as what you back up.
3.1. Restore GRUB
So, if you want to move your system to a new hard disk, or you want to do something bad for your GRUB (for example, install Windows ), you will also need to reinstall GRUB. In this forum, there are a lot of excellent instructions on how to do this, so I will not start from scratch. Instead, let's take a look at this (ForUM) or here: RecoveringUbuntuAfterInstallingWindows
Some methods have been proposed in the topic of this forum. I personally recommend the second remmelt, because it works every time.
Yes, that's it! I hope it will help!