2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
21 * Program to test cache path
23 * Eric Bollengier, August 2009
29 #include "cats/cats.h"
30 #include "cats/bvfs.h"
31 #include "findlib/find.h"
35 static const char *file = "COPYRIGHT";
37 static const char *db_name = "regress";
38 static const char *db_user = "regress";
39 static const char *db_password = "";
40 static const char *db_host = NULL;
41 static const char *db_ssl_mode = NULL;
42 static const char *db_ssl_key = NULL;
43 static const char *db_ssl_cert = NULL;
44 static const char *db_ssl_ca = NULL;
45 static const char *db_ssl_capath = NULL;
46 static const char *db_ssl_cipher = NULL;
52 "\n%sVersion: %s (%s)\n"
53 " -d <nn> set debug level to <nn>\n"
54 " -dt print timestamp in debug output\n"
55 " -n <name> specify the database name (default bacula)\n"
56 " -u <user> specify database user name (default bacula)\n"
57 " -P <password specify database password (default none)\n"
58 " -h <host> specify database host (default NULL)\n"
59 " -k <sslkey> path name to the key file (default NULL)\n"
60 " -e <sslcert> path name to the certificate file (default NULL)\n"
61 " -a <sslca> path name to the CA certificate file (default NULL)\n"
62 " -w <working> specify working directory\n"
63 " -j <jobids> specify jobids\n"
64 " -p <path> specify path\n"
65 " -f <file> specify file\n"
66 " -l <limit> maximum tuple to fetch\n"
67 " -T truncate cache table before starting\n"
69 " -? print this message\n\n"), 2001, "", VERSION, BDATE);
73 static int result_handler(void *ctx, int fields, char **row)
75 Bvfs *vfs = (Bvfs *)ctx;
76 ATTR *attr = vfs->get_attr();
77 char empty[] = "A A A A A A A A A A A A A A";
79 memset(&attr->statp, 0, sizeof(struct stat));
80 decode_stat((row[BVFS_LStat] && row[BVFS_LStat][0])?row[BVFS_LStat]:empty,
81 &attr->statp, sizeof(attr->statp), &attr->LinkFI);
83 if (bvfs_is_dir(row) || bvfs_is_file(row)) {
84 /* display clean stuffs */
86 if (bvfs_is_dir(row)) {
87 pm_strcpy(attr->ofname, bvfs_basename_dir(row[BVFS_Name]));
89 /* if we see the requested file, note his filenameid */
90 if (bstrcmp(row[BVFS_Name], file)) {
91 fnid = str_to_int64(row[BVFS_FilenameId]);
93 pm_strcpy(attr->ofname, row[BVFS_Name]);
95 print_ls_output(vfs->get_jcr(), attr);
98 Pmsg5(0, "JobId=%s FileId=%s\tMd5=%s\tVolName=%s\tVolInChanger=%s\n",
99 row[BVFS_JobId], row[BVFS_FileId], row[BVFS_Md5], row[BVFS_VolName],
100 row[BVFS_VolInchanger]);
102 pm_strcpy(attr->ofname, file);
103 print_ls_output(vfs->get_jcr(), attr);
109 /* number of thread started */
111 int main (int argc, char *argv[])
114 char *jobids = (char *)"1";
115 char *path=NULL, *client=NULL;
118 setlocale(LC_ALL, "");
119 bindtextdomain("bacula", LOCALEDIR);
120 textdomain("bacula");
123 Dmsg0(0, "Starting bvfs_test tool\n");
125 my_name_is(argc, argv, "bvfs_test");
126 init_msg(NULL, NULL);
130 while ((ch = getopt(argc, argv, "h:o:k:e:a:c:l:d:n:P:Su:vf:w:?j:p:f:T")) != -1) {
132 case 'd': /* debug level */
133 if (*optarg == 't') {
134 dbg_timestamp = true;
136 debug_level = atoi(optarg);
137 if (debug_level <= 0) {
143 limit = str_to_int64(optarg);
155 db_ssl_mode = optarg;
175 working_directory = optarg;
183 db_password = optarg;
216 Pmsg0(0, _("Wrong number of arguments: \n"));
219 JCR *bjcr = new_jcr(sizeof(JCR), NULL);
220 bjcr->JobId = getpid();
221 bjcr->setJobType(JT_CONSOLE);
222 bjcr->setJobLevel(L_FULL);
223 bjcr->JobStatus = JS_Running;
224 bjcr->client_name = get_pool_memory(PM_FNAME);
225 pm_strcpy(bjcr->client_name, "Dummy.Client.Name");
226 bstrncpy(bjcr->Job, "bvfs_test", sizeof(bjcr->Job));
228 if ((db = db_init_database(NULL, NULL, db_name, db_user, db_password,
230 db_ssl_mode, db_ssl_key,
231 db_ssl_cert, db_ssl_ca,
232 db_ssl_capath, db_ssl_cipher,
233 false, false)) == NULL) {
234 Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
236 Dmsg1(0, "db_type=%s\n", db_get_engine_name(db));
238 if (!db_open_database(NULL, db)) {
239 Emsg0(M_ERROR_TERM, 0, db_strerror(db));
241 Dmsg0(200, "Database opened\n");
243 Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
249 Pmsg0(0, "Clean old table\n");
250 db_sql_query(db, "DELETE FROM PathHierarchy", NULL, NULL);
251 db_sql_query(db, "UPDATE Job SET HasCache=0", NULL, NULL);
252 db_sql_query(db, "DELETE FROM PathVisibility", NULL, NULL);
253 bvfs_update_cache(bjcr, db);
257 fs.set_handler(result_handler, &fs);
259 fs.set_jobids(jobids);
266 fs.ls_special_dirs();
268 while (fs.ls_files()) {
272 if (fnid && client) {
273 Pmsg0(0, "---------------------------------------------\n");
274 Pmsg1(0, "Getting file version for %s\n", file);
275 fs.get_all_file_versions(fs.get_pwd(), fnid, client);
282 Pmsg0(0, "list /\n");
284 fs.ls_special_dirs();
288 Pmsg0(0, "list /tmp/\n");
290 fs.ls_special_dirs();
294 Pmsg0(0, "list /tmp/regress/\n");
295 fs.ch_dir("/tmp/regress/");
296 fs.ls_special_dirs();
300 Pmsg0(0, "list /tmp/regress/build/\n");
301 fs.ch_dir("/tmp/regress/build/");
302 fs.ls_special_dirs();
306 fs.get_all_file_versions(1, 347, "zog4-fd");
309 strcpy(p, "/tmp/toto/rep/");
311 if(strcmp(p, "/tmp/toto/")) {
312 Pmsg0(000, "Error in bvfs_parent_dir\n");
315 if(strcmp(p, "/tmp/")) {
316 Pmsg0(000, "Error in bvfs_parent_dir\n");
320 Pmsg0(000, "Error in bvfs_parent_dir\n");
324 Pmsg0(000, "Error in bvfs_parent_dir\n");
328 Pmsg0(000, "Error in bvfs_parent_dir\n");