#!/sbin/runscript # Copyright 1999-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 opts="dump" description="Backup and restore /var/run directory structure (useful for systems with tmpfs-based /var/run)" description_dump="Creates a backup tarball of /var/run directory structure" [ -e /etc/conf.d/varrun ] && . /etc/conf.d/varrun rc_varrun_tarball="${rc_varrun_tarball:-${RC_VARRUN_TARBALL:-NO}}" rc_varrun_exclude="${rc_varrun_exclude}" varrun_tarball="/var/cache/varrun.tar.bz2" depend() { need localmount } start() { if yesno "${rc_varrun_tarball}" && \ [ -s "${varrun_tarball}" ] then ebegin "Restoring saved /var/run structure" echo # tar -jxpf "${varrun_tarball}" -C /var/run eend $? fi } _stop() { if ! yesno "${rc_varrun_tarball}" || \ ! touch "${varrun_tarball}" 2>/dev/null then return 0 fi ebegin "Saving /var/run structure" # Handle our temp files save_varrun_base=/tmp/varrun.savedirs."$$" varrun_tmp_tarball="${save_varrun_base}"/varrun dirs_exclude="${save_varrun_base}"/dirs.exclude dirs_tosave="${save_varrun_base}"/dirs.tosave dirs_totar="${save_varrun_base}"/dirs.totar files_notar="${save_varrun_base}"/files.notar rm -rf "${save_varrun_base}" mkdir "${save_varrun_base}" touch "${varrun_tmp_tarball}" "${dirs_exclude}" "${dirs_tosave}" "${dirs_totar}" "${files_notar}" if [ -f "${varrun_tmp_tarball}" -a -f "${dirs_exclude}" -a \ -f "${dirs_tosave}" -a -f "${dirs_totar}" -a -f "${files_notar}" ] then cd /var/run # We don't want to save some dirs # You can add to this list via rc_varrun_exclude variable in /etc/conf.d/varrun # All subdirectories of listed directories will be excluded as well if [ -n "${rc_varrun_exclude}" ] then for x in ${rc_varrun_exclude} ; do ls -d1 /var/run/"${x}" | sed -e "s:/var/run/::" >> "${dirs_exclude}" ls -d1 /var/run/"${x}"/* | sed -e "s:/var/run/::" >> "${dirs_exclude}" done fi # We don't want to save any files (PIDs), sockets, pipes etc., only the directory structure cd /var/run find . -xdev -type f -or -type b -or -type c -or -type p -or -type s | \ cut -d/ -f2- >> "${files_notar}" # Now stuff that we want to save find . -xdev -type d | cut -d/ -f2- | grep -v ^\\. > "${dirs_tosave}" fgrep -x -v -f "${dirs_exclude}" "${dirs_tosave}" > "${dirs_totar}" # Lets pack it up if [ -s "${dirs_totar}" ] then # we dont want to descend into mounted filesystems # looking up username may involve NIS/network # and net may be down tar --one-file-system --numeric-owner \ -jcpf "${varrun_tmp_tarball}" -T "${dirs_totar}" -X "${files_notar}" mv -f "${varrun_tmp_tarball}" "${varrun_tarball}" else rm -f "${varrun_tarball}" fi eend 0 else eend 1 "Could not save temporary files!" fi rm -rf "${save_varrun_base}" } stop() { _stop } dump() { _stop }