]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - etc/periodic/daily/220.backup-pkgdb
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / etc / periodic / daily / 220.backup-pkgdb
1 #!/bin/sh
2 #
3 # $FreeBSD$
4 #
5
6 # If there is a global system configuration file, suck it in.
7 #
8 if [ -r /etc/defaults/periodic.conf ]
9 then
10     . /etc/defaults/periodic.conf
11     source_periodic_confs
12 fi
13
14 rc=0
15
16 case "$daily_backup_pkgdb_enable" in
17     [Yy][Ee][Ss])
18         bak="${daily_backup_pkgdb_dir:-/var/backups}"
19         bak_file="${bak}/pkgdb.bak.tbz"
20
21         pkg_dbdir=`make -f/usr/share/mk/bsd.port.mk -V PKG_DBDIR 2>/dev/null` ||
22           pkg_dbdir=/var/db/pkg
23
24         if [ ! -d "$bak" ]
25         then
26             install -d -o root -g wheel -m 750 $bak || {
27                 echo '$daily_backup_pkgdb_enable is enabled but' \
28                     "$daily_backup_pkgdb_dir doesn't exist" ;
29                 exit 2 ; }
30         fi
31
32         echo ''
33         echo 'Backing up package db directory:'
34
35         new_bak_file=`mktemp ${bak_file}-XXXXX`
36
37         if tar -cjHf "${new_bak_file}" "$pkg_dbdir" 2>/dev/null; then
38             chmod 644 "${new_bak_file}"
39
40             if [ -e "${bak_file}.2" -a -e "${bak_file}" ]; then
41                 unlink "${bak_file}.2"
42                 mv "${bak_file}" "${bak_file}.2"
43             fi
44             [ -e "${bak_file}" ] && mv "${bak_file}" "${bak_file}.2"
45             mv "${new_bak_file}" "${bak_file}"
46         else
47             rc=3
48         fi ;;
49 esac
50
51 exit $rc