首页 > 代码库 > shell dd备份系统

shell dd备份系统

备份MBR、根分区、Boot分区

#!/bin/bash

Bak_dir=/mnt   #已挂载的移动硬盘或其他外设

Mbr=`fdisk -l |grep "Disk" |awk NR==1‘{print $2}‘ |awk -F"/" ‘{print $3}‘|sed s/://g`

Root=`df |awk ‘/\//{print $1}‘ |awk NR==1‘{print $1}‘`

Boot=`df |awk ‘/\/boot/{print $1}‘`

### Backup MBR

dd if=/dev/$Mbr of=$Bak_dir/mbr.img bs=512 count=1

### Backup Root [/]

dd if=$Root |gzip >$Bak_dir/root.img.gz

### Backup Boot [/boot]

dd if=$Boot |gzip >$Bak_dir/boot.img.gz


shell dd备份系统