Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to back up a Ubuntu system

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to back up the Ubuntu system". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to back up the Ubuntu system".

1. In the desktop environment, open your mobile hard drive

Check the drive letter where the disk is located: df-ah

Df (DiskFree) a stands for all,h for characters that human (person) can understand. For details, see the command df-- help

Ly@ly:/dev$ df-ah

File system capacity used available used% mount point

/ dev/sda9 93G 8.9G 79G 11% /

Proc 0 000-/ proc

Sysfs 0 000-/ sys

None 4.0K 0 4.0K 0% / sys/fs/cgroup

None 0 000-/ sys/fs/fuse/connections

None 0 000-/ sys/kernel/debug

None 0 000-/ sys/kernel/security

Udev 1.9G 4.0K 1.9G 1% / dev

Devpts 0 000-/ dev/pts

Tmpfs 386m 888K 386m 1% / run

None 5.0M 0 5.0M 0% / run/lock

None 1.9G 156K 1.9G 1% / run/shm

None 100m 36K 100m 1% / run/user

Gvfsd-fuse 0 000-/ run/user/ly/gvfs

/ dev/sdb5 222G 126G 97G 57% / media/ly/LY2

/ dev/sdb1 245G 175G 70G 72% / media/ly/LY1

I want to put the backup files on the removable hard drive LY1. So remember the device sdb1

Here is how to back up the Ubuntu system:

Then open the terminal and enter the following command:

1. Become the root user: sudo su

2. Go to the root directory: cd /

Then, here are the complete commands I use to back up 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 bit:

Tar is a backup program.

C-create a new backup document

V-detailed mode, the tar program will output all the information on the screen in real time.

P-Save permissions and apply to all files.

Z-use 'gzip' to compress backup files to reduce backup file size.

F-indicates the path where the backup file is stored, and / media/sda7/backup.tgz is the backup file name in this example. The backup location of this backup file is in the other partition, that is, the original WIN partition. Because there is not enough space in my root directory, I have to back up somewhere else.

-- excloude-excludes the specified directory from being backed up

Let's take a look at the directories we want to include, we don't have to back up everything, because some directories are not very useful. Confirm the files you do not want to include, or you will get a very strange result. You don't have to back up anything 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 hung in the / media directory (for example, any CD or removable storage media). Otherwise, / media is removed.

The last parameter is the directory we want to save. We want to save everything and use / as the root directory.

When I use this method for backup, what will you tell me at the end: tar:Error exit delayed from previous errors

Of course, what you may show is Chinese, anyway, I checked it on the Internet and said it was caused by insufficient permissions, but if you still use Root permissions, it is best to use Live usb for backup, because some people say that backup is possible at run time. (some people say this hint can be ignored.)

Using Live usb backup method:

Then open the terminal and enter the following command:

1. Become the root user: sudo su

2. Go to the root directory: cd /

3. Create a directory: mkdir / a

4, hang in the root directory partition mount / dev/sdax / a

5. Enter directory a cd / a

6. Back up tar-cvpzf / media/xxx/backup.tgz *

Then it's time to 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 likely to overwrite your important data, so please be very careful!

Attention! Because tar restore will only overwrite the same files, but this method only restores the files at the time of backup, that is, if some files are lost or damaged, you can restore and repair them, but you cannot delete other files generated during the period from your own copy to the recovery period. To put it bluntly, if you backup the system with 1234 of these four files, if three days later, for some reason, it becomes 12345th (4 changed). After you restore, it will become 12345, of which 4 'will be restored to the backup files and 5 will be retained. So if you want to completely restore to the backup look, it is best to completely delete all the files in the root directory, and then restore, so that you can restore to the backup look.

Well, continuing with the example we talked about earlier, we created a backup file called backup.tgz in the other sda7 directory.

One of the wonderful things about Linux is that it can be restored while the system is running without the need to boot the CD or any other mess. Of course, if your system has crashed, you must choose to use live CD, but the result is the same.

All right, let's get down to business. This is the command I want to 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 compressed:

Tar-xvpjf / media/xxx/backup.tar.bz2-C /

If the system has crashed, you can log in using Live usb, and then

Mkdir / tmp/root

Mount / dev/sdaX / tmp/root

Tar-xvpjf / media/xxx/backup.tar.bz2-C / tmp/root

Of course, you can rm-rf / tmp/root/* before recovery, so it will be clean. (that is, delete all files in the root directory as mentioned earlier)

This is only restored on the local machine, if you restore to another machine, remember to modify the fstab file. (you may also need to install grub)

When the restore command ends and your work is not finished, don't forget to recreate the directories that were excluded from the backup:

# mkdir proc

# mkdir lost+found

# mkdir mnt

# mkdir sys

# mkdir media

Thank you for your reading, the above is the content of "how to back up the Ubuntu system", after the study of this article, I believe you have a deeper understanding of how to back up the Ubuntu system, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report