svn commit: r220020 - in head/etc: defaults periodic/daily
Doug Barton
dougb at FreeBSD.org
Sat Mar 26 03:01:48 UTC 2011
Author: dougb
Date: Sat Mar 26 03:01:48 2011
New Revision: 220020
URL: http://svn.freebsd.org/changeset/base/220020
Log:
Add a daily period script to back up /var/db/pkg
The final product contains work from the originator, and
Florent Thoumie <florent.thoumie at gmail.com>. The final
product contains considerable re-working by me, so all
responsibility for bugs rests under my pointy hat.
PR: ports/145957
Submitted by: Eitan Adler <EitanAdlerList at gmail.com>
Added:
head/etc/periodic/daily/220.backup-pkgdb (contents, props changed)
Modified:
head/etc/defaults/periodic.conf
Modified: head/etc/defaults/periodic.conf
==============================================================================
--- head/etc/defaults/periodic.conf Sat Mar 26 02:52:04 2011 (r220019)
+++ head/etc/defaults/periodic.conf Sat Mar 26 03:01:48 2011 (r220020)
@@ -74,6 +74,10 @@ daily_backup_passwd_enable="YES" # Bac
# 210.backup-aliases
daily_backup_aliases_enable="YES" # Backup mail aliases
+# 220.backup-pkgdb
+daily_backup_pkgdb_enable="YES" # Backup /var/db/pkg
+daily_backup_pkgdb_dir="/var/backups"
+
# 300.calendar
daily_calendar_enable="NO" # Run calendar -a
Added: head/etc/periodic/daily/220.backup-pkgdb
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/etc/periodic/daily/220.backup-pkgdb Sat Mar 26 03:01:48 2011 (r220020)
@@ -0,0 +1,50 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+
+# If there is a global system configuration file, suck it in.
+#
+if [ -r /etc/defaults/periodic.conf ]
+then
+ . /etc/defaults/periodic.conf
+ source_periodic_confs
+fi
+
+rc=0
+
+case "$daily_backup_pkgdb_enable" in
+ [Yy][Ee][Ss])
+ bak="${daily_backup_pkgdb_dir:-/var/backups}"
+ bak_file="${bak}/pkgdb.bak.tbz"
+
+ pkg_dbdir=`make -f/usr/share/mk/bsd.port.mk -V PKG_DBDIR 2>/dev/null`
+
+ if [ ! -d "$bak" ]
+ then
+ install -d -o root -g wheel -m 750 $bak || {
+ echo '$daily_backup_pkgdb_enable is enabled but' \
+ "$daily_backup_pkgdb_dbdir doesn't exist" ;
+ exit 2 ; }
+ fi
+
+ echo ''
+ echo 'Backing up package db directory:'
+
+ new_bak_file=`mktemp ${bak_file}-XXXXX`
+
+ if tar -cjf "${new_bak_file}" "$pkg_dbdir"; then
+ chmod 644 "${new_bak_file}"
+
+ if [ -e "${bak_file}.2" -a -e "${bak_file}" ]; then
+ unlink "${bak_file}.2"
+ mv "${bak_file}" "${bak_file}.2"
+ fi
+ [ -e "${bak_file}" ] && mv "${bak_file}" "${bak_file}.2"
+ mv "${new_bak_file}" "${bak_file}"
+ else
+ rc=3
+ fi ;;
+esac
+
+exit $rc
More information about the svn-src-head
mailing list