`
samwang
  • 浏览: 44956 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

Back up Linux system

阅读更多
http://ubuntuforums.org/showthread.php?t=35087

Howto: Backup and restore your system!

<!-- / icon and title --><!-- message -->

Hi, and welcome to the Heliode guide to successful backing-up and restoring of a Linux system!

Most of you have probably used Windows before you started using Ubuntu. During that time you might have needed to backup and restore your system. For Windows you would need proprietary software for which you would have to reboot your machine and boot into a special environment in which you could perform the backing-up/restoring (programs like Norton Ghost).
During that time you might have wondered why it wasn't possible to just add the whole c:\ to a big zip-file. This is impossible because in Windows, there are lots of files you can't copy or overwrite while they are being used, and therefore you needed specialized software to handle this.

Well, I'm here to tell you that those things, just like rebooting , are Windows CrazyThings (tm). There's no need to use programs like Ghost to create backups of your Ubuntu system (or any Linux system, for that matter). In fact; using Ghost might be a very bad idea if you are using anything but ext2. Ext3, the default Ubuntu partition, is seen by Ghost as a damaged ext2 partition and does a very good job at screwing up your data.

1: Backing-up

"What should I use to backup my system then?" might you ask. Easy; the same thing you use to backup/compress everything else; TAR. Unlike Windows, Linux doesn't restrict root access to anything, so you can just throw every single file on a partition in a TAR file!

To do this, become root with

Code:
sudo su

and go to the root of your filesystem (we use this in our example, but you can go anywhere you want your backup to end up, including remote or removable drives.)

Code:
cd /

Now, below is the full command I would use to make a backup of my system:

Code:
tar cvpzf backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz
 --exclude=/mnt --exclude=/sys /

Now, lets explain this a little bit.
The 'tar' part is, obviously, the program we're going to use.

'cvpfz' are the options we give to tar, like 'create archive' (obviously),
'preserve permissions'(to keep the same permissions on everything the same), and 'gzip' to keep the size down.

Next, the name the archive is going to get. backup.tgz in our example.

Next comes the root of the directory we want to backup. Since we want to backup everything; /

Now come the directories we want to exclude. We don't want to backup everything since some dirs aren't very useful to include. Also make sure you don't include the file itself, or else you'll get weird results.
You might also not want to include the /mnt folder if you have other partitions mounted there or you'll end up backing those up too. Also make sure you don't have anything mounted in /media (i.e. don't have any cd's or removable media mounted). Either that or exclude /media.

EDIT : kvidell suggests below we also exclude the /dev directory. I have other evidence that says it is very unwise to do so though.

Well, if the command agrees with you, hit enter (or return, whatever) and sit back&relax. This might take a while.

Afterwards you'll have a file called backup.tgz in the root of your filessytem, which is probably pretty large. Now you can burn it to DVD or move it to another machine, whatever you like!

EDIT2:
At the end of the process you might get a message along the lines of 'tar: Error exit delayed from previous errors' or something, but in most cases you can just ignore that.

Alternatively, you can use Bzip2 to compress your backup. This means higher compression but lower speed. If compression is important to you, just substitute
the 'z' in the command with 'j', and give the backup the right extension.
That would make the command look like this:

Code:
tar cvpjf backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2
 --exclude=/mnt --exclude=/sys /

2: Restoring

Warning: Please, for goodness sake, be careful here. If you don't understand what you are doing here you might end up overwriting stuff that is important to you, so please take care!

Well, we'll just continue with our example from the previous chapter; the file backup.tgz in the root of the partition.

Once again, make sure you are root and that you and the backup file are in the root of the filesystem.

One of the beautiful things of Linux is that This'll work even on a running system; no need to screw around with boot-cd's or anything. Of course, if you've rendered your system unbootable you might have no choice but to use a live-cd, but the results are the same. You can even remove every single file of a Linux system while it is running with one command. I'm not giving you that command though!

Well, back on-topic.
This is the command that I would use:

Code:
 tar xvpfz backup.tgz -C /

Or if you used bz2;

Code:
 tar xvpfj backup.tar.bz2 -C /

WARNING: this will overwrite every single file on your partition with the one in the archive!

Just hit enter/return/your brother/whatever and watch the fireworks. Again, this might take a while. When it is done, you have a fully restored Ubuntu system! Just make sure that, before you do anything else, you re-create the directories you excluded:

Code:
mkdir proc
mkdir lost+found
mkdir mnt
mkdir sys
etc...

And when you reboot, everything should be the way it was when you made the backup!

分享到:
评论

相关推荐

    Linux System Administrator Guide Version0.9

    The guide provides a detailed overview of the various components that make up a Linux system, including: - **Operating System Components**: The guide explains the different parts of an operating ...

    Linux: Powerful Server Administration

    Set up high performance, scalable, and fault-tolerant back ends with web and database servers Facilitate team communication with a real-time chat service and collaboration tools Monitor, manage and ...

    Beginning Ubuntu Linux Part1

    It covers setting up the Linux system so that it’s ready to use. One chapter is dedicated to setting up common hardware devices, such as printers and modems, and another explains how you can secure ...

    Beginning Ubuntu Linux Part2

    It covers setting up the Linux system so that it’s ready to use. One chapter is dedicated to setting up common hardware devices, such as printers and modems, and another explains how you can secure ...

    CentOS宝典.pdf

    Learn how to set up users, automate system tasks, back up and restore files, and prepare for the latest security issues and threats; also learn how to use and customize the desktop menus, icons, ...

    【Linux Device Driver】(3edtion).pdf

    Setting Up Your Test System 15 The Hello World Module 16 Kernel Modules Versus Applications 18 Compiling and Loading 22 The Kernel Symbol Table 28 Preliminaries 30 Initialization and Shutdown 31 ...

    RHEL6 performance tuning guide

    The Performance Tuning Guide describes how to optimize the performance of a system running Red Hat Enterprise Linux 6....You should also back up all your data and pre-tuning configurations.

    Oracle sqldeveloper without jdk (win+linux)

    If the locale of the operating system is not English, a few UI elements, like default wizard buttons and Oracle error messages, may show up in the language of this locale. If the locale of the ...

    mongodb在linux环境下命令行操作介绍文档

    back_up (empty) blogtest 0.203125GB local 44.056640625GB test (empty) ``` 这里显示了服务器上几个不同的数据库,包括空的数据库以及包含数据的数据库。 ##### 2.2 切换数据库 要切换到另一个数据库,可以...

    Professional Ubuntu Mobile Development

    Essential reading for open source software developersAs the most popular open source operating system in use today, Ubuntu Linux has recently released versions that are aimed at device manufacturers ...

    ap6212a0_a33_sc3817r_神舟验证版本_借用nvram_ap6210这个配置文件_20170626_1834没有外层目录.7z

    # device/softwinner/polaris-common/rild/ip-up:system/etc/ppp/ip-up \ # device/softwinner/polaris-common/rild/3g_dongle.cfg:system/etc/3g_dongle.cfg \ # device/softwinner/polaris-common/rild/usb_mode...

    Ubuntu The Complete Reference

    - **Backup Planning**: Overview of planning a backup strategy, including determining what to back up and how often. - **Backup Tools**: Discussion of backup tools available for Ubuntu, such as `rsync`...

    IBM HMC配置及操作手册

    * 备份方法:登陆 HMC 后,选择 Back up Critical Concole Data,之后选择是备份到随 HMC 来的 DVD-RAM 上,还是远程服务器上。 * 恢复方法:从 DVD-RAM 中恢复或从远程服务器中恢复,选择相应的备份文件进行恢复。 ...

    cp201x资源启动程序

    Reboot Linux system. Run Terminal: $ ls /dev/tty* The we can see the device is detected by Linux Host OS: 【技术】Ubuntu下USB转串口芯片驱动程序安装cp210x,pl2303 Reference: ...

    HMC配置及操作手册范本.doc

    备份方法:登陆 HMC 后,选择 Back up Critical Concole Data 之后选择是备份到随 HMC 来的 DVD-RAM 上,还是远程服务器上。 #### 3.3.4 从备份中恢复 HMC 重要数据(Critical Console Data) 从 DVD-RAM 中恢复当...

    Senfore_DragDrop_v4.1

    Linux and Kylix are not supported. There are *NO* plans to port the library to Kylix. The drag and drop protocols available on Linux are too much of a mess at this time. ----------------------------...

Global site tag (gtag.js) - Google Analytics