I just re-installed the system. This time I decided to back up some important directories. I used to know that the tar command is a master in this field. But how do I back up the database? I have not studied it systematically. So I have summarized my experience and shared it with you.
The tar command is very powerful. In many cases, it can back up the entire system, and you can restore it through a live CD or through the installed system, overwrite and reply to yourself. If you have anything you need to back up, of course, it is better not to be a small thing. You can try the following method.
Part 1 backup
First
We need to re-create a compressed file under the/directory. Why should we create it under the/directory? This is because we cannot compress the compressed file, for example, the compressed file is located at/home.
/Dongmh, And I just backed up the home folder. What will happen? You can create an experiment on your own. I have created a test folder here, and then run CD
In the folder, enter the following command:
| Code: |
Tar cvpzf backup. tgz ../ |
This command creates a compressed file under the test folder, and the parent directory of the test is packaged in the file, at this time, my execution result is a backup in the test folder of the generated compressed package. tgz, which has a size of KB. the following error occurs when you try to open it:
| Reference: |
Gzip: stdin: unexpected end of File Tar: Abnormal EOF in the archive file Tar: the error cannot be recovered. exit now. |
Back to our backup, first we need the root permission:
Then go to the/directory:
Next, let's start the important backup:
| Code: |
Tar cvpzf backup. tgz -- exclude =/proc -- exclude =/lost + found -- exclude =/backup. tgz -- exclude =/mnt -- exclude =/sys/ |
This command is the core of the entire backup. It indicates creating a compressed package that does not contain/proc/lost + found/backup. tgz/sys in the current directory, and the compressed object is the/directory.
In the parameters of this directory
C: Create V: Detailed information Z: gzip: Compressed F: archive file or device P: Keep everything the same
Of course we can also use Bzip2 for compression, which will produce smaller packages, but it will be slower, depending on the performance of your processor. The method to use it is to replace Z with J.
| Code: |
Tar cvpjf backup.tar.bz2 -- exclude =/proc -- exclude =/lost + found -- exclude =/backup.tar.bz2 -- exclude =/mnt -- exclude =/sys/ |
Part 2 Restoration
Be careful about this part. If you are not sure what you are doing, you 'd better not perform overwriting.
The restoration process is very simple. The command is as follows:
| Code: |
| Tar xcpfz backup. tgz-C/ |
If you use Bzip2 for compression, run the following command:
| Code: |
| Tar xvpfj backup.tar.bz2-C/ |
Part 3 conclusion
Maybe you don't want to reinstall it for ease of use, just want to get a Ubuntu identical with the original computer on another computer, so this method is also suitable for you, you only need to modify/etc/fstab for Different Hard Disk Partitions. Other aspects are not very problematic. Good luck to everyone.
Source:
Http://forum.ubuntu.org.cn/trackback.php? E = 599
PS:
To query the uuid value of a partition, run the following command:
| Code: |
Ls-Al/dev/Disk/by-UUID Or sudo vol_id -- UUID $ HDD |
My/home is an independent partition, so I use the BACKUP command:
Sudo tar cvpjf/home/backup.tar.bz2 -- exclude =/proc -- exclude =/lost + found -- exclude =/home -- exclude =/mnt -- exclude =/media -- exclude =/tmp/