Re: ubuntu PE (8.10)
发表于 : 2009-02-08 17:27
还有 swap 、 /home 的啊
还有一个 proc 什么的
除此之外也就没啥要添加的了吧??
还有一个 proc 什么的
除此之外也就没啥要添加的了吧??
代码: 全选
#!/bin/sh
workingdir=`uuidgen`
resultdir=`uuidgen`
mypath=$0
myname=`basename "$mypath"`
packagecheck(){
dpkg -s squashfs-tools > /dev/null 2>&1 || { echo "squashfs-tools is required to run this program."; exit 1; }
}
rebuildtree(){
mkdir /$workingdir
mount --bind / /$workingdir
mount --bind /boot /$workingdir/boot
mount --bind /home /$workingdir/home
mount --bind /tmp /$workingdir/tmp
mount --bind /usr /$workingdir/usr
mount --bind /var /$workingdir/var
mount --bind /srv /$workingdir/srv
mount --bind /opt /$workingdir/opt
mount --bind /usr/local /$workingdir/usr/local
}
destroytree(){
umount /$workingdir/usr/local
umount /$workingdir/opt
umount /$workingdir/srv
umount /$workingdir/var
umount /$workingdir/usr
umount /$workingdir/tmp
umount /$workingdir/home
umount /$workingdir/boot
umount /$workingdir
rmdir /$workingdir
}
checkdir(){
[ "${1#/}" = "$1" ] && { echo "You must specify the absolute path"; exit 1; }
[ -d "$*" ] || { echo "$* does not exist, or is not a directory"; exit 1; }
}
dobackup(){
packagecheck
echo "You are about to backup your system. It is recommended that you quit all open applications now. Continue?(y/n)"
read yn
[ "$yn" != "y" ] && exit 1
echo "Specify a directory(absolute path) to save the backup. If you don't specify, /$resultdir will be used"
read backupdir
# 脱引号
[ "${backupdir#'}" != "$backupdir" ] && [ "${backupdir%'}" != "$backupdir" ] && { backupdir="${backupdir#'}"; backupdir="${backupdir%'}"; }
[ "$backupdir" != "" ] && { checkdir $backupdir; resultdir="${backupdir#/}"; }
ls "/$resultdir/backup.squashfs" > /dev/null 2>&1 && { echo "Error: /$resultdir/backup.squashfs already exists"; exit 1; }
mkdir -p "/$resultdir"
rebuildtree
mksquashfs /$workingdir "/$resultdir/backup.squashfs" -e "$myname" "$resultdir" "$workingdir" boot/grub etc/fstab lost+found boot/lost+found home/lost+found tmp/lost+found usr/lost+found var/lost+found srv/lost+found opt/lost+found usr/local/lost+found
destroytree
mksquashfs "$mypath" "/$resultdir/backup.squashfs"
cp /boot/initrd.img-`uname -r` "/$resultdir/initrd.img"
cp /boot/vmlinuz-`uname -r` "/$resultdir/vmlinuz"
echo "Your backup is ready in /$resultdir :)"
}
dorestore(){
echo under construction
}
[ "$(whoami)" != root ] && { echo "Admin rights are required to run this program."; exit 1; }
[ "$*" = -b ] && { dobackup; exit 0; }
[ "$*" = -r ] && { dorestore; exit 0; }
echo "usage"
exit 1
如果还有什么已知的细节,请不吝指教。/rofs/etc/mtab 注意到了。而/etc/blkid.tab 之前不知道。这也是我说“做可启动映像比较麻烦”的原因。你得注意很多细节。