3 * Program to test batch mode
5 * Eric Bollengier, March 2007
11 Bacula® - The Network Backup Solution
13 Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
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 plus additions
20 that are listed in the file LICENSE.
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.
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
32 Bacula® is a registered trademark of John Walker.
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.
41 for i in $(seq 10000 99999) ; do
42 j=$((($i % 1000) + 555))
43 echo "$i;/tmp/totabofds$j/fiddddle${j}$i;xxxLSTATxxxx;xxxxxxxMD5xxxxxx"
49 find / | while read a; do
51 echo "$j;$a;xxxLSTATxxxx;xxxxxxxMD5xxxxxx"
56 #include "stored/stored.h"
57 #include "findlib/find.h"
58 #include "cats/cats.h"
60 /* Forward referenced functions */
61 static void *do_batch(void *);
67 static const char *db_name = "bacula";
68 static const char *db_user = "bacula";
69 static const char *db_password = "";
70 static const char *db_host = NULL;
78 "\nVersion: %s (%s)\n\n"
79 "Usage: bbatch [ options ] -w working/dir -f datafile\n"
80 " -d <nn> set debug level to nn\n"
81 " -n <name> specify the database name (default bacula)\n"
82 " -u <user> specify database user name (default bacula)\n"
83 " -P <password specify database password (default none)\n"
84 " -h <host> specify database host (default NULL)\n"
85 " -w <working> specify working directory\n"
87 " -f <file> specify data file\n"
88 " -? print this message\n\n"), 2001, VERSION, BDATE);
92 /* number of thread started */
95 int main (int argc, char *argv[])
98 setlocale(LC_ALL, "");
99 bindtextdomain("bacula", LOCALEDIR);
100 textdomain("bacula");
103 char **files = (char **) malloc (10 * sizeof(char *));
105 my_name_is(argc, argv, "bbatch");
106 init_msg(NULL, NULL);
110 while ((ch = getopt(argc, argv, "h:c:d:n:P:Su:vf:w:?")) != -1) {
112 case 'd': /* debug level */
113 debug_level = atoi(optarg);
114 if (debug_level <= 0)
127 working_directory = optarg;
135 db_password = optarg;
144 files[nb++] = optarg;
158 Pmsg0(0, _("Wrong number of arguments: \n"));
162 #ifdef HAVE_BATCH_FILE_INSERT
163 printf("With new Batch mode\n");
165 printf("Without new Batch mode\n");
170 JCR *bjcr = new_jcr(sizeof(JCR), NULL);
172 bjcr->VolSessionId = 1;
173 bjcr->VolSessionTime = (uint32_t)time(NULL);
174 bjcr->NumReadVolumes = 0;
175 bjcr->NumWriteVolumes = 0;
176 bjcr->JobId = getpid();
177 bjcr->JobType = JT_CONSOLE;
178 bjcr->JobLevel = L_FULL;
179 bjcr->JobStatus = JS_Running;
180 bjcr->where = bstrdup(files[i]);
181 bjcr->job_name = get_pool_memory(PM_FNAME);
182 pm_strcpy(bjcr->job_name, "Dummy.Job.Name");
183 bjcr->client_name = get_pool_memory(PM_FNAME);
184 pm_strcpy(bjcr->client_name, "Dummy.Client.Name");
185 bstrncpy(bjcr->Job, "bbatch", sizeof(bjcr->Job));
186 bjcr->fileset_name = get_pool_memory(PM_FNAME);
187 pm_strcpy(bjcr->fileset_name, "Dummy.fileset.name");
188 bjcr->fileset_md5 = get_pool_memory(PM_FNAME);
189 pm_strcpy(bjcr->fileset_md5, "Dummy.fileset.md5");
191 if ((db=db_init_database(NULL, db_name, db_user, db_password,
192 db_host, 0, NULL, 0)) == NULL) {
193 Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
195 if (!db_open_database(NULL, db)) {
196 Emsg0(M_ERROR_TERM, 0, db_strerror(db));
198 Dmsg0(200, "Database opened\n");
200 Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
205 pthread_create(&thid, NULL, do_batch, bjcr);
215 static void fill_attr(ATTR_DBR *ar, char *data)
220 ar->Stream = STREAM_UNIX_ATTRIBUTES;
221 ar->JobId = getpid();
223 for(p = b = data; *p; p++) {
228 ar->FileIndex = str_to_int64(b);
246 static void *do_batch(void *jcr)
248 JCR *bjcr = (JCR *)jcr;
252 memset(&ar, 0, sizeof(ar));
253 btime_t begin = get_current_btime();
254 char *datafile = bjcr->where;
256 FILE *fd = fopen(datafile, "r");
258 Emsg1(M_ERROR_TERM, 0, _("Error opening datafile %s\n"), datafile);
260 while (fgets(data, sizeof(data)-1, fd)) {
261 strip_trailing_newline(data);
263 if (verbose && ((lineno % 5000) == 1)) {
264 printf("\r%i", lineno);
266 fill_attr(&ar, data);
267 if (!db_create_file_attributes_record(bjcr, bjcr->db, &ar)) {
268 Emsg0(M_ERROR_TERM, 0, _("Error while inserting file\n"));
272 db_write_batch_file_records(bjcr);
273 btime_t end = get_current_btime();
275 char ed1[200], ed2[200];
276 printf("\rbegin = %s, end = %s\n", edit_int64(begin, ed1),edit_int64(end, ed2));
277 printf("Insert time = %llims\n", (end - begin) / 10000);
278 printf("Create %u files at %.2f/s\n", lineno,
279 (lineno / ((float)((end - begin) / 1000000))));