[Turn] Use tar to backup ubuntu

Today, I accidentally forcibly ended a process that I didn’t know its use for. As a result, I could not enter the x interface, and gdm could not be started. I used apt-get to repair it. As a result, I almost deleted all the software packages related to the x interface, so I had to reinstall the system. In order to prevent similar problems next time, make a backup of the system.
  There are two backup methods, one is to backup through a software, and the other is to backup through the command line.
  The method of software backup is to download a software called UCloner. The usage method has been explained in the compressed package, so I won't say more, but because this software only supports Ubuntu 10.10 10.04 and 9.10, other versions must use the command line for backup.


Here's how to back up an Ubuntu system:
Open a terminal and enter the following commands:
  1. Become root: sudo su
  2. Go to the root directory: cd /
  Then, here is the complete command I used to backup my system:
  tar - cvpzf /media/sda7/backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys --exclude=/media /
  Next, let's explain a little:
  tar is a program used for backup
  c - create a new backup document
  v - verbose mode, the tar program will output all information in real time on the screen.
  p - save permissions, and apply to all files.
  z - Compress the backup file with 'gzip' to reduce the size of the backup file.
  f - Indicates the path where the backup file is stored, /media/sda7/backup.tgz is the name of the backup file in this example. The backup location of this backup file is another partition, that is, the original WIN partition. Because of the lack of space in my root directory, I have to make backups elsewhere.
  --excloude - Exclude specified directories from being backed
  up Let's see what directories we want to include, we don't have to back up everything because some directories are not very useful. Make sure you don't want to include files, otherwise you'll get a weird result. You also don't have to back up stuff in the /mnt directory unless you have other partitions hanging under it or you insist on backing up. You must also make sure that no resources are attached to the /media directory (eg, any CDs or removable media). Otherwise, remove /media.
  The last parameter is the directory we want to save. We want to save everything, use / as the root directory.
  When I used this method for backup, I finally gave me a hint: tar:Error exit delayed from previous errors
  Of course, yours may be displayed in Chinese. Anyway, what is wrong? I checked the Internet and said that it was caused by insufficient permissions. , but if you use Root and that's still the case, it's better to use the Live usb for backup, because some people say that the backup may be like this when it is running. (Some people say that this prompt can be ignored)
  The way to backup with Live usb:
  Then open the terminal and enter the following commands:
  1. Become the root user: sudo su
  2. Go to the root directory: cd /
  3, create a directory: mkdir /a
  4, Mount /dev/sdax /a
  5 on the root directory partition, enter the a directory cd /a
  6, backup tar -cvpzf /media/xxx/backup.tgz *
  and then restore the Ubuntu system backup in the future:
  Warning: please, for God's sake, be careful here. If you don't understand what you are doing, it is very likely to overwrite your important data, so please be very careful!
  Be careful!!! Because tar restore will only overwrite the same files, but this method only restores the files at the time of backup , that is to say, if some files are lost or damaged, these files can be recovered and repaired, but other files generated during the period from backup to recovery cannot be deleted. To put it bluntly, if you back up the system, there are four files of 1234. If three days later, for some reason, it becomes 1234'5 (4 changed), after you restore it, it will become 12345, of which 4' is restored to the file at the time of backup, and 5 is retained. So if you want to completely restore it to the way it was backed up, it's best to delete all the files in the root directory completely, and then restore it, so that it can be restored to the way it was when it was backed up.
  Well, to continue the example we talked about earlier, we created a backup file named backup.tgz in the other partition (sda7) directory.
  One of the nice things about Linux is that you can restore while the system is running, without the need for a bootable CD or any other mess. Of course, if your system has crashed, you must choose to use a live CD, but the result is still the same.
  well, let's get back to business. This is the command I use, if your backup is not in the same location as mine, please modify /media/sda7 accordingly:
  tar -xvpzf /media/xxx/backup.tgz -C /
  if You are using bz2 compression:
  tar -xvpjf /media/xxx/backup.tar.bz2 -C /
  If the system has crashed, you can use Live usb to log in, then
  mkdir /tmp/root
  mount /dev/sdaX /tmp/root
  tar -xvpjf /media/xxx/backup.tar.bz2 -C /tmp/
  root rm -rf /tmp/root/* and it will be clean. (That is, delete all files in the root directory as mentioned earlier)
  This is only restored on this machine. If it is restored to another machine, remember to modify the fstab file. (May also require grub to be installed)
  At the end of the restore command, and your work is not done, don't forget to recreate those directories that were excluded from the backup:
  # mkdir proc
  # mkdir lost+found
  # mkdir mnt
  # mkdir sys
  # mkdir media
  , etc.


This is the way to back up the Linux system. It may not be necessary to back up the system at all, but be prepared. Who knows if it needs to be restored.
Transfer from: Multi-backup system backup forum http://bbs.dbfen.com/thread- 2011-1-2.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326931772&siteId=291194637