|
发表于 2010-12-21 02:24:19
|
显示全部楼层
更加激进的方法,放进内存。。可选把sync还是local放进内存,或者都放进,只放sync比较安全,这样哪怕突然掉电也仅仅损失同步数据库,重新同步一下就好了。就算都放进去会可能丢失的是本次启动后更新的数据库,因为有备份,下次启动会恢复,还算安全。
通过/etc/conf.d/pacmandb.conf来修改将那个db放入内存,还有整个db的大小限制,这个实际大小是动态的,限制是最大容量。
使用方法只需要将两个文件放入相应位置,然后/etc/rc.d/pacmandb start|stop|restart就可以了。可以放入rc.conf
/etc/rc.d/pacmandb- #!/bin/bash
- . /etc/rc.conf
- . /etc/rc.d/functions
- . /etc/conf.d/pacmandb.conf
- CONFIG=/etc/pacman.conf
- function readconf() {
- match=0
- while read line; do
- # skip comments
- [[ $line =~ ^\ {0,}# ]] && continue
- # skip empty lines
- [[ -z "$line" ]] && continue
- # still no match? lets check again
- if [ $match == 0 ]; then
- # do we have a section tag ?
- if [[ $line =~ ^\[.*?\] ]]; then
- #strip []
- line=${line:1:$((${#line}-2))}
- # strip whitespace
- section=${line// /}
- # do we have a match ?
- if [[ "$section" == "$1" ]]; then
- match=1
- continue
- fi
- continue
- fi
- # found next section after config was read - exit loop
- elif [[ $line =~ ^\[.*?\] && $match == 1 ]]; then
- break
- # got a config line eval it
- else
- var=${line%%=*}
- var=${var// /}
- value=${line##*=}
- value=${value## }
- eval "$var='$value'"
- fi
- done < "$CONFIG"
- }
- readconf options
- [ -z "$DBPath" ] && DBPath=/var/lib/pacman
- case "$1" in
- start)
- stat_busy "Starting pacmandb"
- mount pacman $DBPath -t tmpfs -o rw,noatime,nodiratime,noexec,nosuid,nodev,nouser,size=$DBSize
- chmod 755 $DBPath
- for db in ${DBs[@]}; do
- cd $DBPath
- stat_busy "Restory $db"
- tar xpf ../$db.tar
- if [ $? -gt 0 ];then
- stat_fail
- else
- stat_done
- fi
- cd $OLDPWD
- done
- add_daemon pacmandb
- stat_done
- ;;
- stop)
- stat_busy "Stopping pacmandb"
- for db in ${DBs[@]}; do
- cd $DBPath
- stat_busy "Backup $db"
- tar cpf ../$db.tar $db
- if [ $? -gt 0 ];then
- stat_fail
- else
- stat_done
- fi
- cd $OLDPWD
- done
- umount $DBPath
- rm_daemon pacmandb
- stat_done
- ;;
- restart)
- $0 stop
- $0 start
- ;;
- *)
- echo "usage: $0 {start|stop|restart}"
- esac
- exit 0
复制代码
/etc/conf.d/pacmandb.conf- DBs=('local' 'sync')
- DBSize=100M
复制代码 |
|