首页 > 代码库 > Linux系统备份还原脚本

Linux系统备份还原脚本

\

#!/bin/sh#备份linux系统。#命令如:sh 当前脚本.sh /dev/sdax 备份文件名#参数1:备份的盘,备份前先umount。如:/dev/sda1#参数2:备份保存的文件名。if [ $# -ne 2 ]; then    echo "请传入两个参数。"    exit 0fi#当前日期,用于建立临时文件夹和备份文件。datename=`date +%Y%m%d_%H%M%S`#临时挂载的文件夹名称tmpdir="/tmp/dir${datename}"mkdir ${tmpdir}mount ${1} ${tmpdir}#执行备份echo "正在备份系统!"tar cvpzf ${2}${datename}.tgz –exclude=${tmpdir}/proc –exclude=${tmpdir}/backup –exclude=${tmpdir}/lost+found –exclude=${tmpdir}/mnt –exclude=${tmpdir}/sys ${tmpdir}/echo "卸载备份盘!"umount ${tmpdir}echo "删除备份源文件夹!"rmdir ${tmpdir}#参考:http://blog.sina.com.cn/s/blog_48a0f2740100kddw.html#      http://blog.csdn.net/shuibinlang/article/details/1731295#      http://blog.csdn.net/lanmanck/article/details/6035371#      http://www.cnblogs.com/peida/archive/2012/10/24/2737730.html#      http://dadekey.blog.51cto.com/107327/119938/#      http://blog.163.com/sy1984_5_23/blog/static/419093352009510111929258/
#!/bin/sh#还原linux系统。#命令如:sh 当前脚本.sh /dev/sdax 备份文件.tgz#参数1:还原的盘,还原前先umount。如:/dev/sda1#参数2:还原的源文件。if [ $# -ne 2 ]; then    echo "请传入两个参数。"    exit 0fi    echo "建立临时文件夹。"datename=`date +%Y%m%d_%H%M%S`tmpdir="/tmp/dir${datename}"mkdir ${tmpdir}echo "挂载还原盘。"mount ${1} ${tmpdir}#执行还原echo "正在还原系统!"tar xvpfz ${2} -C ${tmpdir}/mkdir ${tmpdir}/procmkdir ${tmpdir}/lost+foundmkdir ${tmpdir}/mntmkdir ${tmpdir}/sysmkdir ${tmpdir}/backupecho "卸载备份盘!"umount ${tmpdir}echo "删除临时文件夹"rmdir ${tmpdir}echo "完成系统还原!"#参考:http://blog.sina.com.cn/s/blog_48a0f2740100kddw.html