SPECS: bacula.spec - post dir procedure is +- safe for sqlite/sqli...

arekm arekm at pld-linux.org
Sat Nov 24 20:03:57 CET 2007


Author: arekm                        Date: Sat Nov 24 19:03:57 2007 GMT
Module: SPECS                         Tag: HEAD
---- Log message:
- post dir procedure is +- safe for sqlite/sqlite3 only

---- Files affected:
SPECS:
   bacula.spec (1.77 -> 1.78) 

---- Diffs:

================================================================
Index: SPECS/bacula.spec
diff -u SPECS/bacula.spec:1.77 SPECS/bacula.spec:1.78
--- SPECS/bacula.spec:1.77	Sat Nov 24 19:16:45 2007
+++ SPECS/bacula.spec	Sat Nov 24 20:03:51 2007
@@ -589,47 +589,43 @@
 
 %post dir
 umask 077
+
+# XXX: Most of this upgrade procedure is safe for sqlite only. Other databases would require knowledge
+#      about currently used version so we can't easily support these :(
+
+if %{with sqlite} || %{with sqlite3}
 [ -s %{_localstatedir}/bacula.db ] && \
 	DB_VER=`echo "select * from Version;" | \
 	%{_bindir}/sqlite%{?with_sqlite3:3} %{_localstatedir}/bacula.db | tail -n 1 2>/dev/null`
+
 if [ -z "$DB_VER" ]; then
 # grant privileges and create tables
 	%{_libexecdir}/%{name}/grant_bacula_privileges > dev/null
 	%{_libexecdir}/%{name}/create_bacula_database > dev/null
 	%{_libexecdir}/%{name}/make_bacula_tables > dev/null
-elif [ "$DB_VER" -lt "9" ]; then
+else
 	echo "Backing up bacula tables"
 	echo ".dump" | sqlite%{?with_sqlite3:3} %{_localstatedir}/bacula.db | bzip2 > %{_localstatedir}/bacula_backup.sql.bz2
-	echo "Upgrading bacula tables"
-	%if %{with sqlite3}
-		type=sqlite3
-		if [ "$DB_VER" -lt "9" ]; then
-			%{_libexecdir}/%{name}/update_${type}_tables_8_to_9
-		fi
-	%endif
-	%if %{with sqlite}
-		type=sqlite
-		if [ "$DB_VER" -lt "9" ]; then
-			if [ "$DB_VER" -lt "8" ]; then
-				if [ "$DB_VER" -lt "7" ]; then
-					if [ "$DB_VER" -lt "6" ]; then
-						if [ "$DB_VER" -lt "5" ]; then
-							%{_libexecdir}/%{name}/update_${type}_tables_4_to_5
-						fi
-						%{_libexecdir}/%{name}/update_${type}_tables_5_to_6
-					fi
-					%{_libexecdir}/%{name}/update_${type}_tables_6_to_7
-				fi
-				%{_libexecdir}/%{name}/update_${type}_tables_7_to_8
-			fi
-			%{_libexecdir}/%{name}/update_${type}_tables_8_to_9
+
+	db_type="%{_database}"
+
+	next_ver=$(($DB_VER + 1))
+	# support up to version 30; increase this if needed
+	for ver in $(seq $next_ver 30); do
+		prev_ver=$(($ver - 1))
+
+		if [ -x %{_libexecdir}/%{name}/update_${type}_tables_${prev_ver}_to_${ver} ]; then
+			echo "Upgrading bacula database: db=${db_type} from ${prev_ver} to ${ver}..."
+			%{_libexecdir}/%{name}/update_${type}_tables_${prev_ver}_to_${ver}
 		fi
-	%endif
+	done
+
 	%{_libexecdir}/%{name}/update_bacula_tables
 	echo "If bacula works correctly you can remove the backup file %{_localstatedir}/bacula_backup.sql.bz2"
 fi
 chown -R bacula:bacula %{_localstatedir}
 chmod -R u+rX,go-rwx %{_localstatedir}/*
+%endif
 
 echo "Updating Bacula passwords and names..."
 cd /etc/bacula
@@ -933,6 +929,9 @@
 All persons listed below can be reached at <cvs_login>@pld-linux.org
 
 $Log$
+Revision 1.78  2007-11-24 19:03:51  arekm
+- post dir procedure is +- safe for sqlite/sqlite3 only
+
 Revision 1.77  2007-11-24 18:16:45  arekm
 - rel 2; switch to mysql (it's recommended for serious tasks); fix mysql/wxwidgets detection; enable batch-insert
 
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SPECS/bacula.spec?r1=1.77&r2=1.78&f=u



More information about the pld-cvs-commit mailing list