Arch ramdisk-script 1.4
In meinem Arch Ramdisk-Script <1.4 hatte sich ein dämlicher Bug eingeschlichen: bei sämtlichen rsync-Aufrufen fehlte das --delete.
Das bewirkt z.B. bei Verwendung mit Firefox, dass der Cache nie geleert wird und (streng) monoton wächst – unschön.
Hier die gefixte Version
#!/bin/sh # # Manages outsourcing of specified directories into memory on bootup and # takes care of synchronization/backup on system shutdown. # # Version 1.4, 2010-04-26, by Alexander Koch # # includes . /etc/rc.conf . /etc/rc.d/functions # configuration (syntax is: [persist. storage]:[mountpoint]:[mount options]) DISKS=('/home/alex/.ramdisks/_mozilla:/home/alex/.mozilla:size=100M,uid=1000,gid=100' \ 'empty:/home/alex/.adobe:size=10M,uid=1000,gid=100' \ 'empty:/home/alex/.macromedia:size=10M,uid=1000,gid=100') # helper functions function activate_rd() { [ -d "$1" ] || [ "$1" = "empty" ] || return 1 [ -d "$2" ] || return 1 mount | grep "$2" &>/dev/null && return 1 MNT="mount -t tmpfs" [ -z "$3" ] || MNT="$MNT -o $3" $MNT none "$2" [ $? -gt 0 ] && return 1 if [ "$1" != "empty" ]; then for D in $1/.* $1/*; do [ "$(basename "$D")" == "." ] && continue [ "$(basename "$D")" == ".." ] && continue rsync -axq "$D" "$2" &>/dev/null if [ $? -gt 0 ]; then umount "$2" return 1 fi done fi return 0 } function backup_rd() { mount | grep "$1" &>/dev/null || return 0 if [ "$2" != "empty" ]; then for D in $1/.* $1/*; do [ "$(basename "$D")" == "." ] && continue [ "$(basename "$D")" == ".." ] && continue rsync -axq --delete "$D" "$2" &>/dev/null if [ $? -gt 0 ]; then tar -cf "/root/$(basename "$2")-failed.tar" "$1" return 1 fi done fi umount "$1" || return 1 return 0 } # main logic case $1 in start) stat_busy "Mounting ramdisks" error=0 for M in ${DISKS[@]}; do FROM="$(echo "$M" | cut -d ':' -f 1)" TO="$(echo "$M" | cut -d ':' -f 2)" OPTS="$(echo "$M" | cut -d ':' -f 3)" activate_rd "$FROM" "$TO" "$OPTS" || error=1 done if [ $error -eq 0 ]; then add_daemon ramdisks stat_done else stat_fail exit 1 fi ;; stop) stat_busy "Saving ramdisks" error=0 for M in ${DISKS[@]}; do FROM="$(echo "$M" | cut -d ':' -f 2)" TO="$(echo "$M" | cut -d ':' -f 1)" backup_rd "$FROM" "$TO" || error=1 done if [ $error -eq 0 ]; then rm_daemon ramdisks stat_done else stat_fail echo -n "WARNING: failed to save ramdisk(s), tried to make " echo "backup(s) under /root." echo "Hit enter to proceed shutdown." read DUMMY exit 1 fi ;; restart) if ! ck_daemon ramdisks; then "$0" stop && sleep 3 fi "$0" start ;; *) echo "usage: $0 {start|stop|restart}" ;; esac exit 0
Keine Kommentare
Noch keine Kommentare vorhanden.
RSS-Feed für Kommentare zu diesem Artikel. TrackBack URI