LINUX系統備份還原


1、Linux系統備份工具 REAR (RELAX-AND-RECOVER)

https://blog.csdn.net/qq43748322/article/details/78710754?locationNum=2&fps=1

https://www.suse.com/zh-cn/documentation/sle_ha/book_sleha/data/sec_ha_rear_concept.html   

以下是關於backup和rescue備份到同一個ISO的測試過程,供您參考:

~~~ 1. # cat /etc/rear/local.conf

OUTPUT=ISO OUTPUT_URL=file:///10.66.219.236/srv/backup <===

BACKUP=NETFS BACKUP_URL=iso:///10.66.219.236/backup <===

BACKUP_PROG_EXCLUDE=("${BACKUP_PROG_EXCLUDE[@]}" '/media' '/var/tmp' '/var/crash')

NETFS_KEEP_OLD_BACKUP_COPY= ISO_MAX_SIZE=4000 <===

2. # rear -v mkbackup

 

3. # ls -lugh /10.66.219.236/srv/backup/mail/ //生成多個文件

total 4.9G -rw------- 1 root 202 Aug 22 04:36

README -rw------- 1 root 194K Aug 22 04:36

rear.log -rw------- 1 root 973M Aug 22 05:39

rear-mail_01.iso -rw------- 1 root 4.0G Aug 22 05:40

rear-mail.iso -rw------- 1 root 283 Aug 22 04:36 VERSION

4. 將ISO文件拷貝到本地,然后創建新的虛擬機並按照順序打開iso文件,在恢復過程中會提示更換iso文件,更換完成后,繼續恢復,結果顯示,系統正常恢復; ~~~

*****

showmount -e *.*.1.80 查看機器的所有共享目錄。


 

2、How to backup and restore a whole Red Hat Enterprise Linux system with the dump/restore commands?

阿里雲詳解:https://www.aliyun.com/jiaocheng/205464.html
 SOLUTION 已驗證 - 已更新 2016年二月22日17:04 - 

環境

  • Red Hat Enterprise Linux 4
  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7
  • ext2, ext3 or ext4 filesystem
  • dump and restore

問題

  • How to backup and restore a whole Red Hat Enterprise Linux system with the dump/restore commands?
  • Need to migrate, upgrade, or perform disaster recovery on the OS, how to create a backup image?
  • Is it possible to take complete back of OS+ application in RHEL like ignite or system state back up?

決議

1. Introduction

This article shows a test in which a whole Red Hat Enterprise Linux 5.2 system is backed-up to another disk partition, the files system is then destroyed using fdisk (to simulate a disk failure), and finally the system is restored successfully. All the steps can also be used for Red Hat Enterprise Linux 4.

NOTE 1: Since there are different kinds of storage, we could not make detailed test on them, and also consider that any mistake will destroy the system and difficult to recover, so we STRONGLY RECOMMEND to test all the steps on a test machine.

NOTE 2:Since there is now a GPT partitions you may use parted instead of fdisk.

2. Configuration Procedure

Backup Using Dump

  1. All data must be backed up before attempting any kind of restore operation. Data backups should be made on a regular basis. In addition to data, there is configuration information that should be saved, including "/etc/fstab" and the output of "fdisk -l". Running a sosreport/sysreport will capture this information and is strongly recommended.

    Raw
    # cat /etc/fstab
    LABEL=/                 /                       ext3    defaults        1 1
    LABEL=/boot1            /boot                   ext3    defaults        1 2
    LABEL=/data             /data                   ext3    defaults        0 0
    tmpfs                   /dev/shm                tmpfs   defaults        0 0
    devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
    sysfs                   /sys                    sysfs   defaults        0 0
    proc                    /proc                   proc    defaults        0 0
    LABEL=SWAP-sda5         swap                    swap    defaults        0 0
    /dev/sda6               /backup-files           ext3    defaults        0 0
    
    # fdisk -l
       Device Boot    Start      End    Blocks      Id  System
    /dev/sda1 *           1       13    104391      83  Linux
    /dev/sda2            14      1925   15358140    83  Linux
    /dev/sda3          1926      3200   10241437+   83  Linux
    /dev/sda4          3201      4864   13366080    5   Extended
    /dev/sda5          3201      3391   1534176     82  Linux swap / Solaris
    /dev/sda6          3392      4864   11831841    83  Linux
    

    In this example, we will use the /dev/sda6 partition to save backup files, and we assume that /dev/sda6 is mounted on /backup-files.

  2. Bootup your system into Single User Mode

  3. Use "dump" to backup the contents of the partitions:

    Notes

    • If the system has been running for a long time, it is advisable to run e2fsck on the partitions before backup.
    • dump should(may) not be used at heavily loaded and mounted filesystem as it could backup corrupted version of files. This problem has been mentioned on dump.sourceforge.net and Red Hat Manual

      Raw
      # dump -0uf /backup-files/sda1.dump /dev/sda1
      # dump -0uf /backup-files/sda2.dump /dev/sda2
      # dump -0uf /backup-files/sda3.dump /dev/sda3
      

    If you want to do a remote backup, you can use both ssh or configure a non-password login. For information on how to configure ssh for a non-password login, please see How do you set-up SSH with DSA public key authentication?
    Note: If using standard redirection, the '-f' option must be passed separately.

    Raw
    # dump -0u -f - /dev/sda1 | ssh root@remoteserver.example.com dd of=/tmp/sda1.dump
    
  4. We then simulate a disk failure by using fdisk to delete the partitions that have been backed up.

    Notice: DO NOT delete /dev/sda6 because it saves our backup files. In general, backup files should of course be stored on in a different location.

Restoring the Backed-Up Data

  1. Bootup your system into Rescue Mode

  2. Rebuild sda1/sda2/sda3/sda4/sda5 by using the fdisk command

    Notice: When rebuild all the partitions, please use the same "Start" and "End" number as before.

  3. format sda1/sda2/sda3/sda5 by using the mkfs command, as shown below.

    Notice: DO NOT format /dev/sda6 because it saves backup files.

    Raw
    # mkfs.ext3 /dev/sda1
    # mkfs.ext3 /dev/sda2
    # mkfs.ext3 /dev/sda3
    
  4. Re-label all the partitions so they match how they were before. This step is important for the restore to work.

    Raw
    # e2label /dev/sda1 /boot1
    # e2label /dev/sda2 /
    # e2label /dev/sda3 /data
    # mkswap -L SWAP-sda5 /dev/sda5
    
  5. Prepare the working directories

    Raw
    # mkdir /mnt/sda1
    # mount -t ext3 /dev/sda1 /mnt/sda1
    # mkdir /mnt/sda2
    # mount -t ext3 /dev/sda2 /mnt/sda2
    # mkdir /mnt/sda3
    # mount -t ext3 /dev/sda3 /mnt/sda3
    # mkdir /backup-files
    # mount -t ext3 /dev/sda6 /backup-files
    
  6. Restore the data

    Raw
    # cd /mnt/sda1
    # restore -rf /backup-files/sda1.dump
    # cd /mnt/sda2
    # restore -rf /backup-files/sda2.dump
    # cd /mnt/sda3
    # restore -rf /backup-files/sda3.dump
    

    If want remote restore, you can use both ssh or rsh, maybe you need to configure a none-password login, the following is examples:

    login into 10.0.0.87, and restore sda1 from local sda1.dump file:

    Raw
    # ssh 10.0.0.87 "cd /mnt/sda1 && cat /backup-files/sda1.dump | restore -rf -"
    

    login into 10.0.0.87, and restore sda1 from a remote 10.66.0.124 sda1.dump file:

    Raw
    # ssh 10.0.0.87 "cd /mnt/sda1 && RSH=/usr/bin/ssh restore -r -f 10.66.0.124:/tmp/sda1.dump"
    
  7. Reboot

3. Other Notices

  1. dump/restore command can only be used for ext2/ext3/ext4 partitions, some IA64 system has a boot partition in vfat format, tar command can be used to backup a vfat partition.

    The ext4 filesystem is supported by dump/restore command only in Red Hat Enterprise Linux 6:
    Is dump available for ext4 file systems on RHEL 6?

    Red Hat Enterprise Linux 5 dump program does not support the ext4 file system.

  2. The MBR is not backup for it is not belong to any partition! So, if you backup your system to another disk, the system is not able to boot up. Please run grub-install in rescue mode first.

  3. Some system will setting immunity flag on some important files which means these files could not be deleted/modified/overwrited even by root user, so restore will failed to overwrite these file and output "Permission Denied" error. In this situation, before restore the system, please find out the files have immunity flag with lsattr command, and remove the immunity flag with "chattr -i" command.

  4. You can backup your data to tape device, another hard disk or another disk partition, just change the dump file name to tape device like following:

    Raw
    # dump -0uf /dev/st0 /dev/sda1
    
  5. When use tape device, you need mt command to control forward/backward of tape, please take care of the operation order to make sure the right data is restored into a right partition.

  6. There are some factors can influence the backup/restore, such as the tape device' driver, type(rewind/non-rewind), and the size of data block, so I suggest you to use the same tape device in backup and restore.

  7. In the test of this article selinux is enabled, and some files' selinux property have been modified, but seems everything can be restored correctly.

  8. At last, only one dump/restore can not ensure the data security of your system, the real data security need some detail security policy and backup policy.

  9. If the root partition is a lvm partition. When restoring the root partition, you should run in the rescue mode.
    and do the things as follows.

    Raw
    # vgscan 
    # vgchange -ay VolGroup
    # mount  /dev/VolGroup/lv_root  /mnt/sysimage
    # cd /mnt/sysimage
    # restore -rf <the dump file of root partition>
    
  10. For how to backup and restore partition table, please refer to How can I backup and restore partition table?

 


 


 

中文顯示:

如何通過 dump/restore 命令備份和恢復整個 Red Hat Enterprise Linux 系統?

 SOLUTION IN PROGRESS - 已更新 2015年四月23日17:49 - 

環境

  • Red Hat Enterprise Linux 4
  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7
  • ext2, ext3 or ext4 文件系統
  • dump 和 restore

問題

  • 如何通過 dump/restore 命令備份或恢復整個 Red Hat Enterprise Linux (RHEL) 系統?
  • 需要在需要進行 OS 遷移,升級或者災難恢復,該如何創建一個備份鏡像文件?

決議

1. 說明

該文檔介紹了一個測試案例。將一個 RHEL 5.2 的系統備份到另一個磁盤,然后使用 fdisk 命令(模擬磁盤故障)破壞該文件系統,並最終成功恢復該系統。注,以下所有步驟均適用於 RHEL 4。

注意: 由於存儲的方式有很多,我們無法針對每一種情況進行詳細測試。此外,由於操作過程中出現的問題可能會損壞系統且難以恢復,所以我們 強烈建議 您在測試機上執行以下步驟。

2. 配置步驟

使用 Dump 備份數據

  1. 在您執行任何恢復數據的操作之前,請務必備份數據,而且您應該定期備份數據。 除了數據,您還需要保存一些配置信息,包括"/etc/fstab" 和 "fdisk -l" 的輸出結果。我們強烈建議您執行sosreport/sysreport 來捕獲這些信息。

    Raw
    # cat /etc/fstab
    LABEL=/                 /                       ext3    defaults        1 1
    LABEL=/boot1            /boot                   ext3    defaults        1 2
    LABEL=/data             /data                   ext3    defaults        0 0
    tmpfs                   /dev/shm                tmpfs   defaults        0 0
    devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
    sysfs                   /sys                    sysfs   defaults        0 0
    proc                    /proc                   proc    defaults        0 0
    LABEL=SWAP-sda5         swap                    swap    defaults        0 0
    /dev/sda6               /backup-files           ext3    defaults        0 0
    
    # fdisk -l
       Device Boot    Start      End    Blocks      Id  System
    /dev/sda1 *           1       13    104391      83  Linux
    /dev/sda2            14      1925   15358140    83  Linux
    /dev/sda3          1926      3200   10241437+   83  Linux
    /dev/sda4          3201      4864   13366080    5   Extended
    /dev/sda5          3201      3391   1534176     82  Linux swap / Solaris
    /dev/sda6          3392      4864   11831841    83  Linux
    

    在這個例子中,我們使用 /dev/sda6 分區來存儲備份的文件,而且我們假設該分區掛載在 /backup-files 目錄下。

  2. 啟動系統,使其運行在 單用戶模式 下。

  3. 使用 "dump" 備份分區里的內容:

    注意

    • 如果該系統已經運行了很長時間,我們建議您在備份數據之前對該分區執行 e2fsck 命令。
    • 由於可能會備份修改中的文件,所以請不要在系統高負荷運轉或者文件系統被掛載時,使用 dump。dump.sourceforge.net 和 Red Hat Manual里提到了這個問題。

      Raw
      # dump -0uf /backup-files/sda1.dump /dev/sda1
      # dump -0uf /backup-files/sda2.dump /dev/sda2
      # dump -0uf /backup-files/sda3.dump /dev/sda3
      

    如果您想在將數據備份到其他服務器的磁盤上,您可以使用 ssh ,且通過更改配置使之登錄時不需要密碼。關於如何配置免密碼登錄 ssh,請參考 How do you set-up SSH with DSA public key authentication?
    注: 如果您想使用標准重定向,-f 參數必須單獨書寫。

    Raw
    # dump -0u -f - /dev/sda1 | ssh root@remoteserver.example.com dd of=/tmp/sda1.dump
    
  4. 然后我們可以通過使用 fdisk 命令來刪除已經備份好的分區,模擬磁盤故障。

    注意: 不要刪除 /dev/sda6,因為它存有我們備份的文件。一般情況下,備份的文件應該保存在不同的位置。

Restoring the Backuped Data

  1. 啟動系統進入 救援模式

  2. 通過 fdisk 命令重新創建 sda1/sda2/sda3/sda4/sda5 分區。

    注意: 在重新創建分區時,請使用與之前一樣的 "Start" 和 "End" 號。

  3. 使用 mkfs 命令格式化 sda1/sda2/sda3/sda5 ,如下所示:

    注意: 不要格式化 /dev/sda6,因為它存有備份文件。

    Raw
    # mkfs.ext3 /dev/sda1
    # mkfs.ext3 /dev/sda2
    # mkfs.ext3 /dev/sda3
    
  4. 重新給所有分區貼標簽,這樣它們就可以與之前所匹配。這一步對於恢復工作來說至關重要。

    Raw
    # e2label /dev/sda1 /boot1
    # e2label /dev/sda2 /
    # e2label /dev/sda3 /data
    # mkswap -L SWAP-sda5 /dev/sda5
    
  5. 創建需要用來掛載分區的目錄

    Raw
    # mkdir /mnt/sda1
    # mount -t ext3 /dev/sda1 /mnt/sda1
    # mkdir /mnt/sda2
    # mount -t ext3 /dev/sda2 /mnt/sda2
    # mkdir /mnt/sda3
    # mount -t ext3 /dev/sda3 /mnt/sda3
    # mkdir /backup-files
    # mount -t ext3 /dev/sda6 /backup-files
    
  6. 恢復數據

    Raw
    # cd /mnt/sda1
    # restore -rf /backup-files/sda1.dump
    # cd /mnt/sda2
    # restore -rf /backup-files/sda2.dump
    # cd /mnt/sda3
    # restore -rf /backup-files/sda3.dump
    

    如果您想備份到遠程存儲上,您可以使用 ssh 或者 rsh。請參考以下實例配置無密碼登錄。

    login into 10.0.0.87, and restore sda1 from local sda1.dump file:

    Raw
    # ssh 10.0.0.87 "cd /mnt/sda1 && cat /backup-files/sda1.dump | restore -rf -"
    

    login into 10.0.0.87, and restore sda1 from a remote 10.66.0.124 sda1.dump file:

    Raw
    # ssh 10.0.0.87 "cd /mnt/sda1 && RSH=/usr/bin/ssh restore -r -f 10.66.0.124:/tmp/sda1.dump"
    
  7. 重啟

3. 注意事項

  1. dump/restore 命令只能用於 ext2/ext3/ext4 分區,有些 IA64 系統的 boot 分區是 vfat 格式,此時您可以使用 tar 命令備份 vfat 分區。

    對於 ext4 文件系統進行 dump/restore 命令,僅僅在RHEL6 上是被支持的
    Is dump available for ext4 file systems on RHEL 6?

    對於 ext4 文件系統進行 dump/restore 命令,在RHEL5上是不被支持的

  2. 由於 MBR 不屬於任何分區,它不會被備份。所以,如果您將系統備份到另一塊磁盤,該系統將不能啟動。進入救援模式后,請先執行 grub-install。

  3. 某些系統在一些重要的文件上設置了 immunity 標簽,這表明即使是 root 用戶也不能刪除/修改/覆蓋這些文件,所以當恢復系統時會因為覆蓋這些文件而導致失敗並且輸出 "Permission Denied" 的報錯信息。這種情況下,在恢復系統之前,請通過 lsattr 命令找出有 immunity 標簽的文件,然后通過 "chattr -i" 命令移除 immunity 標簽。

  4. 您可以將您的數據備份到磁帶設備,其他硬盤或者其他磁盤分區上。您只需要將轉儲文件名改為磁帶設備,如下所示:

    Raw
    # dump -0uf /dev/st0 /dev/sda1
    
  5. 當您使用磁帶設備時,您需要使用 mt 命令控制磁帶的前進/后退。請注意操作順序以確保正確的數據被恢復到正確的分區。

  6. 由於某些因素可能會影響系統的備份/恢復,比如磁帶設備驅動,類型(重繞/非重繞)以及數據塊的大小,所以我們建議您使用相同的磁帶設備用來行進備份和恢復。

  7. 在該測試案例中,selinux 設成了 enable,而且修改了某些文件的 selinux 屬性,但是仍可以正確恢復系統數據。

  8. 最后,僅僅通過 dump/restore 不能保證您系統的數據安全,真正的數據安全需要一些具體的安全和備份的策略。

  9. 如果根分區是 lvm 分區,當您恢復根分區時,請在救援模式下運行系統,並按照以下步驟操作。

    Raw
    # vgscan 
    # vgchange -ay VolGroup
    # mount  /dev/VolGroup/lv_root  /mnt/sysimage
    # cd /mnt/sysimage
    # restore -rf <the dump file of root partition>
    
  10. 關於如何備份和恢復分區表,請參考 How can I backup and restore partition table?

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM