\
#!/bin/SH#备份linux系统. #命令如:SHThe current script.SH/dev/Sdax backup file name # parameter 1: Backup disk, umount before backup. such as:/dev/sda1# parameter 2: Backup saved file name. if[$#-ne2]; Then Echo "please pass in two parameters. "Exit0fi#当前日期, used to create temporary folders and backup files. Datename=`Date+%y%m%d_%h%m%S ' #临时挂载的文件夹名称tmpdir="/tmp/dir${datename}"mkdir${tmpdir}Mount${1} ${tmpdir} #执行备份Echo "backing up the system! "TarCvpzf ${2}${datename}.tgz–exclude=${tmpdir}/proc–exclude=${tmpdir}/backup–exclude=${tmpdir}/lost+found–exclude=${tmpdir }/mnt–exclude=${tmpdir}/sys ${tmpdir}/Echo "unmount the backup disk! "Umount${tmpdir}Echo "Delete the backup source folder! "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系统. #命令如:SHThe current script.SH/dev/sdax backup files. tgz# parameter 1: The restored disk, umount before restoring. such as:/dev/sda1# Parameter 2: The restored source file. if[$#-ne2]; Then Echo "please pass in two parameters. "Exit0fi Echo "Create a temporary folder. "Datename=`Date+%y%m%d_%h%m%S ' Tmpdir="/tmp/dir${datename}"mkdir${tmpdir}Echo "mount the restore disk. "Mount${1} ${tmpdir} #执行还原Echo "The system is being restored! "TarXVPFZ ${2}-C ${tmpdir}/mkdir${tmpdir}/procmkdir${tmpdir}/lost+foundmkdir${tmpdir}/mntmkdir${tmpdir}/SYSmkdir${tmpdir}/BackupEcho "unmount the backup disk! "Umount${tmpdir}Echo "Delete Temp Folder"rmdir${tmpdir}Echo "Complete System Restore! "#参考: http://blog.sina.com.cn/s/blog_48a0f2740100kddw.html