Centos系統備份與恢復

Centos系統備份與恢復

  linux全部的東西都是文件,基於這一點,備份和還原仍是比較簡單方便的。習慣用三種命令:tar,dd,rsync。詳細的用法能夠man。 html

  一、make a backup filelinux

  #man tarpost

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

   orthis

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

  2. restore from the backup filecode

  #cp backup.tgz /htm

  #tar xvpfz backup.tgz -C /blog

  orip

  #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################################

相關文章
相關標籤/搜索