Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Style
Baptiste Daroussin committed 11 years ago
commit 4dc33efea0fa2a3cbce1fde43d18c771973a09f9
parent bd40583
1 file changed +68 -70
modified scripts/periodic/411.pkg-backup.in
@@ -12,100 +12,98 @@ rc=0


backup_pkg() {
-
    local pkgargs="$1"
-
    local bak_file="$2"
-
    local rc
-

-
    [ -e "${bak_file}" ] && \
-
	mv -f "${bak_file}" "${bak_file}.2"
-

-
    if ${pkgcmd} ${pkgargs} shell .dump | xz -c > ${bak_file}; then
-
	rc=0
-
    else
-
	rc=3
-
    fi
-
    
-
    return $rc
+
	local pkgargs="$1"
+
	local bak_file="$2"
+
	local rc
+

+
	[ -e "${bak_file}" ] && \
+
		mv -f "${bak_file}" "${bak_file}.2"
+

+
	if ${pkgcmd} ${pkgargs} shell .dump | xz -c > ${bak_file}; then
+
		rc=0
+
	else
+
		rc=3
+
	fi
+

+
	return $rc
}

backup_pkg_all() {
-
    local bak=$1
-
    local last_rc
+
	local bak=$1
+
	local last_rc
+

+
	: ${daily_backup_pkg_chroots=$pkg_chroots}
+
	: ${daily_backup_pkg_jails=$pkg_jails}

-
    : ${daily_backup_pkg_chroots=$pkg_chroots}
-
    : ${daily_backup_pkg_jails=$pkg_jails}
+
	if [ ! -d $bak ]; then
+
		install -d -o root -g wheel -m 750 $bak || {
+
			echo 'pkg-backup is enabled but' \
+
			"$daily_backup_pkgng_dbdir doesn't exist" ;
+
		exit 2 ; }
+
	fi

-
    if [ ! -d $bak ]
-
    then
-
	install -d -o root -g wheel -m 750 $bak || {
-
	    echo 'pkg-backup is enabled but' \
-
		"$daily_backup_pkgng_dbdir doesn't exist" ;
-
	    exit 2 ; }
-
    fi
+
	echo
+
	echo 'Backing up pkgng database:'

-
    echo
-
    echo 'Backing up pkgng database:'
+
	# We always backup the pkg database for the host system, but only
+
	# print a banner line if we're also backing up for any chroots or
+
	# jails.

-
    # We always backup the pkg database for the host system, but only
-
    # print a banner line if we're also backing up for any chroots or
-
    # jails.
+
	if [ -n "${daily_backup_pkg_chroots}" -o \
+
		-n "${daily_backup_pkg_jails}" ]; then
+
		echo "Host system:"
+
	fi

-
    if [ -n "${daily_backup_pkg_chroots}" -o \
-
	 -n "${daily_backup_pkg_jails}" ];
-
    then
-
	echo "Host system:"
-
    fi
+
	backup_pkg '' "${bak}/pkg.sql.xz"
+
	rc=$?

-
    backup_pkg '' "${bak}/pkg.sql.xz"
-
    rc=$?
+
	for c in $daily_backup_pkg_chroots ; do
+
		echo
+
		echo "chroot: $c"
+
		bak_file="${bak}/pkg.chroot-$(echo $c | tr -C a-zA-Z0-9.- _).sql.xz"
+
		backup_pkg "-c $c" $bak_file
+
		last_rc=$?
+
		[ $last_rc -gt 1 ] && rc=$last_rc
+
	done

-
    for c in $daily_backup_pkg_chroots ; do
-
	echo
-
	echo "chroot: $c"
-
	bak_file="${bak}/pkg.chroot-$(echo $c | tr -C a-zA-Z0-9.- _).sql.xz"
-
	backup_pkg "-c $c" $bak_file
-
	last_rc=$?
-
	[ $last_rc -gt 1 ] && rc=$last_rc
-
    done
-

-
    case $daily_backup_pkg_jails in
+
	case $daily_backup_pkg_jails in
	\*)
-
	    jails=$(jls -q -h name | sed -e 1d)
-
	    ;;
+
		jails=$(jls -q -h name | sed -e 1d)
+
		;;
	'')
-
	    jails=
-
	    ;;
+
		jails=
+
		;;
	*)
-
	    jails=$daily_backup_pkg_jails
-
	    ;;
-
    esac
-

-
    for j in $jails ; do
-
	echo
-
	echo "jail: $j"
-
	bak_file="${bak}/pkg.jail-$(echo $j | tr -C a-zA-Z0-9._- _).sql.xz"
-
	backup_pkg "-j $j" $bak_file
-
	last_rc=$?
-
	[ $last_rc -gt 1 ] && rc=$last_rc
-
    done
-

-
    return $rc
+
		jails=$daily_backup_pkg_jails
+
		;;
+
	esac
+

+
	for j in $jails ; do
+
		echo
+
		echo "jail: $j"
+
		bak_file="${bak}/pkg.jail-$(echo $j | tr -C a-zA-Z0-9._- _).sql.xz"
+
		backup_pkg "-j $j" $bak_file
+
		last_rc=$?
+
		[ $last_rc -gt 1 ] && rc=$last_rc
+
	done
+

+
	return $rc
}

# $daily_backup_pkgng_{enable,dir} are deprecated -- use
# daily_backup_pkg_{enable,dir} instead.

case "$daily_backup_pkgng_enable" in
-
    [Yy][Ee][Ss])
+
[Yy][Ee][Ss])
	: ${daily_backup_pkg_enable:="$daily_backup_pkgng_enable"}
	: ${daily_backup_pkg_dir:="$daily_backup_pkgng_dir"}
	;;
esac

case "${daily_backup_pkg_enable:-YES}" in
-
	[Nn][Oo])
+
[Nn][Oo])
	;;
-
	*)
+
*)
	bak="${daily_backup_pkg_dir:-/var/backups}"
	bak_file="${bak}/pkg.sql.xz"
	pkgcmd=@prefix@/sbin/pkg
@@ -113,8 +111,8 @@ case "${daily_backup_pkg_enable:-YES}" in
	if ! ${pkgcmd} -N >/dev/null 2>&1 ; then
		echo 'pkg-backup is enabled but pkg is not used'
		rc=2
-
 	else
-
	    backup_pkg_all $bak
+
	else
+
		backup_pkg_all $bak
	fi
	;;
esac