linux备份与恢复系统 - graybull's Blog

linux备份与恢复系统

graybull posted @ 2013年4月16日 14:12 in Unix/Linux with tags linux tar dd backup dump , 3499 阅读
  • tar命令(目录级)
  • dump命令(文件系统级)
  • dd命令

1.tar命令(目录级)

备份与恢复某一目录下的全部内容(可去掉不需要的目录或文件)

备份命令:

tar –cjvpf 备份结果文件名 需备份的目录名 --exclude=不需要备份的目录名或文件

选项-c:创建一个文件,用于存放备份结果

    -j:对tar结果进行压缩,比zip效率更高

    -v:显示备份清单

    -p:保持文件和目录的原属性

    -f:备份结果文件

实例:

tar -cjvpf /media/backup/78/78_`date +'%Y%m%d'`_root.tar.bz2 / \

 --exclude='/sys' --exclude='/proc' --exclude='/media' --exclude='/mnt' \

 --exclude='/tmp' --exclude='lost+found' \

 1> /media/backup/78/78_`date +'%Y%m%d'`_bk_lst.log \

 2> /media/backup/78/78_`date +'%Y%m%d'`_bk_err.log 

注解:该tar命令备份根目录下所有内容,但去掉下列内容:

(1)所有虚拟文件系统挂载的目录,例:/sys,/proc

(2)所有明确不需要备份的目录,例:/tmp,lost+found

(3)所有介质挂载目录(如果没有挂载可不用去掉),例:/media,/mnt

(4)用户应用中已确定不需要备份的目录或文件(文件的去除格式为--exclude='/xxx/文件前缀*'),例:备份文件,log文件等

*_bk_lst.log文件用于记录备份文件/目录清单

*_bk_err.log 文件用于记录备份出错的文件/目录清单   

恢复命令:

    tar -jxvfC xxxx.tar.gz 目标目录名

实例:

tar –jxvfC root.tar.bz2 /

注解:-x:恢复

-C:指定绝对恢复的目录名

该命令将覆盖原目录(此例为根目录)中所有内容,恢复后需要重启系统。

2.dump命令(文件系统级)

备份:

用df列出所有文件系统及挂载目录,依次将需要备份的文件系统做全备份:

#df

Filesystem           1K-blocks      Used Available Use% Mounted on

/dev/sda2            138022764   8153372  122744968   7% /

/dev/sda1               101086     12445     83422  13% /boot

tmpfs                  1037728         0   1037728   0% /dev/shm

/dev/sdb1             140000000  8000123   13000232    7% /backup

将根文件系统备份到/backup/root.dump文件

dump  -0f /backup/root.dump /

将/boot文件系统备份到/backup/boot.dump文件

dump  -0f /backup/boot.dump /boot

注解:-0:0级备份,即全备份

      -f:备份结果文件,注意不要放在同一个文件系统中

查看备份结果:

restore –tf /backup/root.dump

恢复:

(1)重建整个文件系统:

重建根文件系统:

restore -rf /backup/root.dump

重建/boot文件系统:

restore -rf /backup/boot.dump

(2)抽取个别文件或目录:

从根文件系统的备份文件中恢复/etc目录

restore -xf /backup/root.dump /etc

3.dd命令

完整复制磁盘全部内容到一个文件。

备份

dd if=/dev/sdb of=/media/backup/sda.disk

注解:本命令将系统的第2块SCSI硬盘复制到文件名为sda.disk的文件中。

恢复:

dd if=/media/backup/sda.disk of=/dev/sdb

注解:本命令将文件名为sda.disk的文件内容复制到系统的第2块SCSI硬盘。

4.远程备份/恢复命令

(待)

转自:http://wenku.baidu.com/view/c65b003043323968011c92aa.html

Avatar_small
run 3 说:
2019年11月21日 16:19

I think this is one of the best blogs for me because this is really helpful for me. Thanks for sharing this valuable information for free.

Avatar_small
hotmail login 说:
2019年12月19日 23:35

I loved the way you discuss the topic great work thanks for the share.

Avatar_small
AP 10th Physics Mode 说:
2022年9月15日 03:46

Physical Science is the part of Science known as Physics (PS), every student in class 10th grade studying at Government & Private Schools of the state board can download the AP SSC PS Model Paper 2023 with answers for all topics of the course designed by the board experts based on the new revised syllabus and curriculum of the BSEAP. Either Telugu medium, English medium and Urdu medium students of class 10th can download the AP SSC Physics model papers 2023 to practice with regular revisions and mock tests. AP 10th Physics Model Paper Class teachers and leading institutional experts are prepared those AP 10th Class PS Model Paper 2023 Pdf with answers that support all exam formats of the board such as Summative Assessments (SA-1 & SA-2) and Formative assessments (FA-1, FA- 2, FA-3, FA-4) along with Assignments.

Avatar_small
Alyssa 说:
2022年12月13日 23:57

There are a few things to consider when backing up and restoring a Linux system. First, what kind of data do you need to backup? This can include personal files, system files, or both. Second, what is the best way to backup this data? There are many options, such as using an external hard drive, a cloud service, or a Linux backup utility. Third, how often do you need to backup your data? This will depend on how often you make changes to your system or files. Finally, when restoring your real estate agent Phoenix system, you will need to consider how you will restore your data. This can be done from a backup, from a clean install, or from a live system.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee