Centos系统备份与恢复

Centos系统备份与恢复

  linux所有的东西都是文件,基于这一点,备份和还原还是比较简单方便的。习惯用三种命令:tar,dd,rsync。详细的用法可以man。 

  1、make a backup file

  #man tar

  #tar cvpzf backup.tgz / --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys --exclude=/media

   or

  #tar cvpjf backup.tar.bz2 / --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys --exclude=/media
  

  2. restore from the backup file

  #cp backup.tgz /

  #tar xvpfz backup.tgz -C /

  or

  #tar xvpfj backup.tar.bz2 -C /

  #mkdir proc

  #mkdir lost+found

  #mkdir mnt

  #mkdir sys

  #restorecon -Rv /  

  #reboot

  3.make a backup file uses dd

        #man dd

  #dd if=/dev/sda1 of=/dev/sdb1

  4.restore from the backup file:

  #dd if=/dev/sdb1 of=/dev/sda1

  5.make a bakup file uses rsync

  #man rsync

  #rsync -Pa / /media/usb/backup --exclude=/media --exclude=/sys --exclude=/proc --exclude=/mnt --exclude=/tmp

  pay attention to this:

  "

  rsync -avz foo:src/bar /data/tmp

  This would recursively transfer all files from the directory src/bar on the
  machine foo into the /data/tmp/bar directory on the local machine. The files
  are transferred in "archive" mode, which ensures that symbolic links, devices,
  attributes, permissions, ownerships, etc. are preserved in the transfer.
  Additionally, compression will be used to reduce the size of data portions of
  the transfer.

  rsync -avz foo:src/bar/ /data/tmp

  A trailing slash on the source changes this behavior to avoid creating an
  additional directory level at the destination. You can think of a trailing /
  on a source as meaning "copy the contents of this directory" as opposed to
  "copy the directory by name", but in both cases the attributes of the contain‐
  ing directory are transferred to the containing directory on the destination.
  In other words, each of the following commands copies the files in the same
  way, including their setting of the attributes of /dest/foo:

  rsync -av /src/foo /dest
  rsync -av /src/foo/ /dest/foo   

  Note also that host and module references don’t require a trailing slash to
  copy the contents of the default directory. For example, both of these copy
  the remote directory’s contents into "/dest":

  rsync -av host: /dest
  rsync -av host::module /dest

  "

  6.restore from the backup file:

  #rsync -Pa /media/youxia/usb/backup_20141216 /

#######################END################################

posted @ 2019-03-13 10:16  RenBwo  阅读(1458)  评论(0编辑  收藏  举报