]> git.sur5r.net Git - bacula/docs/blob - docs/manual-de/postgresql.tex
Updates
[bacula/docs] / docs / manual-de / postgresql.tex
1 %%
2 %%
3
4 \section*{Installing and Configuring PostgreSQL}
5 \label{_ChapterStart10}
6 \index[general]{PostgreSQL!Installing and Configuring }
7 \index[general]{Installing and Configuring PostgreSQL }
8 \addcontentsline{toc}{section}{Installing and Configuring PostgreSQL}
9
10 \subsection*{Installing and Configuring PostgreSQL -- Phase I}
11 \index[general]{Installing and Configuring PostgreSQL -- Phase I }
12 \index[general]{Phase I!Installing and Configuring PostgreSQL -- }
13 \addcontentsline{toc}{subsection}{Installing and Configuring PostgreSQL --
14 Phase I}
15
16 If you use the {\bf ./configure \verb:--:with-postgresql=PostgreSQL-Directory}
17 statement for configuring {\bf Bacula}, you will need PostgreSQL version 7.3
18 or later installed. NOTE! PostgreSQL versions earlier than 7.3 do not work
19 with Bacula. If PostgreSQL is installed in the standard system location, you
20 need only enter {\bf \verb:--:with-postgresql} since the configure program will
21 search all the standard locations. If you install PostgreSQL in your home
22 directory or some other non-standard directory, you will need to provide the
23 full path with the {\bf \verb:--:with-postgresql} option. 
24
25 Installing and configuring PostgreSQL is not difficult but can be confusing
26 the first time. If you prefer, you may want to use a package provided by your
27 chosen operating system. Binary packages are available on most PostgreSQL
28 mirrors. 
29
30 If you prefer to install from source, we recommend following the instructions
31 found in the 
32 \elink{PostgreSQL documentation}{http://www.postgresql.org/docs/}. 
33
34 If you are using FreeBSD, 
35 \elink{this FreeBSD Diary article}{http://www.freebsddiary.org/postgresql.php}
36 will be useful. Even if you are not using FreeBSD, the article will contain
37 useful configuration and setup information. 
38
39 After installing PostgreSQL, you should return to completing the installation
40 of {\bf Bacula}. Later, after Bacula is installed, come back to this chapter
41 to complete the installation. Please note, the installation files used in the
42 second phase of the PostgreSQL installation are created during the Bacula
43 Installation. 
44 \label{PostgreSQL_phase2}
45
46 \subsection*{Installing and Configuring PostgreSQL -- Phase II}
47 \index[general]{Phase II!Installing and Configuring PostgreSQL -- }
48 \index[general]{Installing and Configuring PostgreSQL -- Phase II }
49 \addcontentsline{toc}{subsection}{Installing and Configuring PostgreSQL --
50 Phase II}
51
52 At this point, you should have built and installed PostgreSQL, or already have
53 a running PostgreSQL, and you should have configured, built and installed {\bf
54 Bacula}. If not, please complete these items before proceeding. 
55
56 Please note that the {\bf ./configure} used to build {\bf Bacula} will need to
57 include {\bf \verb:--:with-postgresql=PostgreSQL-directory}, where {\bf
58 PostgreSQL-directory} is the directory name that you specified on the
59 ./configure command for configuring PostgreSQL (if you didn't specify a
60 directory or PostgreSQL is installed in a default location, you do not need to
61 specify the directory). This is needed so that Bacula can find the necessary
62 include headers and library files for interfacing to PostgreSQL. 
63
64 {\bf Bacula} will install scripts for manipulating the database (create,
65 delete, make tables etc) into the main installation directory. These files
66 will be of the form *\_bacula\_* (e.g. create\_bacula\_database). These files
67 are also available in the \lt{}bacula-src\gt{}/src/cats directory after
68 running ./configure. If you inspect create\_bacula\_database, you will see
69 that it calls create\_postgresql\_database. The *\_bacula\_* files are
70 provided for convenience. It doesn't matter what database you have chosen;
71 create\_bacula\_database will always create your database. 
72
73 Now you will create the Bacula PostgreSQL database and the tables that Bacula
74 uses. These instructions assume that you already have PostgreSQL running. You
75 will need to perform these steps as a user that is able to create new
76 databases. This can be the PostgreSQL user (on most systems, this is the pgsql
77 user). 
78
79 \begin{enumerate}
80 \item cd \lt{}install-directory\gt{}
81
82    This directory contains the Bacula catalog  interface routines.  
83
84 \item ./create\_bacula\_database
85
86    This script creates the PostgreSQL {\bf bacula} database.  
87    If it fails, it is probably because the database is owned by a
88    user other than yourself. On many systems, the database owner is
89    {\bf pgsql} and on others such as RedHat and Fedora it is {\bf postgres}.
90    You can find out which it is by examining your /etc/passwd file.
91    To create a new user under either your name or with say the name
92    {\bf bacula}, you can do the following:
93
94 \begin{verbatim}
95    su
96    (enter root password)
97    password pgsql (or postgres)
98    (enter a password for this account)
99    exit
100    su pgsql (or postgres)
101    (enter password just created)
102    createuser kern (or perhaps bacula)
103    Shall the new user be allowed to create databases? (y/n) y
104    Shall the new user be allowed to create more new users? (y/n) (choose
105          what you want)
106    exit
107 \end{verbatim}
108     
109     At this point, you should be able to execute the
110     ./create\_bacula\_database command.
111
112 \item ./make\_bacula\_tables
113
114    This script creates the PostgreSQL tables used by {\bf Bacula}.  
115 \item ./grant\_bacula\_privileges
116
117    This script creates the database user {\bf bacula}  with restricted access
118 rights. You may  want to modify it to suit your situation. Please note that 
119 this database is not password protected.  
120
121 \end{enumerate}
122
123 Each of the three scripts (create\_bacula\_database, make\_bacula\_tables, and
124 grant\_bacula\_privileges) allows the addition of a command line argument.
125 This can be useful for specifying the user name. For example, you might need
126 to add {\bf -h hostname} to the command line to specify a remote database
127 server. 
128
129 To take a closer look at the access privileges that you have setup with the
130 above, you can do: 
131
132 \footnotesize
133 \begin{verbatim}
134 PostgreSQL-directory/bin/psql --command \\dp bacula
135 \end{verbatim}
136 \normalsize
137
138 Also, I had an authorization problem with the password. In the end,
139 I had to modify my {\bf pg_hba.conf} file (in /var/lib/pgsql on my machine)
140 from:
141
142 \footnotesize
143 \begin{verbatim}
144   local   all    all        ident
145 to
146   local   all    all        trust
147 \end{verbatim}
148 \normalsize
149
150 This solved the problem for me, but it is not always a good thing
151 to do from a security standpoint.  However, it allowed me to run
152 my regression scripts without having a password.
153
154 A more secure way to perform database authentication is with md5
155 password hashes.  Begin by editing the {\bf pg_hba.conf} file, and
156 just prior the the existing ``local'' and ``host'' lines, add the line:
157
158 \footnotesize
159 \begin{verbatim}
160   local bacula bacula md5
161 \end{verbatim}
162 \normalsize
163
164 and restart the Postgres database server (frequently, this can be done
165 using "/etc/init.d/postgresql restart") to put this new authentication
166 rule into effect.
167
168 Next, become the Postgres administrator, postgres, either by logging
169 on as the postgres user, or by using su to become root and then using
170 su - postgres to become postgres.  Add a password to the bacula
171 database for the bacula user using:
172
173 \footnotesize
174 \begin{verbatim}
175   \$ psql bacula
176   bacula=# alter user bacula with password 'secret';
177   ALTER USER
178   bacula=# \\q
179 \end{verbatim}
180 \normalsize
181
182 Next, you'll have to add this password to two locations in the
183 bacula-dir.conf file: once to the Catalog resource and once to the
184 RunBeforeJob entry in the BackupCatalog Job resource.  With the
185 password in place, these two lines should look something like:
186
187 \footnotesize
188 \begin{verbatim}
189   dbname = bacula; user = bacula; password = "secret"
190     ... and ...
191   RunBeforeJob = "/etc/make_catalog_backup bacula bacula secret"
192 \end{verbatim}
193 \normalsize
194
195 Naturally, you should choose your own significantly more random
196 password, and ensure that the bacula-dir.conf file containing this
197 password is readable only by the root.
198
199 Even with the files containing the database password properly
200 restricted, there is still a security problem with this approach: on
201 some platforms, the environment variable that is used to supply the
202 password to Postgres is unavoidable made available to all users of the
203 local system.  To eliminate this problem, the Postgres team have
204 deprecated the use of the environment variable password-passing
205 mechanism and recommend the use of a .pgpass file instead.  To use
206 this mechanism, create a file named .pgpass containing the single
207 line:
208
209 \footnotesize
210 \begin{verbatim}
211   localhost:5432:bacula:bacula:secret
212 \end{verbatim}
213 \normalsize
214
215 This file should be copied into the home directory of all accounts
216 that will need to gain access to the database: typically, root,
217 bacula, and any users who will make use of any of the console
218 programs.  The files must then have the owner and group set to match
219 the user (so root:root for the copy in ~root, and so on), and the mode
220 set to 600, limiting access to the owner of the file.
221
222 \subsection*{Re-initializing the Catalog Database}
223 \index[general]{Database!Re-initializing the Catalog }
224 \index[general]{Re-initializing the Catalog Database }
225 \addcontentsline{toc}{subsection}{Re-initializing the Catalog Database}
226
227 After you have done some initial testing with {\bf Bacula}, you will probably
228 want to re-initialize the catalog database and throw away all the test Jobs
229 that you ran. To do so, you can do the following: 
230
231 \footnotesize
232 \begin{verbatim}
233   cd <install-directory>
234   ./drop_bacula_tables
235   ./make_bacula_tables
236   ./grant_bacula_privileges
237 \end{verbatim}
238 \normalsize
239
240 Please note that all information in the database will be lost and you will be
241 starting from scratch. If you have written on any Volumes, you must write an
242 end of file mark on the volume so that Bacula can reuse it. Do so with: 
243
244 \footnotesize
245 \begin{verbatim}
246    (stop Bacula or unmount the drive)
247    mt -f /dev/nst0 rewind
248    mt -f /dev/nst0 weof
249 \end{verbatim}
250 \normalsize
251
252 Where you should replace {\bf /dev/nst0} with the appropriate tape drive
253 device name for your machine. 
254
255 \subsection*{Installing PostgreSQL from RPMs}
256 \index[general]{PostgreSQL!Installing from RPMs}
257 \index[general]{Installing PostgreSQL from RPMs}
258 \addcontentsline{toc}{subsection}{Installing PostgreSQL from RPMs}
259 If you are installing PostgreSQL from RPMs, you will need to install
260 both the PostgreSQL binaries and the client libraries.  The client
261 libraries are ususally found in a devel package, so you must
262 install:
263
264 \footnotesize
265 \begin{verbatim}
266   postgresql
267   postgresql-devel
268 \end{verbatim}
269 \normalsize
270
271 This will be the same with most other package managers too.
272
273
274 \subsection*{Converting from MySQL to PostgreSQL}
275 \index[general]{PostgreSQL!Converting from MySQL to }
276 \index[general]{Converting from MySQL to PostgreSQL }
277 \addcontentsline{toc}{subsection}{Converting from MySQL to PostgreSQL}
278
279 The conversion procedure presented here was worked out by Norm Dressler
280 \lt{}ndressler at dinmar dot com\gt{} 
281
282 This process was tested using the following software versions: 
283
284 \begin{itemize}
285 \item Linux Mandrake 10/Kernel 2.4.22-10 SMP 
286 \item Mysql Ver 12.21 Distrib 4.0.15, for mandrake-linux-gnu (i586) 
287 \item PostgreSQL 7.3.4 
288 \item Bacula 1.34.5 
289    \end{itemize}
290
291 WARNING: Always as a precaution, take a complete backup of your databases
292 before proceeding with this process! 
293
294 \begin{enumerate}
295 \item Shutdown bacula (cd /etc/bacula;./bacula stop)  
296 \item Run the following command to dump your Mysql database:  
297
298    \footnotesize
299 \begin{verbatim}
300        mysqldump -f -t -n >bacula-backup.dmp>
301     
302 \end{verbatim}
303 \normalsize
304
305 \item Make a backup of your /etc/bacula directory (but leave the  original in
306    place).  
307 \item Go to your Bacula source directory and rebuild it to include  PostgreSQL
308    support rather then Mysql support. Check the  config.log file for your
309    original configure command and replace  enable-mysql with enable-postgresql.  
310 \item Recompile Bacula with a make and if everything compiles  completely,
311    perform a make install.  
312 \item Shutdown Mysql. 
313 \item Start PostgreSQL on your system.  
314 \item Create a bacula user in Postgres with the createuser command.  Depending on
315    your Postgres install, you may have to SU to the  user who has privileges to
316    create a user.  
317 \item Verify your pg\_hba.conf file contains sufficient permissions to  allow
318    bacula to access the server. Mine has the following since  it's on a secure
319    network:  
320
321 \footnotesize
322 \begin{verbatim}
323 local all all trust
324                 
325 host all all 127.0.0.1 255.255.255.255 trust
326                 
327 NOTE: you should restart your postgres server if you
328       made changes
329       
330 \end{verbatim}
331 \normalsize
332
333 \item Change into the /etc/bacula directory and prepare the database  and
334    tables with the following commands:  
335
336 \footnotesize
337 \begin{verbatim}
338 ./create_postgresql_database
339                                 
340 ./make_postgresql_tables
341                                 
342 ./grant_postgresql_privileges
343        
344 \end{verbatim}
345 \normalsize
346
347 \item Verify you have access to the database:  
348
349    \footnotesize
350 \begin{verbatim}
351   
352 psql -Ubacula bacula
353       
354 \end{verbatim}
355 \normalsize
356
357 You should not get any errors.  
358 \item Load your database from the Mysql database dump with:  
359
360    \footnotesize
361 \begin{verbatim}
362 psql -Ubacula bacula <bacula-backup.dmp>
363       
364 \end{verbatim}
365 \normalsize
366
367 \item Reseqence your tables with the following commands:  
368
369    \footnotesize
370 \begin{verbatim}
371 psql -Ubacula bacula
372                 
373 SELECT SETVAL('basefiles_baseid_seq', (SELECT
374 MAX(baseid) FROM basefiles));
375 SELECT SETVAL('client_clientid_seq', (SELECT
376 MAX(clientid) FROM client));
377 SELECT SETVAL('file_fileid_seq', (SELECT MAX(fileid)
378 FROM file));
379 SELECT SETVAL('filename_filenameid_seq', (SELECT
380 MAX(filenameid) FROM filename));
381                 
382 SELECT SETVAL('fileset_filesetid_seq', (SELECT
383 MAX(filesetid) FROM fileset));
384                 
385 SELECT SETVAL('job_jobid_seq', (SELECT MAX(jobid) FROM job));
386 SELECT SETVAL('jobmedia_jobmediaid_seq', (SELECT
387 MAX(jobmediaid) FROM jobmedia));
388 SELECT SETVAL('media_mediaid_seq', (SELECT MAX(mediaid) FROM media));
389 SELECT SETVAL('path_pathid_seq', (SELECT MAX(pathid) FROM path));
390                 
391 SELECT SETVAL('pool_poolid_seq', (SELECT MAX(poolid) FROM pool));
392        
393 \end{verbatim}
394 \normalsize
395
396 \item At this point, start up Bacula, verify your volume library and  perform
397    a test backup to make sure everything is working  properly. 
398 \end{enumerate}
399
400 \subsection*{Upgrading PostgreSQL}
401 \index[general]{Upgrading PostgreSQL }
402 \index[general]{Upgrading!PostgreSQL }
403 \addcontentsline{toc}{subsection}{Upgrading PostgreSQL}
404 If you upgrade PostgreSQL, you must reconfigure, rebuild, and re-install 
405 Bacula otherwise you are likely to get bizarre failures.  If you
406 to modify the bacula.spec file to account for the new PostgreSQL version.
407 You can do so by rebuilding from the source rpm. To do so, you may need
408 install from rpms and you upgrade PostgreSQL, you must also rebuild Bacula.
409
410
411 \subsection*{Credits}
412 \index[general]{Credits }
413 \addcontentsline{toc}{subsection}{Credits}
414 Many thanks to Dan Langille for writing the PostgreSQL driver. This will
415 surely become the most popular database that Bacula supports.