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 and included
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;
72 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
78 "\nVersion: %s (%s)\n"
79 "Example : bbatch -w /path/to/workdir -h localhost -f dat1 -f dat -f datx\n"
80 " will start 3 thread and load dat1, dat and datx in your catalog\n"
81 "See bbatch.c to generate datafile\n\n"
82 "Usage: bbatch [ options ] -w working/dir -f datafile\n"
83 " -d <nn> set debug level to nn\n"
84 " -n <name> specify the database name (default bacula)\n"
85 " -u <user> specify database user name (default bacula)\n"
86 " -P <password specify database password (default none)\n"
87 " -h <host> specify database host (default NULL)\n"
88 " -w <working> specify working directory\n"
90 " -f <file> specify data file\n"
91 " -? print this message\n\n"), 2001, VERSION, BDATE);
95 /* number of thread started */
98 int main (int argc, char *argv[])
101 setlocale(LC_ALL, "");
102 bindtextdomain("bacula", LOCALEDIR);
103 textdomain("bacula");
106 char **files = (char **) malloc (10 * sizeof(char *));
108 my_name_is(argc, argv, "bbatch");
109 init_msg(NULL, NULL);
113 while ((ch = getopt(argc, argv, "h:c:d:n:P:Su:vf:w:?")) != -1) {
115 case 'd': /* debug level */
116 debug_level = atoi(optarg);
117 if (debug_level <= 0)
130 working_directory = optarg;
138 db_password = optarg;
147 files[nb++] = optarg;
161 Pmsg0(0, _("Wrong number of arguments: \n"));
165 #ifdef HAVE_BATCH_FILE_INSERT
166 printf("With new Batch mode\n");
168 printf("Without new Batch mode\n");
173 JCR *bjcr = new_jcr(sizeof(JCR), NULL);
175 bjcr->VolSessionId = 1;
176 bjcr->VolSessionTime = (uint32_t)time(NULL);
177 bjcr->NumReadVolumes = 0;
178 bjcr->NumWriteVolumes = 0;
179 bjcr->JobId = getpid();
180 bjcr->JobType = JT_CONSOLE;
181 bjcr->JobLevel = L_FULL;
182 bjcr->JobStatus = JS_Running;
183 bjcr->where = bstrdup(files[i]);
184 bjcr->job_name = get_pool_memory(PM_FNAME);
185 pm_strcpy(bjcr->job_name, "Dummy.Job.Name");
186 bjcr->client_name = get_pool_memory(PM_FNAME);
187 pm_strcpy(bjcr->client_name, "Dummy.Client.Name");
188 bstrncpy(bjcr->Job, "bbatch", sizeof(bjcr->Job));
189 bjcr->fileset_name = get_pool_memory(PM_FNAME);
190 pm_strcpy(bjcr->fileset_name, "Dummy.fileset.name");
191 bjcr->fileset_md5 = get_pool_memory(PM_FNAME);
192 pm_strcpy(bjcr->fileset_md5, "Dummy.fileset.md5");
194 if ((db=db_init_database(NULL, db_name, db_user, db_password,
195 db_host, 0, NULL, 0)) == NULL) {
196 Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
198 if (!db_open_database(NULL, db)) {
199 Emsg0(M_ERROR_TERM, 0, db_strerror(db));
201 Dmsg0(200, "Database opened\n");
203 Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
208 pthread_create(&thid, NULL, do_batch, bjcr);
218 static void fill_attr(ATTR_DBR *ar, char *data)
223 ar->Stream = STREAM_UNIX_ATTRIBUTES;
224 ar->JobId = getpid();
226 for(p = b = data; *p; p++) {
231 ar->FileIndex = str_to_int64(b);
249 static void *do_batch(void *jcr)
251 JCR *bjcr = (JCR *)jcr;
255 memset(&ar, 0, sizeof(ar));
256 btime_t begin = get_current_btime();
257 char *datafile = bjcr->where;
259 FILE *fd = fopen(datafile, "r");
261 Emsg1(M_ERROR_TERM, 0, _("Error opening datafile %s\n"), datafile);
263 while (fgets(data, sizeof(data)-1, fd)) {
264 strip_trailing_newline(data);
266 if (verbose && ((lineno % 5000) == 1)) {
267 printf("\r%i", lineno);
269 fill_attr(&ar, data);
270 if (!db_create_file_attributes_record(bjcr, bjcr->db, &ar)) {
271 Emsg0(M_ERROR_TERM, 0, _("Error while inserting file\n"));
275 db_write_batch_file_records(bjcr);
276 btime_t end = get_current_btime();
279 char ed1[200], ed2[200];
280 printf("\rbegin = %s, end = %s\n", edit_int64(begin, ed1),edit_int64(end, ed2));
281 printf("Insert time = %llims\n", (end - begin) / 10000);
282 printf("Create %u files at %.2f/s\n", lineno,
283 (lineno / ((float)((end - begin) / 1000000))));