]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/tools/ing_test.c
Added patch from Stefan Reddig -- added some checks, db test prog
[bacula/bacula] / bacula / src / tools / ing_test.c
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2009-2009 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  *
30  *  Program to test Ingres DB routines
31  *
32  *   Stefan Reddig, February 2010
33  *
34  *   reusing code from 'bvfs_test.c' by
35  *   Eric Bollengier, August 2009
36  *
37  *
38  */
39
40 #include "bacula.h"
41 #include "cats/cats.h"
42 #include "cats/bvfs.h"
43 #include "findlib/find.h"
44  
45 /* Local variables */
46 static B_DB *db;
47 static const char *file = "COPYRIGHT";
48 static DBId_t fnid=0;
49 static const char *db_name = "bacula";
50 static const char *db_user = "bacula";
51 static const char *db_password = "";
52 static const char *db_host = NULL;
53
54 static void usage()
55 {
56    fprintf(stderr, _(
57 PROG_COPYRIGHT
58 "\nVersion: %s (%s)\n"
59 "       -d <nn>           set debug level to <nn>\n"
60 "       -dt               print timestamp in debug output\n"
61 "       -n <name>         specify the database name (default bacula)\n"
62 "       -u <user>         specify database user name (default bacula)\n"
63 "       -P <password      specify database password (default none)\n"
64 "       -h <host>         specify database host (default NULL)\n"
65 "       -w <working>      specify working directory\n"
66 "       -j <jobids>       specify jobids\n"
67 "       -p <path>         specify path\n"
68 "       -f <file>         specify file\n"
69 "       -l <limit>        maximum tuple to fetch\n"
70 "       -T                truncate cache table before starting\n"
71 "       -v                verbose\n"
72 "       -?                print this message\n\n"), 2001, VERSION, BDATE);
73    exit(1);
74 }
75
76
77
78 /* number of thread started */
79
80 int main (int argc, char *argv[])
81 {
82    int ch;
83    char *jobids = (char *)"1";
84    char *path=NULL, *client=NULL;
85    uint64_t limit=0;
86    bool clean=false;
87    setlocale(LC_ALL, "");
88    bindtextdomain("bacula", LOCALEDIR);
89    textdomain("bacula");
90    init_stack_dump();
91
92    Dmsg0(0, "Starting ing_test tool\n");
93    
94    my_name_is(argc, argv, "ing_test");
95    init_msg(NULL, NULL);
96
97    OSDependentInit();
98
99    while ((ch = getopt(argc, argv, "h:c:l:d:n:P:Su:vf:w:?j:p:f:T")) != -1) {
100       switch (ch) {
101       case 'd':                    /* debug level */
102          if (*optarg == 't') {
103             dbg_timestamp = true;
104          } else {
105             debug_level = atoi(optarg);
106             if (debug_level <= 0) {
107                debug_level = 1;
108             }
109          }
110          break;
111       case 'l':
112          limit = str_to_int64(optarg);
113          break;
114
115       case 'c':
116          client = optarg;
117          break;
118
119       case 'h':
120          db_host = optarg;
121          break;
122
123       case 'n':
124          db_name = optarg;
125          break;
126
127       case 'w':
128          working_directory = optarg;
129          break;
130
131       case 'u':
132          db_user = optarg;
133          break;
134
135       case 'P':
136          db_password = optarg;
137          break;
138
139       case 'v':
140          verbose++;
141          break;
142
143       case 'p':
144          path = optarg;
145          break;
146
147       case 'f':
148          file = optarg;
149          break;
150
151       case 'j':
152          jobids = optarg;
153          break;
154
155       case 'T':
156          clean = true;
157          break;
158
159       case '?':
160       default:
161          usage();
162
163       }
164    }
165    argc -= optind;
166    argv += optind;
167
168    if (argc != 0) {
169       Pmsg0(0, _("Wrong number of arguments: \n"));
170       usage();
171    }
172    
173    if ((db=db_init_database(NULL, db_name, db_user, db_password,
174                             db_host, 0, NULL, 0)) == NULL) {
175       Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
176    }
177    Dmsg1(0, "db_type=%s\n", db_get_type());
178
179    if (!db_open_database(NULL, db)) {
180       Emsg0(M_ERROR_TERM, 0, db_strerror(db));
181    }
182    Dmsg0(200, "Database opened\n");
183    if (verbose) {
184       Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
185    }
186    
187    Dmsg0(200, "DB-Statement: CREATE TABLE t1 ( c1 integer, c2 varchar(29))\n");
188    if (!db_sql_query(db, "CREATE TABLE t1 ( c1 integer, c2 varchar(29))", NULL, NULL))
189    {
190       Emsg0(M_ERROR_TERM, 0, _("CREATE-Stmt went wrong\n"));
191    }
192
193    Dmsg0(200, "DB-Statement: INSERT INTO t1 VALUES (1, 'foo')\n");
194    if (!db_sql_query(db, "INSERT INTO t1 VALUES (1, 'foo')", NULL, NULL))
195    {
196       Emsg0(M_ERROR_TERM, 0, _("INSERT-Stmt went wrong\n"));
197    }
198
199    Dmsg0(200, "DB-Statement: DROP TABLE t1\n");
200    if (!db_sql_query(db, "DROP TABLE t1", NULL, NULL))
201    {
202       Emsg0(M_ERROR_TERM, 0, _("DROP-Stmt went wrong\n"));
203    }
204
205 /*
206    if (clean) {
207       Pmsg0(0, "Clean old table\n");
208       db_sql_query(db, "DELETE FROM PathHierarchy", NULL, NULL);
209       db_sql_query(db, "UPDATE Job SET HasCache=0", NULL, NULL);
210       db_sql_query(db, "DELETE FROM PathVisibility", NULL, NULL);
211    }
212 */
213    db_close_database(NULL, db);
214    Dmsg0(200, "Database closed\n");
215
216    return 0;
217 }