]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/tools/bvfs_test.c
Add a new Bvfs class that implements brestore instant navigation
[bacula/bacula] / bacula / src / tools / bvfs_test.c
1 /*
2  *
3  *  Program to test cache path
4  *
5  *   Eric Bollengier, March 2007
6  *
7  *
8  *   Version $Id$
9  */
10 /*
11    Bacula® - The Network Backup Solution
12
13    Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
14
15    The main author of Bacula is Kern Sibbald, with contributions from
16    many others, a complete list can be found in the file AUTHORS.
17    This program is Free Software; you can redistribute it and/or
18    modify it under the terms of version two of the GNU General Public
19    License as published by the Free Software Foundation and included
20    in the file LICENSE.
21
22    This program is distributed in the hope that it will be useful, but
23    WITHOUT ANY WARRANTY; without even the implied warranty of
24    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25    General Public License for more details.
26
27    You should have received a copy of the GNU General Public License
28    along with this program; if not, write to the Free Software
29    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30    02110-1301, USA.
31
32    Bacula® is a registered trademark of Kern Sibbald.
33    The licensor of Bacula is the Free Software Foundation Europe
34    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
35    Switzerland, email:ftf@fsfeurope.org.
36 */
37
38 #include "bacula.h"
39 #include "cats/cats.h"
40 #include "cats/bvfs.h"
41  
42 /* Local variables */
43 static B_DB *db;
44
45 static const char *db_name = "regress";
46 static const char *db_user = "regress";
47 static const char *db_password = "";
48 static const char *db_host = NULL;
49
50 static void usage()
51 {
52    fprintf(stderr, _(
53 PROG_COPYRIGHT
54 "\nVersion: %s (%s)\n"
55 "       -d <nn>           set debug level to <nn>\n"
56 "       -dt               print timestamp in debug output\n"
57 "       -n <name>         specify the database name (default bacula)\n"
58 "       -u <user>         specify database user name (default bacula)\n"
59 "       -P <password      specify database password (default none)\n"
60 "       -h <host>         specify database host (default NULL)\n"
61 "       -w <working>      specify working directory\n"
62 "       -v                verbose\n"
63 "       -?                print this message\n\n"), 2001, VERSION, BDATE);
64    exit(1);
65 }
66
67 /* number of thread started */
68
69 int main (int argc, char *argv[])
70 {
71    int ch;
72    setlocale(LC_ALL, "");
73    bindtextdomain("bacula", LOCALEDIR);
74    textdomain("bacula");
75    init_stack_dump();
76
77    Dmsg0(0, "Starting bvfs_test tool\n");
78    
79    my_name_is(argc, argv, "bvfs_test");
80    init_msg(NULL, NULL);
81
82    OSDependentInit();
83
84    while ((ch = getopt(argc, argv, "h:c:d:n:P:Su:vf:w:?")) != -1) {
85       switch (ch) {
86       case 'd':                    /* debug level */
87          if (*optarg == 't') {
88             dbg_timestamp = true;
89          } else {
90             debug_level = atoi(optarg);
91             if (debug_level <= 0) {
92                debug_level = 1;
93             }
94          }
95          break;
96
97       case 'h':
98          db_host = optarg;
99          break;
100
101       case 'n':
102          db_name = optarg;
103          break;
104
105       case 'w':
106          working_directory = optarg;
107          break;
108
109       case 'u':
110          db_user = optarg;
111          break;
112
113       case 'P':
114          db_password = optarg;
115          break;
116
117       case 'v':
118          verbose++;
119          break;
120
121       case '?':
122       default:
123          usage();
124
125       }
126    }
127    argc -= optind;
128    argv += optind;
129
130    if (argc != 0) {
131       Pmsg0(0, _("Wrong number of arguments: \n"));
132       usage();
133    }
134    JCR *bjcr = new_jcr(sizeof(JCR), NULL);
135    bjcr->JobId = getpid();
136    bjcr->set_JobType(JT_CONSOLE);
137    bjcr->set_JobLevel(L_FULL);
138    bjcr->JobStatus = JS_Running;
139    bjcr->client_name = get_pool_memory(PM_FNAME);
140    pm_strcpy(bjcr->client_name, "Dummy.Client.Name");
141    bstrncpy(bjcr->Job, "bvfs_test", sizeof(bjcr->Job));
142    
143    if ((db=db_init_database(NULL, db_name, db_user, db_password,
144                             db_host, 0, NULL, 0)) == NULL) {
145       Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
146    }
147    Dmsg1(0, "db_type=%s\n", db_get_type());
148
149    if (!db_open_database(NULL, db)) {
150       Emsg0(M_ERROR_TERM, 0, db_strerror(db));
151    }
152    Dmsg0(200, "Database opened\n");
153    if (verbose) {
154       Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
155    }
156    
157    bjcr->db = db;
158    
159    db_sql_query(db, "DELETE FROM brestore_pathhierarchy", NULL, NULL);
160    db_sql_query(db, "DELETE FROM brestore_knownjobid", NULL, NULL);
161    db_sql_query(db, "DELETE FROM brestore_pathvisibility", NULL, NULL);
162
163    bvfs_update_cache(bjcr, db);
164    Bvfs fs(bjcr, db);
165
166    fs.set_jobids("1");
167    fs.update_cache();
168    fs.ch_dir("");
169    fs.ls_files();
170    fs.ls_dirs();
171
172    fs.ch_dir("/");
173    fs.ls_files();
174    fs.ls_dirs();
175
176    fs.ch_dir("/tmp/");
177    fs.ls_files();
178    fs.ls_dirs();
179
180    fs.ch_dir("/tmp/regress/");
181    fs.ls_files();
182    fs.ls_dirs();
183
184    fs.set_jobid(1);
185    fs.ch_dir("/tmp/regress/build/");
186    fs.ls_files();
187    fs.ls_dirs();
188    fs.ls_special_dirs();
189    fs.get_all_file_versions(1, 347, "zog4-fd");
190
191    char p[200];
192    strcpy(p, "/tmp/toto/rep/");
193    bvfs_parent_dir(p);
194    if(strcmp(p, "/tmp/toto/")) {
195       Pmsg0(000, "Error in bvfs_parent_dir\n");
196    }
197    bvfs_parent_dir(p);
198    if(strcmp(p, "/tmp/")) {
199       Pmsg0(000, "Error in bvfs_parent_dir\n");
200    }
201    bvfs_parent_dir(p);
202    if(strcmp(p, "/")) {
203       Pmsg0(000, "Error in bvfs_parent_dir\n");
204    }
205    bvfs_parent_dir(p);
206    if(strcmp(p, "")) {
207       Pmsg0(000, "Error in bvfs_parent_dir\n");
208    }
209    bvfs_parent_dir(p);
210    if(strcmp(p, "")) {
211       Pmsg0(000, "Error in bvfs_parent_dir\n");
212    }
213
214    return 0;
215 }