1 | /* libmondo-archive.c
|
---|
2 | $Id: libmondo-archive.c 3885 2024-03-10 18:23:12Z bruno $
|
---|
3 |
|
---|
4 | subroutines to handle the archiving of files
|
---|
5 | */
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * @file
|
---|
9 | * Functions to handle backing up data.
|
---|
10 | * This is the main file (at least the longest one) in libmondo.
|
---|
11 | */
|
---|
12 |
|
---|
13 | #include "my-stuff.h"
|
---|
14 | #include "mr_mem.h"
|
---|
15 | #include "mr_str.h"
|
---|
16 | #include "mr_sys.h"
|
---|
17 | #include "mr_file.h"
|
---|
18 | #include "mondostructures.h"
|
---|
19 | #include "libmondo-string-EXT.h"
|
---|
20 | #include "libmondo-stream-EXT.h"
|
---|
21 | #include "libmondo-devices-EXT.h"
|
---|
22 | #include "libmondo-tools-EXT.h"
|
---|
23 | #include "libmondo-gui-EXT.h"
|
---|
24 | #include "libmondo-fork-EXT.h"
|
---|
25 | #include "libmondo-files-EXT.h"
|
---|
26 | #include "libmondo-filelist-EXT.h"
|
---|
27 | #include "libmondo-tools-EXT.h"
|
---|
28 | #include "libmondo-verify-EXT.h"
|
---|
29 |
|
---|
30 | #include <sys/sem.h>
|
---|
31 | #include <sys/types.h>
|
---|
32 | #include <sys/ipc.h>
|
---|
33 | #include <stdarg.h>
|
---|
34 | #include <unistd.h>
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Maximum number of filesets allowed in this function.
|
---|
38 | */
|
---|
39 | #define MAX_NOOF_SETS_HERE 32767
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Offset of the bkpinfo pointer (in bytes) from the
|
---|
43 | * buffer passed to create_afio_files_in_background.
|
---|
44 | */
|
---|
45 | #define BKPINFO_LOC_OFFSET (16+MAX_NOOF_SETS_HERE/8+16)
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 | #ifndef _SEMUN_H
|
---|
50 | #define _SEMUN_H
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * The semaphore union, provided only in case the user's system doesn't.
|
---|
54 | */
|
---|
55 | union semun {
|
---|
56 | int val;
|
---|
57 | struct semid_ds *buf;
|
---|
58 | unsigned short int *array;
|
---|
59 | struct seminfo *__buf;
|
---|
60 | };
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | /*@unused@*/
|
---|
64 | //static char cvsid[] = "$Id: libmondo-archive.c 3885 2024-03-10 18:23:12Z bruno $";
|
---|
65 | //
|
---|
66 | extern char *get_non_rewind_dev(char *);
|
---|
67 |
|
---|
68 | /* *************************** external global vars ******************/
|
---|
69 | extern int g_current_media_number;
|
---|
70 | extern int g_currentY;
|
---|
71 | extern bool g_text_mode;
|
---|
72 | extern bool g_exiting;
|
---|
73 | extern long g_current_progress;
|
---|
74 | extern FILE *g_tape_stream;
|
---|
75 | extern long long g_tape_posK;
|
---|
76 | extern bool g_cd_recovery;
|
---|
77 | extern char *g_mondo_home;
|
---|
78 |
|
---|
79 | extern char *g_getfacl;
|
---|
80 | extern char *g_getfattr;
|
---|
81 | extern char *MONDO_LOGFILE;
|
---|
82 | extern char *MONDO_LOGFILENAME;
|
---|
83 |
|
---|
84 | /* Reference to global bkpinfo */
|
---|
85 | extern struct s_bkpinfo *bkpinfo;
|
---|
86 |
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * @addtogroup globalGroup
|
---|
90 | * @{
|
---|
91 | */
|
---|
92 | /**
|
---|
93 | * The current backup media type in use.
|
---|
94 | */
|
---|
95 | t_bkptype g_backup_media_type = none;
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Incremented by each archival thread when it starts up. After that,
|
---|
99 | * this is the number of threads running.
|
---|
100 | */
|
---|
101 | int g_current_thread_no = 0;
|
---|
102 |
|
---|
103 | /* @} - end of globalGroup */
|
---|
104 |
|
---|
105 | extern int g_noof_rows;
|
---|
106 |
|
---|
107 | /* Semaphore-related code */
|
---|
108 |
|
---|
109 | static int set_semvalue(void);
|
---|
110 | static void del_semvalue(void);
|
---|
111 | static int semaphore_p(void);
|
---|
112 | static int semaphore_v(void);
|
---|
113 |
|
---|
114 | static int g_sem_id;
|
---|
115 | static int g_sem_key;
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Initialize the semaphore.
|
---|
119 | * @see del_semvalue
|
---|
120 | * @see semaphore_p
|
---|
121 | * @see semaphore_v
|
---|
122 | * @return 1 for success, 0 for failure.
|
---|
123 | */
|
---|
124 | static int set_semvalue(void) // initializes semaphore
|
---|
125 | {
|
---|
126 | union semun sem_union;
|
---|
127 | sem_union.val = 1;
|
---|
128 | if (semctl(g_sem_id, 0, SETVAL, sem_union) == -1) {
|
---|
129 | return (0);
|
---|
130 | }
|
---|
131 | return (1);
|
---|
132 | }
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Frees (deletes) the semaphore. Failure is indicated by a log
|
---|
136 | * message.
|
---|
137 | * @see set_semvalue
|
---|
138 | */
|
---|
139 | static void del_semvalue(void) // deletes semaphore
|
---|
140 | {
|
---|
141 | union semun sem_union;
|
---|
142 |
|
---|
143 | if (semctl(g_sem_id, 0, IPC_RMID, sem_union) == -1) {
|
---|
144 | log_msg(3, "Failed to delete semaphore");
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * Acquire (increment) the semaphore (change status to P).
|
---|
150 | * @return 1 for success, 0 for failure.
|
---|
151 | * @see semaphore_v
|
---|
152 | */
|
---|
153 | static int semaphore_p(void) // changes status to 'P' (waiting)
|
---|
154 | {
|
---|
155 | struct sembuf sem_b;
|
---|
156 |
|
---|
157 | sem_b.sem_num = 0;
|
---|
158 | sem_b.sem_op = -1; // P()
|
---|
159 | sem_b.sem_flg = SEM_UNDO;
|
---|
160 | if (semop(g_sem_id, &sem_b, 1) == -1) {
|
---|
161 | log_msg(3, "semaphore_p failed");
|
---|
162 | return (0);
|
---|
163 | }
|
---|
164 | return (1);
|
---|
165 | }
|
---|
166 |
|
---|
167 | /**
|
---|
168 | * Free (decrement) the semaphore (change status to V).
|
---|
169 | * @return 1 for success, 0 for failure.
|
---|
170 | */
|
---|
171 | static int semaphore_v(void) // changes status to 'V' (free)
|
---|
172 | {
|
---|
173 | struct sembuf sem_b;
|
---|
174 |
|
---|
175 | sem_b.sem_num = 0;
|
---|
176 | sem_b.sem_op = 1; // V()
|
---|
177 | sem_b.sem_flg = SEM_UNDO;
|
---|
178 | if (semop(g_sem_id, &sem_b, 1) == -1) {
|
---|
179 | log_msg(3, "semaphore_v failed");
|
---|
180 | return (0);
|
---|
181 | }
|
---|
182 | return (1);
|
---|
183 | }
|
---|
184 |
|
---|
185 |
|
---|
186 | //------------------------------------------------------
|
---|
187 |
|
---|
188 |
|
---|
189 | /**
|
---|
190 | * Size in megabytes of the buffer afforded to the executable "buffer".
|
---|
191 | * This figure is used when we calculate how much data we have probably 'lost'
|
---|
192 | * when writing off the end of tape N, so that we can then figure out how much
|
---|
193 | * data we must recreate & write to the start of tape N+1.
|
---|
194 | */
|
---|
195 | extern int g_tape_buffer_size_MB;
|
---|
196 |
|
---|
197 | /**
|
---|
198 | * Call @c afio to archive the filelist @c filelist to the file @c fname.
|
---|
199 | *
|
---|
200 | * @param bkpinfo The backup information structure. Fields used:
|
---|
201 | * - @c compression_level
|
---|
202 | * - @c scratchdir (only verifies existence)
|
---|
203 | * - @c tmpdir (only verifies existence)
|
---|
204 | * - @c zip_exe
|
---|
205 | * - @c zip_suffix
|
---|
206 | * @param filelist The path to a file containing a list of files to be archived
|
---|
207 | * in this fileset.
|
---|
208 | * @param fname The output file to archive to.
|
---|
209 | * @param setno This fileset number.
|
---|
210 | * @return The number of errors encountered (0 for success).
|
---|
211 | * @ingroup LLarchiveGroup
|
---|
212 | */
|
---|
213 | int
|
---|
214 | archive_this_fileset(char *filelist, char *fname, int setno)
|
---|
215 | {
|
---|
216 |
|
---|
217 | /*@ int *************************************************************** */
|
---|
218 | int retval = 0;
|
---|
219 | unsigned int res = 0;
|
---|
220 | int tries = 0;
|
---|
221 | /*
|
---|
222 | int i = 0;
|
---|
223 | static int free_ramdisk_space = 9999;
|
---|
224 | */
|
---|
225 |
|
---|
226 | /*@ buffers ************************************************************ */
|
---|
227 | char *command = NULL;
|
---|
228 | char *zipparams = NULL;
|
---|
229 | char *tmp = NULL;
|
---|
230 | char *p = NULL;
|
---|
231 |
|
---|
232 | assert(bkpinfo != NULL);
|
---|
233 | assert_string_is_neither_NULL_nor_zerolength(filelist);
|
---|
234 | assert_string_is_neither_NULL_nor_zerolength(fname);
|
---|
235 |
|
---|
236 | if (!does_file_exist(bkpinfo->tmpdir)) {
|
---|
237 | log_OS_error("tmpdir not found");
|
---|
238 | fatal_error("tmpdir not found");
|
---|
239 | }
|
---|
240 | if (!does_file_exist(bkpinfo->scratchdir)) {
|
---|
241 | log_OS_error("scratchdir not found");
|
---|
242 | fatal_error("scratchdir not found");
|
---|
243 | }
|
---|
244 |
|
---|
245 | if (!does_file_exist(filelist)) {
|
---|
246 | log_to_screen("(archive_this_fileset) - filelist %s does not exist", filelist);
|
---|
247 | return (1);
|
---|
248 | }
|
---|
249 | mr_asprintf(tmp, "echo hi > %s 2> /dev/null", fname);
|
---|
250 | if (system(tmp)) {
|
---|
251 | mr_free(tmp);
|
---|
252 | fatal_error("Unable to write tarball to scratchdir");
|
---|
253 | }
|
---|
254 | mr_free(tmp);
|
---|
255 |
|
---|
256 |
|
---|
257 | if (bkpinfo->compression_level > 0) {
|
---|
258 | if (bkpinfo->use_star) {
|
---|
259 | if (bkpinfo->use_lzo) {
|
---|
260 | fatal_error("Can't use lzop with star");
|
---|
261 | }
|
---|
262 | mr_asprintf(zipparams, " -bz");
|
---|
263 | } else {
|
---|
264 | mr_asprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
|
---|
265 | // -b %ld, TAPE_BLOCK_SIZE
|
---|
266 | mr_asprintf(zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe, bkpinfo->compression_level);
|
---|
267 | if (does_file_exist(tmp)) {
|
---|
268 | mr_strcat(zipparams, " -E %s",tmp);
|
---|
269 | } else {
|
---|
270 | log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp);
|
---|
271 | }
|
---|
272 | mr_free(tmp);
|
---|
273 | }
|
---|
274 | } else {
|
---|
275 | mr_asprintf(zipparams, "");
|
---|
276 | }
|
---|
277 |
|
---|
278 | mr_asprintf(command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname, fname, bkpinfo->zip_suffix);
|
---|
279 | paranoid_system(command);
|
---|
280 | mr_free(command);
|
---|
281 |
|
---|
282 | if (bkpinfo->use_star) {
|
---|
283 | mr_asprintf(command, "star H=exustar list=%s -c -sparse " STAR_ACL_SZ " file=%s %s 2>> %s", filelist, fname, zipparams, MONDO_LOGFILE);
|
---|
284 | } else {
|
---|
285 | mr_asprintf(command, "afio -o -b %ld -M 16m %s %s < %s 2>> %s", TAPE_BLOCK_SIZE, zipparams, fname, filelist, MONDO_LOGFILE);
|
---|
286 | }
|
---|
287 | mr_free(zipparams);
|
---|
288 | log_msg(4, "command = '%s'", command);
|
---|
289 |
|
---|
290 | for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
|
---|
291 | log_msg(5, "command='%s'", command);
|
---|
292 | res = system(command);
|
---|
293 |
|
---|
294 | if (bkpinfo->use_star) {
|
---|
295 | mr_asprintf(tmp, "%s", last_line_of_file(MONDO_LOGFILE));
|
---|
296 | log_msg(1, "res=%d; tmp='%s'", res, tmp);
|
---|
297 | if ((res == 254 || res == 65024) && strstr(tmp, "star: Processed all possible files") && tries > 0) {
|
---|
298 | log_msg(1, "Star returned nonfatal error");
|
---|
299 | res = 0;
|
---|
300 | }
|
---|
301 | mr_free(tmp);
|
---|
302 | }
|
---|
303 | if (res) {
|
---|
304 | log_OS_error(command);
|
---|
305 | if (bkpinfo->use_star) {
|
---|
306 | p = strstr(command, "-acl ");
|
---|
307 | if (p) {
|
---|
308 | p[0] = p[1] = p[2] = p[3] = ' ';
|
---|
309 | log_msg(1, "new command = '%s'", command);
|
---|
310 | }
|
---|
311 | }
|
---|
312 | log_msg(3, "Attempt #%d failed. Pausing 3 seconds and retrying...", tries + 1);
|
---|
313 | sleep(3);
|
---|
314 | }
|
---|
315 | }
|
---|
316 | mr_free(command);
|
---|
317 |
|
---|
318 | retval += res;
|
---|
319 | if (retval) {
|
---|
320 | log_msg(3, "Failed to write set %d", setno);
|
---|
321 | } else if (tries > 1) {
|
---|
322 | log_msg(3, "Succeeded in writing set %d, on try #%d", setno, tries);
|
---|
323 | }
|
---|
324 |
|
---|
325 | return (retval);
|
---|
326 | }
|
---|
327 |
|
---|
328 |
|
---|
329 | /**
|
---|
330 | * Remove the archives in @c d.
|
---|
331 | * This could possibly include any of:
|
---|
332 | * - all afioballs (compressed and not)
|
---|
333 | * - all filelists
|
---|
334 | * - all slices
|
---|
335 | * - all checksums
|
---|
336 | * - a zero filler file
|
---|
337 | *
|
---|
338 | * @param d The directory to wipe the archives from.
|
---|
339 | * @ingroup utilityGroup
|
---|
340 | */
|
---|
341 | void wipe_archives(char *d)
|
---|
342 | {
|
---|
343 | /*@ buffers ********************************************* */
|
---|
344 | char *tmp = NULL;
|
---|
345 | char *dir = NULL;
|
---|
346 |
|
---|
347 | assert_string_is_neither_NULL_nor_zerolength(d);
|
---|
348 |
|
---|
349 | mr_asprintf(dir, "%s/archives", d);
|
---|
350 | mr_asprintf(tmp, "rm -f %s/*.afio.* %s/*.star.*", dir, dir);
|
---|
351 | run_program_and_log_output(tmp, FALSE);
|
---|
352 | mr_free(tmp);
|
---|
353 | mr_asprintf(tmp, "rm -f %s/*list.[0-9]* %s/slice*", dir, dir);
|
---|
354 | run_program_and_log_output(tmp, FALSE);
|
---|
355 | mr_free(tmp);
|
---|
356 | mr_asprintf(tmp, "rm -f %s/cklist* %s/zero", dir, dir);
|
---|
357 | run_program_and_log_output(tmp, FALSE);
|
---|
358 | mr_free(tmp);
|
---|
359 | log_msg(1, "Wiped %s's archives", dir);
|
---|
360 | mr_asprintf(tmp, "ls -l %s", dir);
|
---|
361 | mr_free(dir);
|
---|
362 | run_program_and_log_output(tmp, FALSE);
|
---|
363 | mr_free(tmp);
|
---|
364 | }
|
---|
365 |
|
---|
366 |
|
---|
367 | /**
|
---|
368 | * Create a USB image in @c destfile, from files in @c bkpinfo->scratchdir.
|
---|
369 | *
|
---|
370 | * @param bkpinfo The backup information structure. Fields used:
|
---|
371 | * - @c backup_media_type
|
---|
372 | * - @c scratchdir
|
---|
373 | *
|
---|
374 | * @param destfile Where to put the generated USB image.
|
---|
375 | * @return The number of errors encountered (0 for success)
|
---|
376 | */
|
---|
377 | int make_usb_fs()
|
---|
378 | {
|
---|
379 | /*@ int ********************************************** */
|
---|
380 | int retval = 0;
|
---|
381 | int res;
|
---|
382 |
|
---|
383 | /*@ buffers ****************************************** */
|
---|
384 | char *tmp = NULL;
|
---|
385 | char *tmp1 = NULL;
|
---|
386 | char *result_sz = NULL;
|
---|
387 | char *message_to_screen = NULL;
|
---|
388 | char *old_pwd = NULL;
|
---|
389 | char *mds = NULL;
|
---|
390 |
|
---|
391 | assert(bkpinfo != NULL);
|
---|
392 |
|
---|
393 | log_msg(2, "make_usb_fs --- scratchdir=%s", bkpinfo->scratchdir);
|
---|
394 | old_pwd = mr_getcwd();
|
---|
395 | mr_asprintf(tmp, "chmod 700 %s", bkpinfo->scratchdir);
|
---|
396 | run_program_and_log_output(tmp, FALSE);
|
---|
397 | mr_free(tmp);
|
---|
398 | if (chdir(bkpinfo->scratchdir)) {
|
---|
399 | // FIXME
|
---|
400 | }
|
---|
401 |
|
---|
402 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
---|
403 | mr_asprintf(message_to_screen, "Copying data to make %s #%d",mds, g_current_media_number);
|
---|
404 | mr_free(mds);
|
---|
405 | log_msg(1, message_to_screen);
|
---|
406 |
|
---|
407 | if (bkpinfo->media_device) {
|
---|
408 | mr_asprintf(tmp1, "%s1", bkpinfo->media_device);
|
---|
409 | } else {
|
---|
410 | mr_asprintf(tmp1, "");
|
---|
411 | }
|
---|
412 | if (is_this_device_mounted(tmp1)) {
|
---|
413 | log_msg(1, "USB device mounted. Remounting it at the right place");
|
---|
414 | mr_asprintf(tmp, "umount %s", tmp1);
|
---|
415 | run_program_and_log_output(tmp, FALSE);
|
---|
416 | mr_free(tmp);
|
---|
417 | }
|
---|
418 | mr_free(tmp1);
|
---|
419 |
|
---|
420 | log_msg(1, "Mounting USB device.");
|
---|
421 | mr_asprintf(tmp1, "%s/usb", bkpinfo->tmpdir);
|
---|
422 | mr_asprintf(tmp, "mkdir -p %s", tmp1);
|
---|
423 | run_program_and_log_output(tmp, FALSE);
|
---|
424 | mr_free(tmp);
|
---|
425 |
|
---|
426 |
|
---|
427 | /* Mindi always create one single parition on the USB dev */
|
---|
428 | mr_asprintf(tmp, "mount %s1 %s", bkpinfo->media_device, tmp1);
|
---|
429 | run_program_and_log_output(tmp, FALSE);
|
---|
430 | mr_free(tmp);
|
---|
431 |
|
---|
432 | log_msg(1, "Making bootable backup");
|
---|
433 |
|
---|
434 | /* Command to execute */
|
---|
435 | mr_asprintf(tmp,"cd %s ; rm -fr %s/syslinux ; mv * %s", bkpinfo->scratchdir, tmp1, tmp1);
|
---|
436 | res = eval_call_to_make_USB(tmp, message_to_screen);
|
---|
437 | if (res) {
|
---|
438 | mr_asprintf(result_sz, "%s ...failed",tmp);
|
---|
439 | } else {
|
---|
440 | mr_asprintf(result_sz, "%s ...OK",tmp);
|
---|
441 | }
|
---|
442 | log_to_screen(result_sz);
|
---|
443 | mr_free(result_sz);
|
---|
444 | mr_free(tmp);
|
---|
445 | retval += res;
|
---|
446 |
|
---|
447 | /* Recreate the required structure under the scratch dir */
|
---|
448 | mr_asprintf(tmp,"mkdir %s/archive", bkpinfo->scratchdir);
|
---|
449 | run_program_and_log_output(tmp, FALSE);
|
---|
450 | mr_free(tmp);
|
---|
451 | paranoid_free(message_to_screen);
|
---|
452 |
|
---|
453 | /* Copy the current logfile - of course incomplete to the media */
|
---|
454 | mr_system("gzip -c9 %s > %s/archives/%s", MONDO_LOGFILE, tmp1, MONDO_LOGFILENAME);
|
---|
455 | paranoid_free(tmp1);
|
---|
456 |
|
---|
457 | if (is_this_device_mounted(bkpinfo->media_device)) {
|
---|
458 | mr_asprintf(tmp, "umount %s1", bkpinfo->media_device);
|
---|
459 | run_program_and_log_output(tmp, FALSE);
|
---|
460 | mr_free(tmp);
|
---|
461 | }
|
---|
462 |
|
---|
463 | if (chdir(old_pwd)) {
|
---|
464 | // FIXME
|
---|
465 | }
|
---|
466 | mr_free(old_pwd);
|
---|
467 | if (retval) {
|
---|
468 | log_msg(1, "WARNING - make_usb_fs returned an error");
|
---|
469 | }
|
---|
470 | return(retval);
|
---|
471 | }
|
---|
472 |
|
---|
473 |
|
---|
474 | /**
|
---|
475 | * Make sure the user has a valid CD-R(W) in the CD drive.
|
---|
476 | * @param cd_dev Set to the CD-R(W) device checked.
|
---|
477 | * @param keep_looping If TRUE, keep pestering user until they insist
|
---|
478 | * or insert a correct CD; if FALSE, only check once.
|
---|
479 | * @return 0 (there was an OK CD in the drive) or 1 (there wasn't).
|
---|
480 | */
|
---|
481 | int interrogate_disk_currently_in_cddrive(char *cd_dev,
|
---|
482 | bool keep_looping)
|
---|
483 | {
|
---|
484 | int res = 0;
|
---|
485 | char *bkp = NULL;
|
---|
486 | char *cdrecord = NULL;
|
---|
487 |
|
---|
488 | mr_asprintf(bkp, "%s", cd_dev);
|
---|
489 | if ((cd_dev = find_optical_device()) != NULL) {
|
---|
490 | if (!system("which cdrecord > /dev/null 2> /dev/null")) {
|
---|
491 | mr_asprintf(cdrecord, "cdrecord dev=%s -atip", cd_dev);
|
---|
492 | } else {
|
---|
493 | log_msg(2, "Oh well. I guess I'll just pray then.");
|
---|
494 | }
|
---|
495 | if (cdrecord != NULL) {
|
---|
496 | if (!keep_looping) {
|
---|
497 | retract_CD_tray_and_defeat_autorun();
|
---|
498 | res = run_program_and_log_output(cdrecord, 5);
|
---|
499 | } else {
|
---|
500 | while ((res = run_program_and_log_output(cdrecord, 5))) {
|
---|
501 | retract_CD_tray_and_defeat_autorun();
|
---|
502 | if (ask_me_yes_or_no
|
---|
503 | ("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?"))
|
---|
504 | {
|
---|
505 | log_msg(1, "Well, he insisted...");
|
---|
506 | break;
|
---|
507 | }
|
---|
508 | }
|
---|
509 | }
|
---|
510 | }
|
---|
511 | }
|
---|
512 | mr_free(bkp);
|
---|
513 |
|
---|
514 | mr_free(cdrecord);
|
---|
515 | return (res);
|
---|
516 | }
|
---|
517 |
|
---|
518 |
|
---|
519 | /**
|
---|
520 | * Asks the user to put a CD-R(W) in the drive.
|
---|
521 | * @param ask_for_one_if_more_than_this (unused)
|
---|
522 | * @param pmountable If non-NULL, pointed-to value is set to TRUE if the CD is mountable, FALSE otherwise.
|
---|
523 | */
|
---|
524 | void pause_and_ask_for_cdr(int ask_for_one_if_more_than_this, bool * pmountable) {
|
---|
525 |
|
---|
526 | /*@ buffers ********************************************* */
|
---|
527 | char *tmp = NULL;
|
---|
528 | char *cdrom_dev = NULL;
|
---|
529 | char *cd_dev = NULL;
|
---|
530 | char *our_serial_str = NULL;
|
---|
531 | bool ok_go_ahead_burn_it;
|
---|
532 | int cd_number = -1;
|
---|
533 | int attempt_to_mount_returned_this = 999;
|
---|
534 | char *mtpt = NULL;
|
---|
535 | char *szcdno = NULL;
|
---|
536 | char *szserfname = NULL;
|
---|
537 | char *szunmount = NULL;
|
---|
538 | char *mds = NULL;
|
---|
539 |
|
---|
540 | malloc_string(cd_dev);
|
---|
541 |
|
---|
542 | mds = media_descriptor_string(g_backup_media_type);
|
---|
543 | log_to_screen("I am about to burn %s #%d", mds, g_current_media_number);
|
---|
544 | mr_free(mds);
|
---|
545 | if (g_current_media_number < ask_for_one_if_more_than_this) {
|
---|
546 | return;
|
---|
547 | }
|
---|
548 | log_to_screen("Scanning CD-ROM drive...");
|
---|
549 | mr_asprintf(mtpt, "%s/cd.mtpt", bkpinfo->tmpdir);
|
---|
550 | make_hole_for_dir(mtpt);
|
---|
551 |
|
---|
552 | gotos_make_me_puke:
|
---|
553 | ok_go_ahead_burn_it = TRUE;
|
---|
554 | mr_free(cdrom_dev);
|
---|
555 | if ((cdrom_dev = find_optical_device()) != NULL) {
|
---|
556 | /* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird
|
---|
557 | log_msg(2, "paafcd: Retracting CD-ROM drive if possible" );
|
---|
558 | retract_CD_tray_and_defeat_autorun();
|
---|
559 | */
|
---|
560 | mr_asprintf(tmp, "umount %s", cdrom_dev);
|
---|
561 | run_program_and_log_output(tmp, 1);
|
---|
562 | mr_asprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
|
---|
563 | mr_asprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt);
|
---|
564 | mr_asprintf(szunmount, "umount %s", mtpt);
|
---|
565 | cd_number = -1;
|
---|
566 | mr_asprintf(tmp, "mount %s %s", cdrom_dev, mtpt);
|
---|
567 | mr_asprintf(our_serial_str, "%s", "");
|
---|
568 | attempt_to_mount_returned_this = run_program_and_log_output(tmp, 1);
|
---|
569 | mr_free(tmp);
|
---|
570 |
|
---|
571 | if (attempt_to_mount_returned_this) {
|
---|
572 | log_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
|
---|
573 | log_to_screen("If there's a CD/DVD in the drive, it's blank.");
|
---|
574 | } else if (!does_file_exist(szcdno) || !does_file_exist(szserfname)) {
|
---|
575 | mds = media_descriptor_string(g_backup_media_type);
|
---|
576 | log_to_screen("%s has data on it but it's probably not a Mondo CD.", mds);
|
---|
577 | mr_free(mds);
|
---|
578 | } else {
|
---|
579 | mds = media_descriptor_string(g_backup_media_type);
|
---|
580 | log_to_screen("%s found in drive. It's a Mondo disk.", mds);
|
---|
581 | mr_free(mds);
|
---|
582 |
|
---|
583 | cd_number = atoi(last_line_of_file(szcdno));
|
---|
584 | mr_asprintf(tmp, "cat %s 2> /dev/null", szserfname);
|
---|
585 | mr_free(our_serial_str);
|
---|
586 | our_serial_str = call_program_and_get_last_line_of_output(tmp);
|
---|
587 | mr_free(tmp);
|
---|
588 | // FIXME - should be able to use last_line_of_file(), surely?
|
---|
589 | }
|
---|
590 | mr_free(szcdno);
|
---|
591 | mr_free(szserfname);
|
---|
592 |
|
---|
593 | run_program_and_log_output(szunmount, 1);
|
---|
594 | mr_free(szunmount);
|
---|
595 |
|
---|
596 | log_msg(2, "paafcd: cd_number = %d", cd_number);
|
---|
597 | log_msg(2, "our serial str = %s; bkpinfo->serial_string = %s", our_serial_str, bkpinfo->serial_string);
|
---|
598 | if (cd_number > 0 && !strcmp(our_serial_str, bkpinfo->serial_string)) {
|
---|
599 | mds = media_descriptor_string(g_backup_media_type);
|
---|
600 | log_msg(2, "This %s is part of this backup set!", mds);
|
---|
601 | ok_go_ahead_burn_it = FALSE;
|
---|
602 | if (cd_number == g_current_media_number - 1) {
|
---|
603 | log_to_screen("I think you've left the previous %s in the drive.", mds);
|
---|
604 | } else {
|
---|
605 | log_to_screen("Please remove this %s. It is part of the backup set you're making now.", mds);
|
---|
606 | }
|
---|
607 | mr_free(mds);
|
---|
608 |
|
---|
609 | } else {
|
---|
610 | log_to_screen("...but not part of _our_ backup set.");
|
---|
611 | }
|
---|
612 | mr_free(our_serial_str);
|
---|
613 | } else {
|
---|
614 | mds = media_descriptor_string(g_backup_media_type);
|
---|
615 | log_msg(2,
|
---|
616 | "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?", mds);
|
---|
617 | if (interrogate_disk_currently_in_cddrive(cd_dev, FALSE)) {
|
---|
618 | ok_go_ahead_burn_it = FALSE;
|
---|
619 | log_to_screen("There isn't a writable %s in the drive.", mds);
|
---|
620 | }
|
---|
621 | mr_free(mds);
|
---|
622 | }
|
---|
623 |
|
---|
624 | if (!ok_go_ahead_burn_it) {
|
---|
625 | if (!bkpinfo->please_dont_eject) {
|
---|
626 | eject_device(cdrom_dev);
|
---|
627 | }
|
---|
628 | mds = media_descriptor_string(g_backup_media_type);
|
---|
629 | mr_asprintf(tmp, "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.", mds, g_current_media_number, mds);
|
---|
630 | mr_free(mds);
|
---|
631 |
|
---|
632 | popup_and_OK(tmp);
|
---|
633 | mr_free(tmp);
|
---|
634 | goto gotos_make_me_puke;
|
---|
635 | } else {
|
---|
636 | log_msg(2, "paafcd: OK, going ahead and burning it.");
|
---|
637 | }
|
---|
638 |
|
---|
639 | mds = media_descriptor_string(g_backup_media_type);
|
---|
640 | log_msg(2, "paafcd: OK, I assume I have a blank/reusable %s in the drive...", mds);
|
---|
641 |
|
---|
642 | log_to_screen("Proceeding w/ %s in drive.", mds);
|
---|
643 | mr_free(mds);
|
---|
644 |
|
---|
645 | mr_free(cdrom_dev);
|
---|
646 | paranoid_free(cd_dev);
|
---|
647 | mr_free(mtpt);
|
---|
648 | if (pmountable) {
|
---|
649 | if (attempt_to_mount_returned_this) {
|
---|
650 | *pmountable = FALSE;
|
---|
651 | } else {
|
---|
652 | *pmountable = TRUE;
|
---|
653 | }
|
---|
654 | }
|
---|
655 |
|
---|
656 | }
|
---|
657 |
|
---|
658 |
|
---|
659 | /**
|
---|
660 | * @addtogroup LLarchiveGroup
|
---|
661 | * @{
|
---|
662 | */
|
---|
663 |
|
---|
664 | void pause_for_N_seconds(int how_long, char *msg)
|
---|
665 | {
|
---|
666 | int i;
|
---|
667 | open_evalcall_form(msg);
|
---|
668 | for (i = 0; i < how_long; i++) {
|
---|
669 | update_evalcall_form((int) ((100.0 / (float) (how_long) * i)));
|
---|
670 | sleep(1);
|
---|
671 | }
|
---|
672 | close_evalcall_form();
|
---|
673 | }
|
---|
674 |
|
---|
675 |
|
---|
676 | /**
|
---|
677 | * Create an ISO image in @c destfile, from files in @c bkpinfo->scratchdir.
|
---|
678 | *
|
---|
679 | * @param bkpinfo The backup information structure. Fields used:
|
---|
680 | * - @c backup_media_type
|
---|
681 | * - @c call_after_iso
|
---|
682 | * - @c call_before_iso
|
---|
683 | * - @c call_burn_iso
|
---|
684 | * - @c call_make_iso
|
---|
685 | * - @c make_cd_use_lilo
|
---|
686 | * - @c manual_cd_tray
|
---|
687 | * - @c scratchdir
|
---|
688 | *
|
---|
689 | * @param destfile Where to put the generated ISO image.
|
---|
690 | * @return The number of errors encountered (0 for success)
|
---|
691 | */
|
---|
692 | int make_iso_fs(char *destfile) {
|
---|
693 | /*@ int ********************************************** */
|
---|
694 | int retval = 0;
|
---|
695 | int res;
|
---|
696 |
|
---|
697 | /*@ buffers ****************************************** */
|
---|
698 | char *tmp = NULL;
|
---|
699 | char *old_pwd = NULL;
|
---|
700 | char *result_sz = NULL;
|
---|
701 | char *message_to_screen = NULL;
|
---|
702 | char *sz_blank_disk = NULL;
|
---|
703 | char *isofs_cmd = NULL;
|
---|
704 | char *full_isofs_cmd = NULL;
|
---|
705 | char *mds = NULL;
|
---|
706 | char *uefistr = NULL;
|
---|
707 | bool cd_is_mountable;
|
---|
708 |
|
---|
709 | assert(bkpinfo != NULL);
|
---|
710 | assert_string_is_neither_NULL_nor_zerolength(destfile);
|
---|
711 |
|
---|
712 | if (bkpinfo->backup_media_type == iso && bkpinfo->manual_cd_tray) {
|
---|
713 | popup_and_OK("Please insert new media and press Enter.");
|
---|
714 | }
|
---|
715 |
|
---|
716 | log_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s", bkpinfo->scratchdir, destfile);
|
---|
717 | old_pwd = mr_getcwd();
|
---|
718 | mr_asprintf(tmp, "chmod 700 %s", bkpinfo->scratchdir);
|
---|
719 | run_program_and_log_output(tmp, FALSE);
|
---|
720 | mr_free(tmp);
|
---|
721 |
|
---|
722 | if (chdir(bkpinfo->scratchdir)) {
|
---|
723 | // FIXME
|
---|
724 | }
|
---|
725 |
|
---|
726 | if (bkpinfo->call_before_iso != NULL) {
|
---|
727 | mr_asprintf(message_to_screen, "Running pre-ISO call for CD#%d", g_current_media_number);
|
---|
728 | res = eval_call_to_make_ISO(bkpinfo->call_before_iso, destfile, g_current_media_number, message_to_screen);
|
---|
729 | if (res) {
|
---|
730 | mr_strcat(message_to_screen, "...failed");
|
---|
731 | } else {
|
---|
732 | mr_strcat(message_to_screen, "...OK");
|
---|
733 | }
|
---|
734 | log_to_screen(message_to_screen);
|
---|
735 | paranoid_free(message_to_screen);
|
---|
736 |
|
---|
737 | retval += res;
|
---|
738 | }
|
---|
739 |
|
---|
740 | if (bkpinfo->call_make_iso != NULL) {
|
---|
741 | log_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
|
---|
742 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
---|
743 | mr_asprintf(message_to_screen, "Making an ISO (%s #%d)", mds, g_current_media_number);
|
---|
744 | mr_free(mds);
|
---|
745 |
|
---|
746 | pause_and_ask_for_cdr(2, &cd_is_mountable); /* if g_current_media_number >= 2 then pause & ask */
|
---|
747 | if (retval) {
|
---|
748 | log_to_screen
|
---|
749 | ("Serious error(s) occurred already. I shan't try to write to media.");
|
---|
750 | } else {
|
---|
751 | res = eval_call_to_make_ISO(bkpinfo->call_make_iso, bkpinfo->scratchdir, g_current_media_number, message_to_screen);
|
---|
752 | if (res) {
|
---|
753 | log_to_screen("%s...failed to write", message_to_screen);
|
---|
754 | } else {
|
---|
755 | log_to_screen("%s...OK", message_to_screen);
|
---|
756 | mr_asprintf(tmp, "tail -n10 %s | grep -F ':-('", MONDO_LOGFILE);
|
---|
757 | if (!run_program_and_log_output(tmp, 1)) {
|
---|
758 | log_to_screen
|
---|
759 | ("Despite nonfatal errors, growisofs confirms the write was successful.");
|
---|
760 | }
|
---|
761 | mr_free(tmp);
|
---|
762 | }
|
---|
763 | retval += res;
|
---|
764 | if (bkpinfo->wipe_media_first) {
|
---|
765 | mr_asprintf(tmp, "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'", MONDO_LOGFILE);
|
---|
766 | if (g_backup_media_type == optical && (res || !run_program_and_log_output(tmp, 1))) {
|
---|
767 | log_to_screen("Failed to write to disk. I shall blank it and then try again.");
|
---|
768 | sleep(5);
|
---|
769 | /* reset error counter before trying to blank media */
|
---|
770 | retval -= res;
|
---|
771 | sync();
|
---|
772 | pause_for_N_seconds(5, "Letting DVD drive settle");
|
---|
773 |
|
---|
774 | if (!bkpinfo->please_dont_eject) {
|
---|
775 | log_to_screen("Ejecting media to clear drive status.");
|
---|
776 | eject_device(bkpinfo->media_device);
|
---|
777 | inject_device(bkpinfo->media_device);
|
---|
778 | }
|
---|
779 | pause_for_N_seconds(5, "Letting optical drive settle");
|
---|
780 |
|
---|
781 | // dvd+rw-format --- OPTION 2
|
---|
782 | if (bkpinfo->media_device) {
|
---|
783 | mr_asprintf(sz_blank_disk, "dvd+rw-format -force %s", bkpinfo->media_device);
|
---|
784 | } else {
|
---|
785 | mr_asprintf(sz_blank_disk, "dvd+rw-format");
|
---|
786 | }
|
---|
787 | log_msg(3, "sz_blank_disk = '%s'", sz_blank_disk);
|
---|
788 | res = run_external_binary_with_percentage_indicator_NEW("Blanking optical disk", sz_blank_disk);
|
---|
789 | if (res) {
|
---|
790 | log_to_screen("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath...");
|
---|
791 | pause_for_N_seconds(5, "Letting optical drive settle... and trying again.");
|
---|
792 | res = run_external_binary_with_percentage_indicator_NEW("Blanking optical disk", sz_blank_disk);
|
---|
793 | if (res) {
|
---|
794 | log_to_screen("Format failed a second time.");
|
---|
795 | }
|
---|
796 | } else {
|
---|
797 | log_to_screen
|
---|
798 | ("Format succeeded. Sleeping for 5 seconds to take a breath...");
|
---|
799 | }
|
---|
800 | mr_free(sz_blank_disk);
|
---|
801 | pause_for_N_seconds(5, "Letting optical drive settle");
|
---|
802 | if (!bkpinfo->please_dont_eject) {
|
---|
803 | log_to_screen("Ejecting media to clear drive status.");
|
---|
804 | eject_device(bkpinfo->media_device);
|
---|
805 | inject_device(bkpinfo->media_device);
|
---|
806 | }
|
---|
807 | pause_for_N_seconds(5, "Letting optical drive settle");
|
---|
808 | res = eval_call_to_make_ISO(bkpinfo->call_make_iso, bkpinfo->scratchdir, g_current_media_number, message_to_screen);
|
---|
809 | retval += res;
|
---|
810 | if (!bkpinfo->please_dont_eject) {
|
---|
811 | log_to_screen("Ejecting media.");
|
---|
812 | eject_device(bkpinfo->media_device);
|
---|
813 | }
|
---|
814 | if (res) {
|
---|
815 | log_to_screen("Dagnabbit. It still failed.");
|
---|
816 | } else {
|
---|
817 | log_to_screen
|
---|
818 | ("OK, this time I successfully backed up to DVD.");
|
---|
819 | }
|
---|
820 | }
|
---|
821 | mr_free(tmp);
|
---|
822 | }
|
---|
823 | if (g_backup_media_type == optical && !bkpinfo->please_dont_eject) {
|
---|
824 | eject_device(bkpinfo->media_device);
|
---|
825 | }
|
---|
826 | }
|
---|
827 | paranoid_free(message_to_screen);
|
---|
828 | } else {
|
---|
829 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
---|
830 | mr_asprintf(message_to_screen, "Running mkisofs to make %s #%d", mds, g_current_media_number);
|
---|
831 | log_msg(1, message_to_screen);
|
---|
832 | mr_asprintf(result_sz, "Call to mkisofs to make ISO (%s #%d) ", mds, g_current_media_number);
|
---|
833 | mr_free(mds);
|
---|
834 | if ((tmp = find_home_of_exe("xorriso")) != NULL) {
|
---|
835 | mr_asprintf(isofs_cmd, "%s %s", tmp, MONDO_XORRISO_OPT);
|
---|
836 | } else if ((tmp = find_home_of_exe("genisoimage")) != NULL) {
|
---|
837 | mr_asprintf(isofs_cmd, "%s %s", tmp, MONDO_GENISOIMAGE_OPT);
|
---|
838 | } else if ((tmp = find_home_of_exe("mkisofs")) != NULL) {
|
---|
839 | mr_asprintf(isofs_cmd, "%s %s", tmp, MONDO_MKISOFS_OPT);
|
---|
840 | } else if ((tmp = find_home_of_exe("wodim")) != NULL) {
|
---|
841 | mr_asprintf(isofs_cmd, "%s %s", tmp, MONDO_WODIM_OPT);
|
---|
842 | } else {
|
---|
843 | fatal_error("Unable to find a command to create ISO among xorriso, genisoimage, mksiofs or wodim, please install one");
|
---|
844 | }
|
---|
845 | mr_free(tmp);
|
---|
846 | log_msg(1, "Making bootable backup");
|
---|
847 |
|
---|
848 | #ifdef __FreeBSD__
|
---|
849 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
850 | #endif
|
---|
851 |
|
---|
852 |
|
---|
853 | log_msg(1, "make_cd_use_lilo is actually %d", bkpinfo->make_cd_use_lilo);
|
---|
854 | if (bkpinfo->make_cd_use_lilo) {
|
---|
855 | log_msg(1, "make_cd_use_lilo = TRUE");
|
---|
856 | mr_asprintf(full_isofs_cmd, "%s%s-b images/mindi-bootroot.img -c images/boot.cat -o '_ISO_' .",isofs_cmd,MONDO_MKISOFS);
|
---|
857 | // FIXME: fixed boot size probably wrong. lilo to be removed
|
---|
858 | res = eval_call_to_make_ISO(full_isofs_cmd, destfile, g_current_media_number, message_to_screen);
|
---|
859 | mr_free(full_isofs_cmd);
|
---|
860 | } else {
|
---|
861 | log_msg(1, "make_cd_use_lilo = FALSE");
|
---|
862 | log_msg(1, "Isolinux");
|
---|
863 | if (bkpinfo->boot_type == UEFI) {
|
---|
864 | if (strstr(isofs_cmd,"xorriso")) {
|
---|
865 | /* xorriso needs another '-' before efi-boot */
|
---|
866 | mr_asprintf(uefistr, "%s -%s", MONDO_UEFI_PREFIX, MONDO_MKISOFS_UEFI);
|
---|
867 | } else {
|
---|
868 | mr_asprintf(uefistr, "%s %s", MONDO_UEFI_PREFIX, MONDO_MKISOFS_UEFI);
|
---|
869 | }
|
---|
870 | } else {
|
---|
871 | mr_asprintf(uefistr, "%s",MONDO_MKISOFS_CMS);
|
---|
872 | }
|
---|
873 | mr_asprintf(full_isofs_cmd, "%s%s%s-o '_ISO_' .",isofs_cmd,MONDO_MKISOFS_REGULAR_SYSLINUX,uefistr);
|
---|
874 | mr_free(uefistr);
|
---|
875 |
|
---|
876 | res = eval_call_to_make_ISO(full_isofs_cmd, destfile, g_current_media_number, message_to_screen);
|
---|
877 | mr_free(full_isofs_cmd);
|
---|
878 | }
|
---|
879 | mr_free(isofs_cmd);
|
---|
880 | paranoid_free(message_to_screen);
|
---|
881 |
|
---|
882 | if (res) {
|
---|
883 | mr_strcat(result_sz, "...failed");
|
---|
884 | } else {
|
---|
885 | mr_strcat(result_sz, "...OK");
|
---|
886 | }
|
---|
887 | log_to_screen(result_sz);
|
---|
888 | paranoid_free(result_sz);
|
---|
889 | retval += res;
|
---|
890 | }
|
---|
891 |
|
---|
892 | if (bkpinfo->backup_media_type == optical) {
|
---|
893 | if (is_this_device_mounted(bkpinfo->media_device)) {
|
---|
894 | log_msg(2, "Warning - %s mounted. I'm unmounting it before I burn to it.", bkpinfo->media_device);
|
---|
895 | mr_asprintf(tmp, "umount %s", bkpinfo->media_device);
|
---|
896 | run_program_and_log_output(tmp, FALSE);
|
---|
897 | mr_free(tmp);
|
---|
898 | }
|
---|
899 | }
|
---|
900 |
|
---|
901 | if (bkpinfo->call_burn_iso != NULL) {
|
---|
902 | log_msg(2, "bkpinfo->call_burn_iso = %s", bkpinfo->call_burn_iso);
|
---|
903 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
---|
904 | mr_asprintf(message_to_screen, "Burning %s #%d", mds, g_current_media_number);
|
---|
905 | mr_free(mds);
|
---|
906 | pause_and_ask_for_cdr(2, &cd_is_mountable);
|
---|
907 | res = eval_call_to_make_ISO(bkpinfo->call_burn_iso, destfile, g_current_media_number, message_to_screen);
|
---|
908 | if (res) {
|
---|
909 | mr_strcat(message_to_screen, "...failed");
|
---|
910 | } else {
|
---|
911 | mr_strcat(message_to_screen, "...OK");
|
---|
912 | }
|
---|
913 | log_to_screen(message_to_screen);
|
---|
914 | paranoid_free(message_to_screen);
|
---|
915 |
|
---|
916 | retval += res;
|
---|
917 | }
|
---|
918 |
|
---|
919 | if (bkpinfo->call_after_iso != NULL) {
|
---|
920 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
---|
921 | mr_asprintf(message_to_screen, "Running post-ISO call (%s #%d)", mds, g_current_media_number);
|
---|
922 | mr_free(mds);
|
---|
923 | res = eval_call_to_make_ISO(bkpinfo->call_after_iso, destfile, g_current_media_number, message_to_screen);
|
---|
924 | if (res) {
|
---|
925 | mr_strcat(message_to_screen, "...failed");
|
---|
926 | } else {
|
---|
927 | mr_strcat(message_to_screen, "...OK");
|
---|
928 | }
|
---|
929 | log_to_screen(message_to_screen);
|
---|
930 | paranoid_free(message_to_screen);
|
---|
931 |
|
---|
932 | retval += res;
|
---|
933 | }
|
---|
934 |
|
---|
935 | if (chdir(old_pwd)) {
|
---|
936 | // FIXME
|
---|
937 | }
|
---|
938 | mr_free(old_pwd);
|
---|
939 | if (retval) {
|
---|
940 | log_msg(1, "WARNING - make_iso_fs returned an error");
|
---|
941 | }
|
---|
942 | return (retval);
|
---|
943 | }
|
---|
944 |
|
---|
945 |
|
---|
946 | bool is_dev_an_NTFS_dev(char *bigfile_fname)
|
---|
947 | {
|
---|
948 | char *tmp = NULL;
|
---|
949 | char *command = NULL;
|
---|
950 | bool ret = TRUE;
|
---|
951 |
|
---|
952 | mr_asprintf(command, "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1", bigfile_fname);
|
---|
953 | log_msg(1, "command = '%s'", command);
|
---|
954 | tmp = call_program_and_get_last_line_of_output(command);
|
---|
955 | mr_free(command);
|
---|
956 |
|
---|
957 | log_msg(1, "--> tmp = '%s'", tmp);
|
---|
958 | if (strstr(tmp, "NTFS")) {
|
---|
959 | log_it("TRUE");
|
---|
960 | ret = TRUE;
|
---|
961 | } else {
|
---|
962 | log_it("FALSE");
|
---|
963 | ret = FALSE;
|
---|
964 | }
|
---|
965 | mr_free(tmp);
|
---|
966 | return(ret);
|
---|
967 | }
|
---|
968 |
|
---|
969 |
|
---|
970 |
|
---|
971 | /**
|
---|
972 | * Write an ISO image to <tt>[bkpinfo->isodir]/bkpinfo->prefix-[g_current_media_number].iso</tt>.
|
---|
973 | * @param bkpinfo The backup information structure. Fields used:
|
---|
974 | * - @c backup_media_type
|
---|
975 | * - @c prefix
|
---|
976 | * - @c isodir
|
---|
977 | * - @c manual_cd_tray
|
---|
978 | * - @c media_size
|
---|
979 | * - @c netfs_remote_dir
|
---|
980 | * - @c scratchdir
|
---|
981 | * - @c verify_data
|
---|
982 | *
|
---|
983 | * @param last_cd If TRUE, this is the last CD to write; if FALSE, it's not.
|
---|
984 | * @return The number of errors encountered (0 for success)
|
---|
985 | * @see make_iso_fs
|
---|
986 | */
|
---|
987 | int write_iso_and_go_on(bool last_cd)
|
---|
988 | {
|
---|
989 | /*@ pointers **************************************************** */
|
---|
990 | FILE *fout;
|
---|
991 |
|
---|
992 | /*@ buffers ***************************************************** */
|
---|
993 | char *tmp = NULL;
|
---|
994 | char *tmp1 = NULL;
|
---|
995 | char *cdno_fname = NULL;
|
---|
996 | char *lastcd_fname = NULL;
|
---|
997 | char *isofile = NULL;
|
---|
998 | char *mds = NULL;
|
---|
999 |
|
---|
1000 | /*@ bool ******************************************************** */
|
---|
1001 | bool that_one_was_ok;
|
---|
1002 | bool orig_vfy_flag_val;
|
---|
1003 |
|
---|
1004 | /*@ int *********************************************************** */
|
---|
1005 | int res = 0;
|
---|
1006 |
|
---|
1007 | assert(bkpinfo != NULL);
|
---|
1008 | orig_vfy_flag_val = bkpinfo->verify_data;
|
---|
1009 | if (bkpinfo->media_size <= 0) {
|
---|
1010 | fatal_error("write_iso_and_go_on() - unknown media size");
|
---|
1011 | }
|
---|
1012 |
|
---|
1013 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
---|
1014 | log_msg(1, "OK, time to make %s #%d", mds, g_current_media_number);
|
---|
1015 | mr_free(mds);
|
---|
1016 |
|
---|
1017 | /* label the ISO with its number */
|
---|
1018 |
|
---|
1019 | mr_asprintf(cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir);
|
---|
1020 | fout = fopen(cdno_fname, "w");
|
---|
1021 | mr_free(cdno_fname);
|
---|
1022 |
|
---|
1023 | fprintf(fout, "%d", g_current_media_number);
|
---|
1024 | paranoid_fclose(fout);
|
---|
1025 |
|
---|
1026 | mr_asprintf(tmp1, "cp -f %s/autorun %s/", g_mondo_home, bkpinfo->scratchdir);
|
---|
1027 | if (run_program_and_log_output(tmp1, FALSE)) {
|
---|
1028 | log_msg(2, "Warning - unable to copy autorun to scratchdir");
|
---|
1029 | }
|
---|
1030 | mr_free(tmp1);
|
---|
1031 |
|
---|
1032 | /* last CD or not? Label accordingly */
|
---|
1033 | mr_asprintf(lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
|
---|
1034 | if (last_cd) {
|
---|
1035 | unlink(lastcd_fname);
|
---|
1036 | log_msg(2,
|
---|
1037 | "OK, you're telling me this is the last CD. Fair enough.");
|
---|
1038 | } else {
|
---|
1039 | fout = fopen(lastcd_fname, "w");
|
---|
1040 | fprintf(fout,
|
---|
1041 | "You're listening to 90.3 WPLN, Nashville Public Radio.\n");
|
---|
1042 | paranoid_fclose(fout);
|
---|
1043 | }
|
---|
1044 | mr_free(lastcd_fname);
|
---|
1045 |
|
---|
1046 | if (space_occupied_by_cd(bkpinfo->scratchdir) / 1024 > bkpinfo->media_size) {
|
---|
1047 | log_to_screen("Warning! CD is too big. It occupies %ld KB, which is more than the %ld MB allowed.",(long) space_occupied_by_cd(bkpinfo->scratchdir),(long) bkpinfo->media_size);
|
---|
1048 | }
|
---|
1049 |
|
---|
1050 | if (bkpinfo->netfs_remote_dir != NULL) {
|
---|
1051 | // NETFS
|
---|
1052 | mr_asprintf(isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number);
|
---|
1053 | } else {
|
---|
1054 | // ISO
|
---|
1055 | mr_asprintf(isofile, "%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix, g_current_media_number);
|
---|
1056 | }
|
---|
1057 | for (that_one_was_ok = FALSE; !that_one_was_ok;) {
|
---|
1058 | if (bkpinfo->backup_media_type != usb) {
|
---|
1059 | res = make_iso_fs(isofile);
|
---|
1060 | } else {
|
---|
1061 | res = make_usb_fs();
|
---|
1062 | }
|
---|
1063 | if (g_current_media_number == 1 && !res
|
---|
1064 | && (bkpinfo->backup_media_type == optical)) {
|
---|
1065 | if ((tmp = find_optical_device()) == NULL) { // make sure find_optical_device() finds, records CD-R's loc
|
---|
1066 | log_msg(3, "*Sigh* no optical drive found, I hate your computer ;-)");
|
---|
1067 | // if it can't be found then force pausing
|
---|
1068 | bkpinfo->manual_cd_tray = TRUE;
|
---|
1069 | } else {
|
---|
1070 | log_msg(3, "Great. Found an optical drive.");
|
---|
1071 | }
|
---|
1072 | mr_free(tmp);
|
---|
1073 | }
|
---|
1074 | if (bkpinfo->verify_data && !res) {
|
---|
1075 | mds = media_descriptor_string(g_backup_media_type);
|
---|
1076 | log_to_screen("Please reboot from the 1st %s in Compare Mode, as a precaution.", mds);
|
---|
1077 | mr_free(mds);
|
---|
1078 | if (chdir("/")) {
|
---|
1079 | // FIXME
|
---|
1080 | }
|
---|
1081 | log_it("Before calling verification of image()");
|
---|
1082 | if (bkpinfo->backup_media_type == usb) {
|
---|
1083 | res += verify_usb_image();
|
---|
1084 | } else {
|
---|
1085 | res += verify_cd_image();
|
---|
1086 | }
|
---|
1087 | log_it("After calling verification of image()");
|
---|
1088 | }
|
---|
1089 | if (!res) {
|
---|
1090 | that_one_was_ok = TRUE;
|
---|
1091 | } else {
|
---|
1092 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
---|
1093 | mr_asprintf(tmp1, "Failed to create %s #%d. Retry?", mds, g_current_media_number);
|
---|
1094 | mr_free(mds);
|
---|
1095 | res = ask_me_yes_or_no(tmp1);
|
---|
1096 | mr_free(tmp1);
|
---|
1097 |
|
---|
1098 | if (!res) {
|
---|
1099 | if (ask_me_yes_or_no("Abort the backup?")) {
|
---|
1100 | fatal_error("FAILED TO BACKUP");
|
---|
1101 | } else {
|
---|
1102 | break;
|
---|
1103 | }
|
---|
1104 | } else {
|
---|
1105 | log_msg(2, "Retrying, at user's request...");
|
---|
1106 | res = 0;
|
---|
1107 | }
|
---|
1108 | }
|
---|
1109 | }
|
---|
1110 | mr_free(isofile);
|
---|
1111 |
|
---|
1112 | g_current_media_number++;
|
---|
1113 | wipe_archives(bkpinfo->scratchdir);
|
---|
1114 | mr_asprintf(tmp1, "rm -Rf %s/images/*gz %s/images/*data*img", bkpinfo->scratchdir, bkpinfo->scratchdir);
|
---|
1115 | if (system(tmp1)) {
|
---|
1116 | log_msg(2, "Error occurred when I tried to delete the redundant IMGs and GZs");
|
---|
1117 | }
|
---|
1118 | mr_free(tmp1);
|
---|
1119 |
|
---|
1120 | if (last_cd) {
|
---|
1121 | log_msg(2, "This was your last media.");
|
---|
1122 | } else {
|
---|
1123 | log_msg(2, "Continuing to backup your data...");
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 | bkpinfo->verify_data = orig_vfy_flag_val;
|
---|
1127 | return (0);
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 |
|
---|
1131 |
|
---|
1132 |
|
---|
1133 |
|
---|
1134 | /**
|
---|
1135 | * Write the final ISO image.
|
---|
1136 | * @param bkpinfo The backup information structure. Used only
|
---|
1137 | * in the call to @c write_iso_and_go_on().
|
---|
1138 | * @return The number of errors encountered (0 for success)
|
---|
1139 | * @see write_iso_and_go_on
|
---|
1140 | * @see make_iso_fs
|
---|
1141 | * @bug The final ISO is written even if there are no files on it. In practice,
|
---|
1142 | * however, this occurs rarely.
|
---|
1143 | */
|
---|
1144 | int write_final_iso_if_necessary()
|
---|
1145 | {
|
---|
1146 | /*@ int ***************************************************** */
|
---|
1147 | int res;
|
---|
1148 |
|
---|
1149 | /*@ buffers ************************************************** */
|
---|
1150 | char *tmp = NULL;
|
---|
1151 |
|
---|
1152 | assert(bkpinfo != NULL);
|
---|
1153 | // I should really check if there are any slices or tarballs to be copied to CD-R(W)'s; the odds are approx. 1 in a million that there are no files here, so I'll just go ahead & make one more CD anyway
|
---|
1154 |
|
---|
1155 | tmp = mr_center_string("Writing the final ISO", 80);
|
---|
1156 | log_msg(2, tmp);
|
---|
1157 | if (!g_text_mode) {
|
---|
1158 | newtPushHelpLine(tmp);
|
---|
1159 | }
|
---|
1160 | mr_free(tmp);
|
---|
1161 | res = write_iso_and_go_on(TRUE);
|
---|
1162 | if (!g_text_mode) {
|
---|
1163 | newtPopHelpLine();
|
---|
1164 | }
|
---|
1165 | log_msg(2, "Returning from writing final ISO (res=%d)", res);
|
---|
1166 | return (res);
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 |
|
---|
1170 |
|
---|
1171 |
|
---|
1172 | /**
|
---|
1173 | * Finalize the backup.
|
---|
1174 | * For streaming backups, this writes the closing block
|
---|
1175 | * to the stream. For CD-based backups, this creates
|
---|
1176 | * the final ISO image.
|
---|
1177 | * @param bkpinfo The backup information structure, used only
|
---|
1178 | * for the @c backup_media_type.
|
---|
1179 | * @ingroup MLarchiveGroup
|
---|
1180 | */
|
---|
1181 | int do_that_final_phase()
|
---|
1182 | {
|
---|
1183 |
|
---|
1184 | /*@ int ************************************** */
|
---|
1185 | int res = 0;
|
---|
1186 | int retval = 0;
|
---|
1187 |
|
---|
1188 | /*@ buffers ********************************** */
|
---|
1189 |
|
---|
1190 | assert(bkpinfo != NULL);
|
---|
1191 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
1192 | "Writing any remaining data to media ");
|
---|
1193 |
|
---|
1194 | log_msg(1, "Closing tape/CD/USB ... ");
|
---|
1195 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
1196 | /* write tape */
|
---|
1197 | closeout_tape();
|
---|
1198 | } else {
|
---|
1199 | /* write final ISO/USB */
|
---|
1200 | res = write_final_iso_if_necessary();
|
---|
1201 | retval += res;
|
---|
1202 | if (res) {
|
---|
1203 | log_msg(1, "write_final_iso_if_necessary returned an error");
|
---|
1204 | }
|
---|
1205 | }
|
---|
1206 | log_msg(2, "Fork is exiting ... ");
|
---|
1207 |
|
---|
1208 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
1209 |
|
---|
1210 | /* final stuff */
|
---|
1211 | if (retval) {
|
---|
1212 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
1213 | } else {
|
---|
1214 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
1215 | }
|
---|
1216 |
|
---|
1217 | return (retval);
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | /**
|
---|
1221 | * Copy some files to tape.
|
---|
1222 | * This function copies the files specified as parameters into the tape stream.
|
---|
1223 | *
|
---|
1224 | * @param bkpinfo The backup information structure. Used only in the call to
|
---|
1225 | * @c write_file_to_stream_from_file().
|
---|
1226 | *
|
---|
1227 | * @param files_to_add The files to copy to the tape stream.
|
---|
1228 | * @warning The list of @c files_to_add must be terminated with @c NULL.
|
---|
1229 | * @note Files may be split across multiple tapes if necessary.
|
---|
1230 | *
|
---|
1231 | * @return The number of errors encountered (0 for success)
|
---|
1232 | */
|
---|
1233 | int
|
---|
1234 | _move_files_to_stream(char *files_to_add, ...)
|
---|
1235 | {
|
---|
1236 |
|
---|
1237 | /*@ int ************************************************************ */
|
---|
1238 | int retval = 0;
|
---|
1239 | int res = 0;
|
---|
1240 | /*@ buffers ******************************************************** */
|
---|
1241 |
|
---|
1242 | /*@ char *********************************************************** */
|
---|
1243 | char start_chr;
|
---|
1244 | char stop_chr;
|
---|
1245 | char *curr_file = NULL;
|
---|
1246 | char *cf;
|
---|
1247 | /*@ long long ****************************************************** */
|
---|
1248 | off_t length_of_incoming_file = (off_t)0;
|
---|
1249 | va_list ap;
|
---|
1250 |
|
---|
1251 | assert(bkpinfo != NULL);
|
---|
1252 | va_start(ap, files_to_add);
|
---|
1253 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
|
---|
1254 | if (!cf) {
|
---|
1255 | continue;
|
---|
1256 | }
|
---|
1257 | mr_asprintf(curr_file, "%s", cf);
|
---|
1258 | if (!does_file_exist(curr_file)) {
|
---|
1259 | log_msg(1,
|
---|
1260 | "Warning - you're trying to add a non-existent file - '%s' to the tape",
|
---|
1261 | curr_file);
|
---|
1262 | }
|
---|
1263 | /* create header chars */
|
---|
1264 | start_chr = BLK_START_AN_AFIO_OR_SLICE;
|
---|
1265 | stop_chr = BLK_STOP_AN_AFIO_OR_SLICE;
|
---|
1266 | /* ask for new tape if necessary */
|
---|
1267 | length_of_incoming_file = length_of_file(curr_file);
|
---|
1268 | write_header_block_to_stream(length_of_incoming_file, curr_file, start_chr);
|
---|
1269 | res = write_file_to_stream_from_file(curr_file);
|
---|
1270 | retval += res;
|
---|
1271 | unlink(curr_file);
|
---|
1272 | mr_free(curr_file);
|
---|
1273 | /* write closing header */
|
---|
1274 | write_header_block_to_stream((off_t)0, "finished-writing-file", stop_chr);
|
---|
1275 | }
|
---|
1276 | va_end(ap);
|
---|
1277 |
|
---|
1278 | if (retval) {
|
---|
1279 | log_msg(1,
|
---|
1280 | "Warning - errors occurred while I was adding file to tape");
|
---|
1281 | }
|
---|
1282 | return (retval);
|
---|
1283 | }
|
---|
1284 |
|
---|
1285 | /**
|
---|
1286 | * Move some files to the ISO scratch directory.
|
---|
1287 | * This function moves files specified as parameters, into the directory
|
---|
1288 | * @c bkpinfo->scratchdir, where the files that will be stored on the next
|
---|
1289 | * CD are waiting.
|
---|
1290 | *
|
---|
1291 | * @param bkpinfo The backup information structure. Fields used:
|
---|
1292 | * - @c media_size
|
---|
1293 | * - @c scratchdir
|
---|
1294 | * @param files_to_add The files to add to the scratchdir.
|
---|
1295 | * @warning The list of @c files_to_add must be terminated with @c NULL.
|
---|
1296 | * @note If and when the space occupied by the scratchdir would exceed
|
---|
1297 | * the capacity of the current CD,
|
---|
1298 | * <tt>write_iso_and_go_on(bkpinfo, FALSE)</tt> is called and the
|
---|
1299 | * scratchdir is emptied.
|
---|
1300 | *
|
---|
1301 | * @return The number of errors encountered (0 for success)
|
---|
1302 | */
|
---|
1303 | int _move_files_to_cd(char *files_to_add, ...)
|
---|
1304 | {
|
---|
1305 |
|
---|
1306 | /*@ int ************************************************************ */
|
---|
1307 | int retval = 0;
|
---|
1308 | int res = 0;
|
---|
1309 |
|
---|
1310 | /*@ buffers ******************************************************** */
|
---|
1311 | char *tmp = NULL;
|
---|
1312 | char *curr_file = NULL;
|
---|
1313 | char *cf;
|
---|
1314 |
|
---|
1315 | /*@ long ************************************************************ */
|
---|
1316 | va_list ap;
|
---|
1317 | long long would_occupy;
|
---|
1318 |
|
---|
1319 | assert(bkpinfo != NULL);
|
---|
1320 | would_occupy = space_occupied_by_cd(bkpinfo->scratchdir);
|
---|
1321 | va_start(ap, files_to_add); // initialize the variable arguments
|
---|
1322 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
|
---|
1323 | if (!cf) {
|
---|
1324 | continue;
|
---|
1325 | }
|
---|
1326 | mr_asprintf(curr_file, "%s", cf);
|
---|
1327 | if (!does_file_exist(curr_file)) {
|
---|
1328 | log_msg(1, "Warning - you're trying to add a non-existent file - '%s' to the CD", curr_file);
|
---|
1329 | } else {
|
---|
1330 | log_msg(8, "Trying to add file %s to CD", curr_file);
|
---|
1331 | would_occupy += length_of_file(curr_file) / 1024;
|
---|
1332 | }
|
---|
1333 | mr_free(curr_file);
|
---|
1334 | }
|
---|
1335 | va_end(ap);
|
---|
1336 |
|
---|
1337 | if (bkpinfo->media_size <= 0) {
|
---|
1338 | fatal_error("move_files_to_cd() - unknown media size");
|
---|
1339 | }
|
---|
1340 | if (would_occupy / 1024 > bkpinfo->media_size) {
|
---|
1341 | res = write_iso_and_go_on(FALSE); /* FALSE because this is not the last CD we'll write */
|
---|
1342 | retval += res;
|
---|
1343 | if (res) {
|
---|
1344 | log_msg(1, "WARNING - write_iso_and_go_on returned an error");
|
---|
1345 | }
|
---|
1346 | }
|
---|
1347 |
|
---|
1348 | va_start(ap, files_to_add); // initialize the variable arguments
|
---|
1349 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
|
---|
1350 | if (!cf) {
|
---|
1351 | continue;
|
---|
1352 | }
|
---|
1353 | mr_asprintf(curr_file, "%s", cf);
|
---|
1354 |
|
---|
1355 | mr_asprintf(tmp, "mv -f %s %s/archives/", curr_file, bkpinfo->scratchdir);
|
---|
1356 | mr_free(curr_file);
|
---|
1357 | res = run_program_and_log_output(tmp, 5);
|
---|
1358 | retval += res;
|
---|
1359 | if (res) {
|
---|
1360 | log_msg(1, "(move_files_to_cd) '%s' failed", tmp);
|
---|
1361 | } else {
|
---|
1362 | log_msg(8, "Moved %s to CD OK", tmp);
|
---|
1363 | }
|
---|
1364 | mr_free(tmp);
|
---|
1365 | }
|
---|
1366 | va_end(ap);
|
---|
1367 |
|
---|
1368 | if (retval) {
|
---|
1369 | log_msg(1,
|
---|
1370 | "Warning - errors occurred while I was adding files to CD dir");
|
---|
1371 | }
|
---|
1372 | return (retval);
|
---|
1373 | }
|
---|
1374 |
|
---|
1375 |
|
---|
1376 |
|
---|
1377 | /**
|
---|
1378 | * @addtogroup LLarchiveGroup
|
---|
1379 | * @{
|
---|
1380 | */
|
---|
1381 | /**
|
---|
1382 | * Function pointer to an appropriate @c move_files_to_stream routine.
|
---|
1383 | * You can set this to your own function (for example, one to
|
---|
1384 | * transfer files over the network) or leave it as is.
|
---|
1385 | */
|
---|
1386 | int (*move_files_to_stream) (char *, ...) =
|
---|
1387 | _move_files_to_stream;
|
---|
1388 |
|
---|
1389 |
|
---|
1390 | /**
|
---|
1391 | * Function pointer to an appropriate @c move_files_to_cd routine.
|
---|
1392 | * You can set this to your own function (for example, one to
|
---|
1393 | * transfer files over the network) or leave it as is.
|
---|
1394 | */
|
---|
1395 | int (*move_files_to_cd) (char *, ...) =
|
---|
1396 | _move_files_to_cd;
|
---|
1397 |
|
---|
1398 |
|
---|
1399 | /**
|
---|
1400 | * Set the <tt>N</tt>th bit of @c array to @c true_or_false.
|
---|
1401 | * @param array The bit array (as a @c char pointer).
|
---|
1402 | * @param N The bit number to set or reset.
|
---|
1403 | * @param true_or_false If TRUE then set bit @c N, if FALSE then reset bit @c N.
|
---|
1404 | * @see get_bit_N_of_array
|
---|
1405 | */
|
---|
1406 | void set_bit_N_of_array(char *array, int N, bool true_or_false)
|
---|
1407 | {
|
---|
1408 | int bit_number;
|
---|
1409 | int mask, orig_val, to_add;
|
---|
1410 | int element_number;
|
---|
1411 |
|
---|
1412 | assert(array != NULL);
|
---|
1413 |
|
---|
1414 | element_number = N / 8;
|
---|
1415 | bit_number = N % 8;
|
---|
1416 | to_add = (1 << bit_number);
|
---|
1417 | mask = 255 - to_add;
|
---|
1418 | orig_val = array[element_number] & mask;
|
---|
1419 | // log_it("array[%d]=%02x; %02x&%02x = %02x", element_number, array[element_number], mask, orig_val);
|
---|
1420 | if (true_or_false) {
|
---|
1421 | array[element_number] = orig_val | to_add;
|
---|
1422 | }
|
---|
1423 | }
|
---|
1424 |
|
---|
1425 |
|
---|
1426 | /**
|
---|
1427 | * Get the <tt>N</tt>th bit of @c array.
|
---|
1428 | * @param array The bit-array (as a @c char pointer).
|
---|
1429 | * @param N The number of the bit you want.
|
---|
1430 | * @return TRUE (bit is set) or FALSE (bit is not set).
|
---|
1431 | * @see set_bit_N_of_array
|
---|
1432 | * @ingroup utilityGroup
|
---|
1433 | */
|
---|
1434 | bool get_bit_N_of_array(char *array, int N)
|
---|
1435 | {
|
---|
1436 | int element_number;
|
---|
1437 | int bit_number;
|
---|
1438 | int mask;
|
---|
1439 |
|
---|
1440 | element_number = N / 8;
|
---|
1441 | bit_number = N % 8;
|
---|
1442 | mask = 1 << bit_number;
|
---|
1443 | if (array[element_number] & mask) {
|
---|
1444 | return (TRUE);
|
---|
1445 | } else {
|
---|
1446 | return (FALSE);
|
---|
1447 | }
|
---|
1448 | }
|
---|
1449 |
|
---|
1450 |
|
---|
1451 |
|
---|
1452 | /**
|
---|
1453 | * Chop up @c filename.
|
---|
1454 | * @param bkpinfo The backup information structure. Fields used:
|
---|
1455 | * - @c backup_media_type
|
---|
1456 | * - @c compression_level
|
---|
1457 | * - @c optimal_set_size
|
---|
1458 | * - @c tmpdir
|
---|
1459 | * - @c use_lzo
|
---|
1460 | * - @c zip_exe
|
---|
1461 | * - @c zip_suffix
|
---|
1462 | *
|
---|
1463 | * @param biggie_filename The file to chop up.
|
---|
1464 | * @param ntfsprog_fifo The FIFO to ntfsclone if this is an imagedev, NULL otherwise.
|
---|
1465 | * @param biggie_file_number The sequence number of this biggie file (starting from 0).
|
---|
1466 | * @param noof_biggie_files The number of biggie files there are total.
|
---|
1467 | * @return The number of errors encountered (0 for success)
|
---|
1468 | * @see make_slices_and_images
|
---|
1469 | * @ingroup LLarchiveGroup
|
---|
1470 | */
|
---|
1471 | int slice_up_file_etc(char *biggie_filename, char *ntfsprog_fifo, long biggie_file_number, long noof_biggie_files, bool use_ntfsprog) {
|
---|
1472 |
|
---|
1473 | /*@ buffers ************************************************** */
|
---|
1474 | char *tmp = NULL;
|
---|
1475 | char *checksum_line = NULL;
|
---|
1476 | char *command = NULL;
|
---|
1477 | char *tempblock = NULL;
|
---|
1478 | char *curr_slice_fname_uncompressed = NULL;
|
---|
1479 | char *curr_slice_fname_compressed = NULL;
|
---|
1480 | char *file_to_archive = NULL;
|
---|
1481 | char *file_to_openin = NULL;
|
---|
1482 | /*@ pointers ************************************************** */
|
---|
1483 | char *pB = NULL;
|
---|
1484 | FILE *fin = NULL;
|
---|
1485 | FILE *fout = NULL;
|
---|
1486 |
|
---|
1487 | /*@ bool ****************************************************** */
|
---|
1488 | bool finished = FALSE;
|
---|
1489 |
|
---|
1490 | /*@ long ****************************************************** */
|
---|
1491 | size_t blksize = (size_t)0;
|
---|
1492 | long slice_num = 0L;
|
---|
1493 | long i = 0L;
|
---|
1494 | bool should_I_compress_slices = TRUE;
|
---|
1495 | char *suffix = NULL; // for compressed slices
|
---|
1496 |
|
---|
1497 | /*@ long long ************************************************** */
|
---|
1498 | off_t totalread = (off_t)0;
|
---|
1499 | off_t totallength = (off_t)0;
|
---|
1500 |
|
---|
1501 | /*@ int ******************************************************** */
|
---|
1502 | int retval = 0;
|
---|
1503 | int res = 0;
|
---|
1504 |
|
---|
1505 | /*@ structures ************************************************** */
|
---|
1506 | struct s_filename_and_lstat_info biggiestruct;
|
---|
1507 |
|
---|
1508 | assert(bkpinfo != NULL);
|
---|
1509 | assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
|
---|
1510 |
|
---|
1511 | biggiestruct.for_backward_compatibility = '\n';
|
---|
1512 | biggiestruct.use_ntfsprog = use_ntfsprog;
|
---|
1513 | if (is_this_file_compressed(biggie_filename) || bkpinfo->compression_level == 0) {
|
---|
1514 | mr_asprintf(suffix, "%s", "");
|
---|
1515 | should_I_compress_slices = FALSE;
|
---|
1516 | } else {
|
---|
1517 | mr_asprintf(suffix, "%s", bkpinfo->zip_suffix);
|
---|
1518 | should_I_compress_slices = TRUE;
|
---|
1519 | }
|
---|
1520 |
|
---|
1521 | if (bkpinfo->optimal_set_size < 999L) {
|
---|
1522 | fatal_error("bkpinfo->optimal_set_size is insanely small");
|
---|
1523 | }
|
---|
1524 |
|
---|
1525 | if (ntfsprog_fifo) {
|
---|
1526 | file_to_openin = ntfsprog_fifo;
|
---|
1527 | mr_asprintf(checksum_line, "IGNORE");
|
---|
1528 | log_msg(2, "Not calculating checksum for %s: it would take too long", biggie_filename);
|
---|
1529 | if ((tmp = find_home_of_exe("ntfsresize")) == NULL) {
|
---|
1530 | fatal_error("ntfsresize not found");
|
---|
1531 | }
|
---|
1532 | mr_asprintf(command, "%s --force --info %s|grep '^You might resize at '|cut -d' ' -f5", tmp, biggie_filename);
|
---|
1533 | mr_free(tmp);
|
---|
1534 | log_it("command = %s", command);
|
---|
1535 | tmp = call_program_and_get_last_line_of_output(command);
|
---|
1536 | mr_free(command);
|
---|
1537 | log_it("res of it = %s", tmp);
|
---|
1538 | totallength = (off_t)atoll(tmp);
|
---|
1539 | mr_free(tmp);
|
---|
1540 | } else {
|
---|
1541 | file_to_openin = biggie_filename;
|
---|
1542 | if (strchr(biggie_filename,'\'') != NULL) {
|
---|
1543 | mr_asprintf(command, "md5sum \"%s\"", biggie_filename);
|
---|
1544 | } else {
|
---|
1545 | mr_asprintf(command, "md5sum '%s'", biggie_filename);
|
---|
1546 | }
|
---|
1547 | if (!(fin = popen(command, "r"))) {
|
---|
1548 | log_OS_error("Unable to popen-in command");
|
---|
1549 | mr_free(suffix);
|
---|
1550 | return (1);
|
---|
1551 | }
|
---|
1552 | mr_free(command);
|
---|
1553 | mr_getline(checksum_line, fin);
|
---|
1554 | pclose(fin);
|
---|
1555 | totallength = length_of_file(biggie_filename);
|
---|
1556 | }
|
---|
1557 | lstat(biggie_filename, &biggiestruct.properties);
|
---|
1558 | strcpy(biggiestruct.filename, biggie_filename);
|
---|
1559 | pB = strchr(checksum_line, ' ');
|
---|
1560 | if (!pB) {
|
---|
1561 | pB = strchr(checksum_line, '\t');
|
---|
1562 | }
|
---|
1563 | if (pB) {
|
---|
1564 | *pB = '\0';
|
---|
1565 | }
|
---|
1566 | strcpy(biggiestruct.checksum, checksum_line);
|
---|
1567 | mr_free(checksum_line);
|
---|
1568 |
|
---|
1569 | mr_asprintf(tmp, "%s", slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
|
---|
1570 | fout = fopen(tmp, "w");
|
---|
1571 | if (fout == NULL) {
|
---|
1572 | log_msg(1, "Unable to open and write to %s", tmp);
|
---|
1573 | mr_free(tmp);
|
---|
1574 | mr_free(suffix);
|
---|
1575 | return (1);
|
---|
1576 | }
|
---|
1577 | res = fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout);
|
---|
1578 | paranoid_fclose(fout);
|
---|
1579 | mr_free(tmp);
|
---|
1580 |
|
---|
1581 | log_msg(1, "Opening in %s; slicing it and writing to CD/tape", file_to_openin);
|
---|
1582 | if (!(fin = fopen(file_to_openin, "r"))) {
|
---|
1583 | log_OS_error("Unable to openin biggie_filename");
|
---|
1584 | log_to_screen("Cannot archive bigfile '%s': not found", biggie_filename);
|
---|
1585 |
|
---|
1586 | mr_free(suffix);
|
---|
1587 | return (1);
|
---|
1588 | }
|
---|
1589 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
1590 | res = move_files_to_stream(slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""), NULL);
|
---|
1591 | } else {
|
---|
1592 | res = move_files_to_cd(slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""), NULL);
|
---|
1593 | }
|
---|
1594 | i = bkpinfo->optimal_set_size / 256L;
|
---|
1595 | if (!(tempblock = (char *) malloc(256 * 1024))) {
|
---|
1596 | fatal_error("malloc error 256*1024");
|
---|
1597 | }
|
---|
1598 | for (slice_num = 1; !finished; slice_num++) {
|
---|
1599 | mr_asprintf(curr_slice_fname_uncompressed, "%s", slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, ""));
|
---|
1600 | mr_asprintf(curr_slice_fname_compressed, "%s", slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, suffix));
|
---|
1601 |
|
---|
1602 | tmp = percent_media_full_comment();
|
---|
1603 | update_progress_form(tmp);
|
---|
1604 | mr_free(tmp);
|
---|
1605 |
|
---|
1606 | if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) {
|
---|
1607 | log_OS_error(curr_slice_fname_uncompressed);
|
---|
1608 | mr_free(suffix);
|
---|
1609 | return (1);
|
---|
1610 | }
|
---|
1611 | if ((i == bkpinfo->optimal_set_size / 256L) && (totalread < (off_t)1.1 * totallength)) {
|
---|
1612 | for (i = 0L; i < (bkpinfo->optimal_set_size / 256L); i++) {
|
---|
1613 | blksize = fread(tempblock, 1, 256 * 1024, fin);
|
---|
1614 | if (blksize > (size_t)0) {
|
---|
1615 | totalread = totalread + (off_t)blksize;
|
---|
1616 | res = fwrite(tempblock, 1, blksize, fout);
|
---|
1617 | } else {
|
---|
1618 | break;
|
---|
1619 | }
|
---|
1620 | }
|
---|
1621 | } else {
|
---|
1622 | i = 0L;
|
---|
1623 | }
|
---|
1624 | paranoid_fclose(fout);
|
---|
1625 | if (i > 0L) // length_of_file (curr_slice_fname_uncompressed)
|
---|
1626 | {
|
---|
1627 | if (!does_file_exist(curr_slice_fname_uncompressed)) {
|
---|
1628 | log_msg(2, "Warning - '%s' doesn't exist. How can I compress slice?", curr_slice_fname_uncompressed);
|
---|
1629 | }
|
---|
1630 | if (should_I_compress_slices && bkpinfo->compression_level > 0) {
|
---|
1631 | mr_asprintf(command, "%s -%d %s", bkpinfo->zip_exe, bkpinfo->compression_level, curr_slice_fname_uncompressed);
|
---|
1632 | log_msg(2, command);
|
---|
1633 | if ((res = system(command))) {
|
---|
1634 | log_OS_error(command);
|
---|
1635 | }
|
---|
1636 | // did_I_compress_slice = TRUE;
|
---|
1637 | } else {
|
---|
1638 | mr_asprintf(command, "mv %s %s 2>> %s", curr_slice_fname_uncompressed, curr_slice_fname_compressed, MONDO_LOGFILE);
|
---|
1639 | res = 0; // don't do it :)
|
---|
1640 | // did_I_compress_slice = FALSE;
|
---|
1641 | }
|
---|
1642 | mr_free(command);
|
---|
1643 |
|
---|
1644 | retval += res;
|
---|
1645 | if (res) {
|
---|
1646 | log_msg(2, "Failed to compress the slice");
|
---|
1647 | }
|
---|
1648 | if (bkpinfo->use_lzo && strcmp(curr_slice_fname_compressed, curr_slice_fname_uncompressed)) {
|
---|
1649 | unlink(curr_slice_fname_uncompressed);
|
---|
1650 | }
|
---|
1651 | if (res) {
|
---|
1652 | mr_asprintf(tmp, "Problem with slice # %ld", slice_num);
|
---|
1653 | } else {
|
---|
1654 | mr_asprintf(tmp, "%s - Bigfile #%ld, slice #%ld compressed OK ", biggie_filename, biggie_file_number + 1, slice_num);
|
---|
1655 | }
|
---|
1656 | if (!g_text_mode) {
|
---|
1657 | newtDrawRootText(0, g_noof_rows - 2, tmp);
|
---|
1658 | newtRefresh();
|
---|
1659 | } else {
|
---|
1660 | log_msg(2, tmp);
|
---|
1661 | }
|
---|
1662 | mr_free(tmp);
|
---|
1663 |
|
---|
1664 | mr_asprintf(file_to_archive, "%s", curr_slice_fname_compressed);
|
---|
1665 | g_current_progress++;
|
---|
1666 | } else { /* if i==0 then ... */
|
---|
1667 | finished = TRUE;
|
---|
1668 | mr_asprintf(file_to_archive, "%s", curr_slice_fname_uncompressed);
|
---|
1669 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
1670 | break;
|
---|
1671 | }
|
---|
1672 | }
|
---|
1673 | mr_free(curr_slice_fname_uncompressed);
|
---|
1674 | mr_free(curr_slice_fname_compressed);
|
---|
1675 |
|
---|
1676 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
1677 | register_in_tape_catalog(biggieslice, biggie_file_number, slice_num, file_to_archive);
|
---|
1678 | maintain_collection_of_recent_archives(bkpinfo->tmpdir, file_to_archive);
|
---|
1679 | res = move_files_to_stream(file_to_archive, NULL);
|
---|
1680 | } else {
|
---|
1681 | res = move_files_to_cd(file_to_archive, NULL);
|
---|
1682 | }
|
---|
1683 | mr_free(file_to_archive);
|
---|
1684 |
|
---|
1685 | retval += res;
|
---|
1686 | if (res) {
|
---|
1687 | log_to_screen("Failed to add slice %ld of bigfile %ld to scratchdir", slice_num, biggie_file_number + 1);
|
---|
1688 | fatal_error("Hard disk full. You should have bought a bigger one.");
|
---|
1689 | }
|
---|
1690 | }
|
---|
1691 | mr_free(tempblock);
|
---|
1692 | mr_free(suffix);
|
---|
1693 | paranoid_fclose(fin);
|
---|
1694 | mr_asprintf(tmp, "Sliced bigfile #%ld", biggie_file_number + 1);
|
---|
1695 | if (retval) {
|
---|
1696 | mr_strcat(tmp, "...FAILED");
|
---|
1697 | } else {
|
---|
1698 | mr_strcat(tmp, "...OK!");
|
---|
1699 | }
|
---|
1700 | log_msg(1, tmp);
|
---|
1701 | mr_free(tmp);
|
---|
1702 |
|
---|
1703 | return (retval);
|
---|
1704 | }
|
---|
1705 |
|
---|
1706 |
|
---|
1707 |
|
---|
1708 | /**
|
---|
1709 | * Back up big files by chopping them up.
|
---|
1710 | * This function backs up all "big" files (where "big" depends
|
---|
1711 | * on your backup media) in "chunks" (whose size again depends
|
---|
1712 | * on your media).
|
---|
1713 | *
|
---|
1714 | * @param bkpinfo The backup information structure. Fields used:
|
---|
1715 | * - @c backup_media_type
|
---|
1716 | * - @c optimal_set_size
|
---|
1717 | * @param biggielist_fname The path to a file containing a list of
|
---|
1718 | * all "big" files.
|
---|
1719 | * @return The number of errors encountered (0 for success)
|
---|
1720 | * @see slice_up_file_etc
|
---|
1721 | */
|
---|
1722 | int make_slices_and_images(char *biggielist_fname) {
|
---|
1723 |
|
---|
1724 | /*@ pointers ******************************************* */
|
---|
1725 | FILE *fin = NULL;
|
---|
1726 | char *p;
|
---|
1727 | char *q;
|
---|
1728 |
|
---|
1729 | /*@ buffers ******************************************** */
|
---|
1730 | char *tmp = NULL;
|
---|
1731 | char *bigfile_fname = NULL;
|
---|
1732 | char *sz_devfile = NULL;
|
---|
1733 | char *ntfsprog_fifo = NULL;
|
---|
1734 | /*@ long *********************************************** */
|
---|
1735 | long biggie_file_number = 0L;
|
---|
1736 | long noof_biggie_files = 0L;
|
---|
1737 | long estimated_total_noof_slices = 0L;
|
---|
1738 | long size_of_all_biggiefiles = 0L;
|
---|
1739 |
|
---|
1740 | /*@ int ************************************************ */
|
---|
1741 | int retval = 0;
|
---|
1742 | int res = 0;
|
---|
1743 | pid_t pid;
|
---|
1744 | FILE *ftmp = NULL;
|
---|
1745 | bool delete_when_done;
|
---|
1746 | bool use_ntfsprog;
|
---|
1747 | off_t biggie_fsize;
|
---|
1748 |
|
---|
1749 | assert(bkpinfo != NULL);
|
---|
1750 | assert_string_is_neither_NULL_nor_zerolength(biggielist_fname);
|
---|
1751 |
|
---|
1752 | size_of_all_biggiefiles = size_of_all_biggiefiles_K();
|
---|
1753 | estimated_total_noof_slices = size_of_all_biggiefiles / bkpinfo->optimal_set_size + 1L;
|
---|
1754 |
|
---|
1755 | log_msg(1, "size of all biggiefiles = %ld", size_of_all_biggiefiles);
|
---|
1756 | log_msg(1, "estimated_total_noof_slices = %ld KB / %ld KB = %ld", size_of_all_biggiefiles, bkpinfo->optimal_set_size, estimated_total_noof_slices);
|
---|
1757 |
|
---|
1758 | if (length_of_file(biggielist_fname) < 6) {
|
---|
1759 | log_msg(1, "No biggiefiles; fair enough...");
|
---|
1760 | return (0);
|
---|
1761 | }
|
---|
1762 | mr_asprintf(tmp, "I am now backing up all large files.");
|
---|
1763 | log_to_screen(tmp);
|
---|
1764 | noof_biggie_files = count_lines_in_file(biggielist_fname);
|
---|
1765 | log_msg(1, "noof_biggie_files = %ld", noof_biggie_files);
|
---|
1766 | open_progress_form("Backing up big files", tmp, "Please wait. This may take some time.", "", estimated_total_noof_slices);
|
---|
1767 | mr_free(tmp);
|
---|
1768 |
|
---|
1769 | if (!(fin = fopen(biggielist_fname, "r"))) {
|
---|
1770 | log_OS_error("Unable to openin biggielist");
|
---|
1771 | return (1);
|
---|
1772 | }
|
---|
1773 |
|
---|
1774 | malloc_string(bigfile_fname);
|
---|
1775 | for (q = fgets(bigfile_fname, MAX_STR_LEN, fin); !feof(fin) && (q != NULL);
|
---|
1776 | q = fgets(bigfile_fname, MAX_STR_LEN, fin), biggie_file_number++) {
|
---|
1777 | use_ntfsprog = FALSE;
|
---|
1778 | if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) {
|
---|
1779 | bigfile_fname[strlen(bigfile_fname) - 1] = '\0';
|
---|
1780 | }
|
---|
1781 | biggie_fsize = length_of_file(bigfile_fname);
|
---|
1782 | delete_when_done = FALSE;
|
---|
1783 |
|
---|
1784 | if (!does_file_exist(bigfile_fname)) {
|
---|
1785 | ftmp = fopen(bigfile_fname, "w");
|
---|
1786 | if (ftmp == NULL) {
|
---|
1787 | log_msg(3, "Unable to write to %s", bigfile_fname);
|
---|
1788 | // So skip it as it doesn't exist
|
---|
1789 | continue;
|
---|
1790 | } else {
|
---|
1791 | paranoid_fclose(ftmp);
|
---|
1792 | }
|
---|
1793 | delete_when_done = TRUE;
|
---|
1794 | } else {
|
---|
1795 | // Call ntfsclone (formerly partimagehack) if it's a /dev entry
|
---|
1796 | // (i.e. a partition to be imaged)
|
---|
1797 | log_msg(2, "bigfile_fname = %s", bigfile_fname);
|
---|
1798 | use_ntfsprog = FALSE;
|
---|
1799 | if (!strncmp(bigfile_fname, "/dev/", 5) && is_dev_an_NTFS_dev(bigfile_fname)) {
|
---|
1800 | use_ntfsprog = TRUE;
|
---|
1801 | log_msg(2, "Calling ntfsclone in background because %s is an NTFS partition", bigfile_fname);
|
---|
1802 | mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir, (int) (random() % 32768), (int) (random() % 32768));
|
---|
1803 | mkfifo(sz_devfile, 0x770);
|
---|
1804 | ntfsprog_fifo = sz_devfile;
|
---|
1805 | switch (pid = fork()) {
|
---|
1806 | case -1:
|
---|
1807 | mr_free(sz_devfile);
|
---|
1808 | fatal_error("Fork failure");
|
---|
1809 | break;
|
---|
1810 | case 0:
|
---|
1811 | log_msg(2, "CHILD - fip - calling feed_into_ntfsprog(%s, %s)", bigfile_fname, sz_devfile);
|
---|
1812 | res = feed_into_ntfsprog(bigfile_fname, sz_devfile);
|
---|
1813 | /* TODO: Does the child need to unalocate memory as well ?
|
---|
1814 | mr_free(bigfile_fname);
|
---|
1815 | mr_free(sz_devfile);
|
---|
1816 | */
|
---|
1817 | exit(res);
|
---|
1818 | break;
|
---|
1819 | default:
|
---|
1820 | log_msg(2, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
|
---|
1821 | }
|
---|
1822 | }
|
---|
1823 | // Otherwise, use good old 'dd' and 'bzip2'
|
---|
1824 | else {
|
---|
1825 | ntfsprog_fifo = NULL;
|
---|
1826 | }
|
---|
1827 |
|
---|
1828 | // Whether partition or biggiefile, just do your thang :-)
|
---|
1829 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
1830 | write_header_block_to_stream(biggie_fsize, bigfile_fname, use_ntfsprog ? BLK_START_A_PIHBIGGIE : BLK_START_A_NORMBIGGIE);
|
---|
1831 | }
|
---|
1832 | res = slice_up_file_etc(bigfile_fname, ntfsprog_fifo, biggie_file_number, noof_biggie_files, use_ntfsprog);
|
---|
1833 |
|
---|
1834 | /* Free it here as ntfsprog_fifo is not used anymore */
|
---|
1835 | mr_free(sz_devfile);
|
---|
1836 |
|
---|
1837 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
1838 | write_header_block_to_stream((off_t)0, calc_checksum_of_file(bigfile_fname), BLK_STOP_A_BIGGIE);
|
---|
1839 | }
|
---|
1840 | retval += res;
|
---|
1841 | p = strrchr(bigfile_fname, '/');
|
---|
1842 | if (p) {
|
---|
1843 | p++;
|
---|
1844 | } else {
|
---|
1845 | p = bigfile_fname;
|
---|
1846 | }
|
---|
1847 | mr_asprintf(tmp, "Archiving %s ... ", bigfile_fname);
|
---|
1848 | if (res) {
|
---|
1849 | mr_strcat(tmp, "Failed!");
|
---|
1850 | } else {
|
---|
1851 | mr_strcat(tmp, "OK");
|
---|
1852 | }
|
---|
1853 | if (delete_when_done) {
|
---|
1854 | unlink(bigfile_fname);
|
---|
1855 | delete_when_done = FALSE;
|
---|
1856 | }
|
---|
1857 | }
|
---|
1858 | if (!g_text_mode) {
|
---|
1859 | newtDrawRootText(0, g_noof_rows - 2, tmp);
|
---|
1860 | newtRefresh();
|
---|
1861 | }
|
---|
1862 | mr_free(tmp);
|
---|
1863 | }
|
---|
1864 | mr_free(bigfile_fname);
|
---|
1865 |
|
---|
1866 | log_msg(1, "Finished backing up bigfiles");
|
---|
1867 | log_msg(1, "estimated slices = %ld; actual slices = %ld", estimated_total_noof_slices, g_current_progress);
|
---|
1868 | close_progress_form();
|
---|
1869 | paranoid_fclose(fin);
|
---|
1870 | return (retval);
|
---|
1871 | }
|
---|
1872 |
|
---|
1873 |
|
---|
1874 |
|
---|
1875 |
|
---|
1876 | /**
|
---|
1877 | * Wrapper around @c make_slices_and_images().
|
---|
1878 | * @param bkpinfo The backup information structure. Fields used:
|
---|
1879 | * - @c backup_media_type
|
---|
1880 | * - @c scratchdir
|
---|
1881 | * - @c tmpdir
|
---|
1882 | * @return The number of errors encountered (0 for success)
|
---|
1883 | * @ingroup MLarchiveGroup
|
---|
1884 | */
|
---|
1885 | int make_those_slices_phase()
|
---|
1886 | {
|
---|
1887 |
|
---|
1888 | /*@ int ***************************************************** */
|
---|
1889 | int res = 0;
|
---|
1890 | int retval = 0;
|
---|
1891 |
|
---|
1892 | /*@ buffers ************************************************** */
|
---|
1893 | char *biggielist = NULL;
|
---|
1894 | char *command = NULL;
|
---|
1895 | char *blah = NULL;
|
---|
1896 | char *xattr_fname = NULL;
|
---|
1897 | char *acl_fname = NULL;
|
---|
1898 |
|
---|
1899 | assert(bkpinfo != NULL);
|
---|
1900 | /* slice big files */
|
---|
1901 | mvaddstr_and_log_it(g_currentY, 0, "Archiving large files to media ");
|
---|
1902 | mr_asprintf(biggielist, "%s/archives/biggielist.txt", bkpinfo->scratchdir);
|
---|
1903 | if (g_getfattr) {
|
---|
1904 | mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
|
---|
1905 | }
|
---|
1906 | if (g_getfacl) {
|
---|
1907 | mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
|
---|
1908 | }
|
---|
1909 |
|
---|
1910 | mr_asprintf(command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir, biggielist);
|
---|
1911 | paranoid_system(command);
|
---|
1912 | mr_free(command);
|
---|
1913 |
|
---|
1914 | mr_asprintf(blah, "biggielist = %s", biggielist);
|
---|
1915 | log_msg(2, blah);
|
---|
1916 | mr_free(blah);
|
---|
1917 |
|
---|
1918 | if (!does_file_exist(biggielist)) {
|
---|
1919 | log_msg(1, "BTW, the biggielist does not exist");
|
---|
1920 | }
|
---|
1921 |
|
---|
1922 | if (g_getfattr) {
|
---|
1923 | get_fattr_list(biggielist, xattr_fname);
|
---|
1924 | mr_asprintf(command, "cp %s %s/archives/", xattr_fname, bkpinfo->scratchdir);
|
---|
1925 | paranoid_system(command);
|
---|
1926 | mr_free(command);
|
---|
1927 | }
|
---|
1928 | if (g_getfacl) {
|
---|
1929 | get_acl_list(biggielist, acl_fname);
|
---|
1930 | mr_asprintf(command, "cp %s %s/archives/", acl_fname, bkpinfo->scratchdir);
|
---|
1931 | paranoid_system(command);
|
---|
1932 | mr_free(command);
|
---|
1933 | }
|
---|
1934 |
|
---|
1935 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
1936 | res += write_EXAT_files_to_tape(xattr_fname, acl_fname);
|
---|
1937 | mr_asprintf(blah, "%ld", count_lines_in_file(biggielist));
|
---|
1938 | write_header_block_to_stream((off_t)0, blah, BLK_START_BIGGIEFILES);
|
---|
1939 | mr_free(blah);
|
---|
1940 | }
|
---|
1941 | res = make_slices_and_images(biggielist);
|
---|
1942 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
1943 | write_header_block_to_stream((off_t)0, "end-of-biggiefiles", BLK_STOP_BIGGIEFILES);
|
---|
1944 | }
|
---|
1945 | retval += res;
|
---|
1946 | if (res) {
|
---|
1947 | log_msg(1, "make_slices_and_images returned an error");
|
---|
1948 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
1949 | } else {
|
---|
1950 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
1951 | }
|
---|
1952 | mr_free(biggielist);
|
---|
1953 | mr_free(xattr_fname);
|
---|
1954 | mr_free(acl_fname);
|
---|
1955 | return (retval);
|
---|
1956 | }
|
---|
1957 | /* @} - end of LLarchiveGroup */
|
---|
1958 |
|
---|
1959 | /**
|
---|
1960 | * Main function for each @c afio thread.
|
---|
1961 | * @param inbuf A transfer block containing:
|
---|
1962 | * - @c p_last_set_archived: [offset 0] pointer to an @c int
|
---|
1963 | * containing the last set archived.
|
---|
1964 | * - @c p_archival_threads_running: [offset 4] pointer to an @c int
|
---|
1965 | * containing the number of archival threads currently running.
|
---|
1966 | * - @c p_next_set_to_archive: [offset 8] pointer to an @c int containing
|
---|
1967 | * the next set that should be archived.
|
---|
1968 | * - @c p_list_of_fileset_flags: [offset 12] @c char pointer pointing to a
|
---|
1969 | * bit array, where each bit corresponds to a filelist (1=needs
|
---|
1970 | * to be archived, 0=archived).
|
---|
1971 | * - @c bkpinfo: [offset BKPINFO_LOC_OFFSET] pointer to backup information
|
---|
1972 | * structure. Fields used:
|
---|
1973 | * - @c tmpdir
|
---|
1974 | * - @c zip_suffix
|
---|
1975 | *
|
---|
1976 | * Any of the above may be modified by the caller at any time.
|
---|
1977 | *
|
---|
1978 | * @bug Assumes @c int pointers are 4 bytes.
|
---|
1979 | * @see archive_this_fileset
|
---|
1980 | * @see make_afioballs_and_images
|
---|
1981 | * @return NULL, always.
|
---|
1982 | * @ingroup LLarchiveGroup
|
---|
1983 | */
|
---|
1984 | void *create_afio_files_in_background(void *inbuf)
|
---|
1985 | {
|
---|
1986 | long int archiving_set_no = 0L;
|
---|
1987 | char *archiving_filelist_fname = NULL;
|
---|
1988 | char *archiving_afioball_fname = NULL;
|
---|
1989 | char *curr_xattr_list_fname = NULL;
|
---|
1990 | char *curr_acl_list_fname = NULL;
|
---|
1991 |
|
---|
1992 | char *tmp = NULL;
|
---|
1993 | int res = 0, retval = 0;
|
---|
1994 | int *p_archival_threads_running;
|
---|
1995 | int *p_last_set_archived;
|
---|
1996 | int *p_next_set_to_archive;
|
---|
1997 | char *p_list_of_fileset_flags;
|
---|
1998 | int this_thread_no = g_current_thread_no++;
|
---|
1999 |
|
---|
2000 | p_last_set_archived = (int *) inbuf;
|
---|
2001 | p_archival_threads_running = (int *) (inbuf + 4);
|
---|
2002 | p_next_set_to_archive = (int *) (inbuf + 8);
|
---|
2003 | p_list_of_fileset_flags = (char *) (inbuf + 12);
|
---|
2004 |
|
---|
2005 | mr_asprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, 0L);
|
---|
2006 |
|
---|
2007 | while (does_file_exist(archiving_filelist_fname)) {
|
---|
2008 | if (g_exiting) {
|
---|
2009 | mr_free(archiving_filelist_fname);
|
---|
2010 | fatal_error("Execution run aborted (pthread)");
|
---|
2011 | }
|
---|
2012 | if (archiving_set_no >= MAX_NOOF_SETS_HERE) {
|
---|
2013 | mr_free(archiving_filelist_fname);
|
---|
2014 | fatal_error("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please.");
|
---|
2015 | }
|
---|
2016 | if (!semaphore_p()) {
|
---|
2017 | log_msg(3, "P sem failed (pid=%d)", (int) getpid());
|
---|
2018 | mr_free(archiving_filelist_fname);
|
---|
2019 | fatal_error("Cannot get semaphore P");
|
---|
2020 | }
|
---|
2021 | if (archiving_set_no < *p_next_set_to_archive) {
|
---|
2022 | archiving_set_no = *p_next_set_to_archive;
|
---|
2023 | }
|
---|
2024 | *p_next_set_to_archive = *p_next_set_to_archive + 1;
|
---|
2025 | if (!semaphore_v()) {
|
---|
2026 | mr_free(archiving_filelist_fname);
|
---|
2027 | fatal_error("Cannot get semaphore V");
|
---|
2028 | }
|
---|
2029 |
|
---|
2030 | /* backup this set of files */
|
---|
2031 | mr_asprintf(archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no, bkpinfo->zip_suffix);
|
---|
2032 | mr_free(archiving_filelist_fname);
|
---|
2033 | mr_asprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no);
|
---|
2034 | if (!does_file_exist(archiving_filelist_fname)) {
|
---|
2035 | log_msg(3, "%s[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
|
---|
2036 | mr_free(archiving_afioball_fname);
|
---|
2037 | break;
|
---|
2038 | }
|
---|
2039 |
|
---|
2040 | mr_asprintf(tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->zip_suffix);
|
---|
2041 | if (does_file_exist(tmp)) {
|
---|
2042 | log_msg(4, "%s[%d:%d] - waiting for storer", FORTY_SPACES, getpid(), this_thread_no);
|
---|
2043 | while (does_file_exist(tmp)) {
|
---|
2044 | sleep(1);
|
---|
2045 | }
|
---|
2046 | log_msg(4, "[%d] - continuing", getpid());
|
---|
2047 | }
|
---|
2048 | mr_free(tmp);
|
---|
2049 |
|
---|
2050 | log_msg(4, "%s[%d:%d] - EXATing %d...", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
|
---|
2051 |
|
---|
2052 | if (g_getfattr) {
|
---|
2053 | mr_asprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no);
|
---|
2054 | get_fattr_list(archiving_filelist_fname, curr_xattr_list_fname);
|
---|
2055 | mr_free(curr_xattr_list_fname);
|
---|
2056 | }
|
---|
2057 | if (g_getfacl) {
|
---|
2058 | mr_asprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no);
|
---|
2059 | get_acl_list(archiving_filelist_fname, curr_acl_list_fname);
|
---|
2060 | mr_free(curr_acl_list_fname);
|
---|
2061 | }
|
---|
2062 |
|
---|
2063 | log_msg(4, "%s[%d:%d] - archiving %d...", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
|
---|
2064 | res = archive_this_fileset(archiving_filelist_fname, archiving_afioball_fname, archiving_set_no);
|
---|
2065 | mr_free(archiving_afioball_fname);
|
---|
2066 |
|
---|
2067 | retval += res;
|
---|
2068 |
|
---|
2069 | if (res) {
|
---|
2070 | log_to_screen("Errors occurred while archiving set %ld. Please review logs.", archiving_set_no);
|
---|
2071 | }
|
---|
2072 |
|
---|
2073 | if (!semaphore_p()) {
|
---|
2074 | mr_free(archiving_filelist_fname);
|
---|
2075 | fatal_error("Cannot get semaphore P");
|
---|
2076 | }
|
---|
2077 |
|
---|
2078 | set_bit_N_of_array(p_list_of_fileset_flags, archiving_set_no, 5);
|
---|
2079 |
|
---|
2080 | if (*p_last_set_archived < archiving_set_no) {
|
---|
2081 | *p_last_set_archived = archiving_set_no;
|
---|
2082 | } // finished archiving this one
|
---|
2083 |
|
---|
2084 | if (!semaphore_v()) {
|
---|
2085 | mr_free(archiving_filelist_fname);
|
---|
2086 | fatal_error("Cannot get semaphore V");
|
---|
2087 | }
|
---|
2088 | log_msg(4, "%s[%d:%d] - archived %d OK", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
|
---|
2089 | archiving_set_no++;
|
---|
2090 |
|
---|
2091 | mr_free(archiving_filelist_fname);
|
---|
2092 | mr_asprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no);
|
---|
2093 | }
|
---|
2094 | mr_free(archiving_filelist_fname);
|
---|
2095 |
|
---|
2096 | if (!semaphore_p()) {
|
---|
2097 | fatal_error("Cannot get semaphore P");
|
---|
2098 | }
|
---|
2099 | (*p_archival_threads_running)--;
|
---|
2100 | if (!semaphore_v()) {
|
---|
2101 | fatal_error("Cannot get semaphore V");
|
---|
2102 | }
|
---|
2103 | log_msg(3, "%s[%d:%d] - exiting", FORTY_SPACES, getpid(), this_thread_no);
|
---|
2104 | pthread_exit(NULL);
|
---|
2105 | }
|
---|
2106 |
|
---|
2107 |
|
---|
2108 | /**
|
---|
2109 | * Start up threads to archive your files.
|
---|
2110 | *
|
---|
2111 | * This function starts @c ARCH_THREADS threads,
|
---|
2112 | * each starting execution in @c create_afio_files_in_background().
|
---|
2113 | * Each thread will archive individual filesets, based on the
|
---|
2114 | * pointers passed to it and continually updated, until all files
|
---|
2115 | * have been backed up. This function coordinates the threads
|
---|
2116 | * and copies their output to the @c scratchdir.
|
---|
2117 | *
|
---|
2118 | * @param bkpinfo The backup information structure. Fields used:
|
---|
2119 | * - @c backup_media_type
|
---|
2120 | * - @c scratchdir
|
---|
2121 | * - @c tmpdir
|
---|
2122 | * - @c zip_suffix
|
---|
2123 | *
|
---|
2124 | * @return The number of errors encountered (0 for success)
|
---|
2125 | */
|
---|
2126 | int make_afioballs_and_images()
|
---|
2127 | {
|
---|
2128 |
|
---|
2129 | /*@ int ************************************************** */
|
---|
2130 | int retval = 0;
|
---|
2131 | long int storing_set_no = 0;
|
---|
2132 | int res = 0;
|
---|
2133 | bool done_storing = FALSE;
|
---|
2134 | char *result_str;
|
---|
2135 | char *transfer_block;
|
---|
2136 | void *vp;
|
---|
2137 | void **pvp;
|
---|
2138 |
|
---|
2139 | /*@ buffers ********************************************** */
|
---|
2140 | char *storing_filelist_fname = NULL;
|
---|
2141 | char *storing_afioball_fname = NULL;
|
---|
2142 | char *tmp = NULL;
|
---|
2143 | char *media_usage_comment = NULL;
|
---|
2144 | pthread_t archival_thread[ARCH_THREADS];
|
---|
2145 | char *p_list_of_fileset_flags;
|
---|
2146 | int *p_archival_threads_running;
|
---|
2147 | int *p_last_set_archived;
|
---|
2148 | int *p_next_set_to_archive;
|
---|
2149 | int noof_threads;
|
---|
2150 | int i;
|
---|
2151 | char *curr_xattr_list_fname = NULL;
|
---|
2152 | char *curr_acl_list_fname = NULL;
|
---|
2153 | int misc_counter_that_is_not_important = 0;
|
---|
2154 |
|
---|
2155 | log_msg(8, "here");
|
---|
2156 | assert(bkpinfo != NULL);
|
---|
2157 | malloc_string(result_str);
|
---|
2158 | transfer_block = malloc(sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
|
---|
2159 | memset((void *) transfer_block, 0, sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
|
---|
2160 | p_last_set_archived = (int *) transfer_block;
|
---|
2161 | p_archival_threads_running = (int *) (transfer_block + 4);
|
---|
2162 | p_next_set_to_archive = (int *) (transfer_block + 8);
|
---|
2163 | p_list_of_fileset_flags = (char *) (transfer_block + 12);
|
---|
2164 | memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET), (void *) bkpinfo, sizeof(struct s_bkpinfo));
|
---|
2165 | pvp = &vp;
|
---|
2166 | vp = (void *) result_str;
|
---|
2167 | *p_archival_threads_running = 0;
|
---|
2168 | *p_last_set_archived = -1;
|
---|
2169 | *p_next_set_to_archive = 0;
|
---|
2170 | log_to_screen("Archiving regular files");
|
---|
2171 | log_msg(5, "Go, Shorty. It's your birthday.");
|
---|
2172 | open_progress_form("Backing up filesystem",
|
---|
2173 | "I am backing up your live filesystem now.",
|
---|
2174 | "Please wait. This may take a couple of hours.",
|
---|
2175 | "Working...",
|
---|
2176 | (long)get_last_filelist_number() + 1L);
|
---|
2177 |
|
---|
2178 | log_msg(5, "We're gonna party like it's your birthday.");
|
---|
2179 |
|
---|
2180 | srand((unsigned int) getpid());
|
---|
2181 | g_sem_key = 1234 + random() % 30000;
|
---|
2182 | if ((g_sem_id = semget((key_t) g_sem_key, 1, IPC_CREAT | S_IREAD | S_IWRITE)) == -1) {
|
---|
2183 | fatal_error("MABAI - unable to semget");
|
---|
2184 | }
|
---|
2185 | if (!set_semvalue()) {
|
---|
2186 | fatal_error("Unable to init semaphore");
|
---|
2187 | } // initialize semaphore
|
---|
2188 | for (noof_threads = 0; noof_threads < ARCH_THREADS; noof_threads++) {
|
---|
2189 | log_msg(8, "Creating thread #%d", noof_threads);
|
---|
2190 | (*p_archival_threads_running)++;
|
---|
2191 | if ((res = pthread_create(&archival_thread[noof_threads], NULL, create_afio_files_in_background, (void *) transfer_block))) {
|
---|
2192 | fatal_error("Unable to create an archival thread");
|
---|
2193 | }
|
---|
2194 | }
|
---|
2195 |
|
---|
2196 | log_msg(8, "About to enter while() loop");
|
---|
2197 | while (!done_storing) {
|
---|
2198 | if (g_exiting) {
|
---|
2199 | fatal_error("Execution run aborted (main loop)");
|
---|
2200 | }
|
---|
2201 | if (*p_archival_threads_running == 0
|
---|
2202 | && *p_last_set_archived == storing_set_no - 1) {
|
---|
2203 | log_msg(2, "No archival threads are running. The last stored set was %d and I'm looking for %d. Take off your make-up; the party's over... :-)", *p_last_set_archived, storing_set_no);
|
---|
2204 | done_storing = TRUE;
|
---|
2205 | } else
|
---|
2206 | if (!get_bit_N_of_array(p_list_of_fileset_flags, storing_set_no)) {
|
---|
2207 | misc_counter_that_is_not_important = (misc_counter_that_is_not_important + 1) % 5;
|
---|
2208 | sleep(1);
|
---|
2209 | } else {
|
---|
2210 | // store set N
|
---|
2211 | mr_asprintf(storing_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no);
|
---|
2212 | mr_asprintf(storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no, bkpinfo->zip_suffix);
|
---|
2213 | if (g_getfattr) {
|
---|
2214 | mr_asprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no);
|
---|
2215 | }
|
---|
2216 | if (g_getfacl) {
|
---|
2217 | mr_asprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no);
|
---|
2218 | }
|
---|
2219 |
|
---|
2220 | log_msg(2, "Storing set %d", storing_set_no);
|
---|
2221 | while (!does_file_exist(storing_filelist_fname) || !does_file_exist(storing_afioball_fname)) {
|
---|
2222 | log_msg(2, "Warning - either %s or %s doesn't exist yet. I'll pause 5 secs.", storing_filelist_fname, storing_afioball_fname);
|
---|
2223 | sleep(5);
|
---|
2224 | }
|
---|
2225 | /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
|
---|
2226 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
2227 | register_in_tape_catalog(fileset, storing_set_no, -1, storing_afioball_fname);
|
---|
2228 | maintain_collection_of_recent_archives(bkpinfo->tmpdir, storing_afioball_fname);
|
---|
2229 | log_it("Writing EXAT files");
|
---|
2230 | res += write_EXAT_files_to_tape(curr_xattr_list_fname, curr_acl_list_fname);
|
---|
2231 | // archives themselves
|
---|
2232 | res += move_files_to_stream(storing_afioball_fname, NULL);
|
---|
2233 | } else {
|
---|
2234 | if (g_getfacl) {
|
---|
2235 | if (g_getfattr) {
|
---|
2236 | res = move_files_to_cd(storing_filelist_fname, curr_xattr_list_fname, curr_acl_list_fname, storing_afioball_fname, NULL);
|
---|
2237 | } else {
|
---|
2238 | res = move_files_to_cd(storing_filelist_fname, curr_acl_list_fname, storing_afioball_fname, NULL);
|
---|
2239 | }
|
---|
2240 | } else {
|
---|
2241 | if (g_getfattr) {
|
---|
2242 | res = move_files_to_cd(storing_filelist_fname, curr_xattr_list_fname, storing_afioball_fname, NULL);
|
---|
2243 | } else {
|
---|
2244 | res = move_files_to_cd(storing_filelist_fname, storing_afioball_fname, NULL);
|
---|
2245 | }
|
---|
2246 | }
|
---|
2247 | }
|
---|
2248 | retval += res;
|
---|
2249 | g_current_progress++;
|
---|
2250 | media_usage_comment = percent_media_full_comment();
|
---|
2251 | update_progress_form(media_usage_comment);
|
---|
2252 | mr_free(media_usage_comment);
|
---|
2253 | if (res) {
|
---|
2254 | log_to_screen("Failed to add archive %ld's files to CD dir\n", storing_set_no);
|
---|
2255 | fatal_error("Is your hard disk full? If not, please send the author the logfile.");
|
---|
2256 | }
|
---|
2257 | storing_set_no++;
|
---|
2258 | // sleep(2);
|
---|
2259 | if (g_getfacl) {
|
---|
2260 | mr_free(curr_acl_list_fname);
|
---|
2261 | }
|
---|
2262 | if (g_getfattr) {
|
---|
2263 | mr_free(curr_xattr_list_fname);
|
---|
2264 | }
|
---|
2265 | mr_free(storing_filelist_fname);
|
---|
2266 | mr_free(storing_afioball_fname);
|
---|
2267 | }
|
---|
2268 | }
|
---|
2269 | close_progress_form();
|
---|
2270 |
|
---|
2271 | mr_asprintf(tmp, "Your regular files have been archived ");
|
---|
2272 | log_msg(2, "Joining background threads to foreground thread");
|
---|
2273 | for (i = 0; i < noof_threads; i++) {
|
---|
2274 | pthread_join(archival_thread[i], pvp);
|
---|
2275 | log_msg(3, "Thread %d of %d: closed OK", i + 1, noof_threads);
|
---|
2276 | }
|
---|
2277 | del_semvalue();
|
---|
2278 | log_msg(2, "Done.");
|
---|
2279 | if (retval) {
|
---|
2280 | mr_strcat(tmp, "(with errors).");
|
---|
2281 | } else {
|
---|
2282 | mr_strcat(tmp, "successfully.");
|
---|
2283 | }
|
---|
2284 | log_to_screen(tmp);
|
---|
2285 | mr_free(tmp);
|
---|
2286 |
|
---|
2287 | paranoid_free(transfer_block);
|
---|
2288 | paranoid_free(result_str);
|
---|
2289 | return (retval);
|
---|
2290 | }
|
---|
2291 |
|
---|
2292 |
|
---|
2293 |
|
---|
2294 | /**
|
---|
2295 | * Single-threaded version of @c make_afioballs_and_images().
|
---|
2296 | * @see make_afioballs_and_images
|
---|
2297 | */
|
---|
2298 | int make_afioballs_and_images_OLD()
|
---|
2299 | {
|
---|
2300 |
|
---|
2301 | /*@ int ************************************************** */
|
---|
2302 | int retval = 0;
|
---|
2303 | long int curr_set_no = 0L;
|
---|
2304 | int res = 0;
|
---|
2305 |
|
---|
2306 | /*@ buffers ********************************************** */
|
---|
2307 | char *curr_filelist_fname = NULL;
|
---|
2308 | char *curr_afioball_fname = NULL;
|
---|
2309 | char *curr_xattr_list_fname = NULL;
|
---|
2310 | char *curr_acl_list_fname = NULL;
|
---|
2311 | char *tmp = NULL;
|
---|
2312 | char *media_usage_comment = NULL;
|
---|
2313 |
|
---|
2314 | log_to_screen("Archiving regular files");
|
---|
2315 |
|
---|
2316 | open_progress_form("Backing up filesystem",
|
---|
2317 | "I am backing up your live filesystem now.",
|
---|
2318 | "Please wait. This may take a couple of hours.",
|
---|
2319 | "Working...",
|
---|
2320 | get_last_filelist_number() + 1);
|
---|
2321 |
|
---|
2322 | for (;;) {
|
---|
2323 | /* backup this set of files */
|
---|
2324 | mr_asprintf(curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, curr_set_no);
|
---|
2325 | if (! does_file_exist(curr_filelist_fname)) {
|
---|
2326 | mr_free(curr_filelist_fname);
|
---|
2327 | break;
|
---|
2328 | }
|
---|
2329 |
|
---|
2330 | mr_asprintf(curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, curr_set_no, bkpinfo->zip_suffix);
|
---|
2331 |
|
---|
2332 | log_msg(1, "EXAT'g set %ld", curr_set_no);
|
---|
2333 | if (g_getfattr) {
|
---|
2334 | mr_asprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, curr_set_no);
|
---|
2335 | get_fattr_list(curr_filelist_fname, curr_xattr_list_fname);
|
---|
2336 | }
|
---|
2337 | if (g_getfacl) {
|
---|
2338 | mr_asprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, curr_set_no);
|
---|
2339 | get_acl_list(curr_filelist_fname, curr_acl_list_fname);
|
---|
2340 | }
|
---|
2341 |
|
---|
2342 | log_msg(1, "Archiving set %ld", curr_set_no);
|
---|
2343 | res = archive_this_fileset(curr_filelist_fname, curr_afioball_fname, curr_set_no);
|
---|
2344 | retval += res;
|
---|
2345 | if (res) {
|
---|
2346 | log_to_screen("Errors occurred while archiving set %ld. Perhaps your live filesystem changed?", curr_set_no);
|
---|
2347 | }
|
---|
2348 |
|
---|
2349 | /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
|
---|
2350 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
2351 | register_in_tape_catalog(fileset, curr_set_no, -1, curr_afioball_fname);
|
---|
2352 | maintain_collection_of_recent_archives(bkpinfo->tmpdir, curr_afioball_fname);
|
---|
2353 | log_it("Writing EXAT files");
|
---|
2354 | res +=
|
---|
2355 | write_EXAT_files_to_tape(curr_xattr_list_fname,
|
---|
2356 | curr_acl_list_fname);
|
---|
2357 | // archives themselves
|
---|
2358 | res = move_files_to_stream(curr_afioball_fname, NULL);
|
---|
2359 | } else {
|
---|
2360 | if (g_getfacl) {
|
---|
2361 | if (g_getfattr) {
|
---|
2362 | res = move_files_to_cd(curr_filelist_fname,
|
---|
2363 | curr_xattr_list_fname,
|
---|
2364 | curr_acl_list_fname,
|
---|
2365 | curr_afioball_fname, NULL);
|
---|
2366 | } else {
|
---|
2367 | res = move_files_to_cd(curr_filelist_fname,
|
---|
2368 | curr_acl_list_fname,
|
---|
2369 | curr_afioball_fname, NULL);
|
---|
2370 | }
|
---|
2371 | } else {
|
---|
2372 | if (g_getfattr) {
|
---|
2373 | res = move_files_to_cd(curr_filelist_fname,
|
---|
2374 | curr_xattr_list_fname,
|
---|
2375 | curr_afioball_fname, NULL);
|
---|
2376 | } else {
|
---|
2377 | res = move_files_to_cd(curr_filelist_fname,
|
---|
2378 | curr_afioball_fname, NULL);
|
---|
2379 | }
|
---|
2380 | }
|
---|
2381 | }
|
---|
2382 | if (g_getfattr) {
|
---|
2383 | mr_free(curr_xattr_list_fname);
|
---|
2384 | }
|
---|
2385 | if (g_getfacl) {
|
---|
2386 | mr_free(curr_acl_list_fname);
|
---|
2387 | }
|
---|
2388 | retval += res;
|
---|
2389 | g_current_progress++;
|
---|
2390 |
|
---|
2391 | media_usage_comment = percent_media_full_comment();
|
---|
2392 | update_progress_form(media_usage_comment);
|
---|
2393 | mr_free(media_usage_comment);
|
---|
2394 |
|
---|
2395 | if (res) {
|
---|
2396 | log_to_screen("Failed to add archive %ld's files to CD dir\n", curr_set_no);
|
---|
2397 | fatal_error("Is your hard disk is full? If not, please send the author the logfile.");
|
---|
2398 | }
|
---|
2399 | mr_free(curr_filelist_fname);
|
---|
2400 | mr_free(curr_afioball_fname);
|
---|
2401 | curr_set_no++;
|
---|
2402 | }
|
---|
2403 | close_progress_form();
|
---|
2404 | mr_asprintf(tmp, "Your regular files have been archived ");
|
---|
2405 | if (retval) {
|
---|
2406 | mr_strcat(tmp, "(with errors).");
|
---|
2407 | } else {
|
---|
2408 | mr_strcat(tmp, "successfully.");
|
---|
2409 | }
|
---|
2410 | log_to_screen(tmp);
|
---|
2411 | mr_free(tmp);
|
---|
2412 | return (retval);
|
---|
2413 | }
|
---|
2414 |
|
---|
2415 |
|
---|
2416 |
|
---|
2417 | /**
|
---|
2418 | * Wrapper around @c make_afioballs_and_images().
|
---|
2419 | * @param bkpinfo the backup information structure. Only the
|
---|
2420 | * @c backup_media_type field is used within this function.
|
---|
2421 | * @return return code of make_afioballs_and_images
|
---|
2422 | * @see make_afioballs_and_images
|
---|
2423 | * @ingroup MLarchiveGroup
|
---|
2424 | */
|
---|
2425 | int make_those_afios_phase()
|
---|
2426 | {
|
---|
2427 | /*@ int ******************************************* */
|
---|
2428 | int res = 0;
|
---|
2429 | int retval = 0;
|
---|
2430 |
|
---|
2431 | assert(bkpinfo != NULL);
|
---|
2432 |
|
---|
2433 | mvaddstr_and_log_it(g_currentY, 0, "Archiving regular files to media ");
|
---|
2434 |
|
---|
2435 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
2436 | write_header_block_to_stream((off_t)0, "start-of-afioballs", BLK_START_AFIOBALLS);
|
---|
2437 | #if __FreeBSD__ == 5
|
---|
2438 | log_msg(1, "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0");
|
---|
2439 | res = make_afioballs_and_images_OLD();
|
---|
2440 | #else
|
---|
2441 | res = make_afioballs_and_images_OLD();
|
---|
2442 | #endif
|
---|
2443 | write_header_block_to_stream((off_t)0, "stop-afioballs", BLK_STOP_AFIOBALLS);
|
---|
2444 | } else {
|
---|
2445 | res = make_afioballs_and_images();
|
---|
2446 | }
|
---|
2447 |
|
---|
2448 | retval += res;
|
---|
2449 | if (res) {
|
---|
2450 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
2451 | log_msg(1, "make_afioballs_and_images returned an error");
|
---|
2452 | } else {
|
---|
2453 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
2454 | }
|
---|
2455 | return (retval);
|
---|
2456 | }
|
---|
2457 |
|
---|
2458 |
|
---|
2459 | /**
|
---|
2460 | * Initialize the backup.
|
---|
2461 | * Does the following:
|
---|
2462 | * - Sets up the serial number.
|
---|
2463 | * - For streaming backups, opens the tape stream and writes the data disks
|
---|
2464 | * and backup headers.
|
---|
2465 | * - For CD-based backups, wipes the ISOs in the target directory.
|
---|
2466 | *
|
---|
2467 | * @param bkpinfo The backup information structure. Fields used:
|
---|
2468 | * - @c backup_media_type
|
---|
2469 | * - @c prefix
|
---|
2470 | * - @c isodir
|
---|
2471 | * - @c media_device
|
---|
2472 | * - @c scratchdir
|
---|
2473 | * - @c tmpdir
|
---|
2474 | * - @c serial_string
|
---|
2475 | * @return The number of errors encountered (0 for success).
|
---|
2476 | * @ingroup MLarchiveGroup
|
---|
2477 | */
|
---|
2478 | int do_that_initial_phase() {
|
---|
2479 | /*@ int *************************************** */
|
---|
2480 | int retval = 0;
|
---|
2481 |
|
---|
2482 | /*@ buffers *********************************** */
|
---|
2483 | char *command = NULL;
|
---|
2484 | char *tmp = NULL;
|
---|
2485 | char *tmpfile = NULL;
|
---|
2486 | char *data_disks_file = NULL;
|
---|
2487 |
|
---|
2488 | assert(bkpinfo != NULL);
|
---|
2489 | mr_asprintf(data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir);
|
---|
2490 |
|
---|
2491 | tmp = call_program_and_get_last_line_of_output("dd if=/dev/urandom bs=16 count=1 2> /dev/null | hexdump | tr -s ' ' '0' | head -n1");
|
---|
2492 | bkpinfo->serial_string = mr_strip_spaces(tmp);
|
---|
2493 | mr_free(tmp);
|
---|
2494 | mr_strcat(bkpinfo->serial_string, "...word.");
|
---|
2495 | log_msg(2, "bkpinfo->serial_string = '%s'", bkpinfo->serial_string);
|
---|
2496 |
|
---|
2497 | mr_asprintf(tmpfile, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);
|
---|
2498 | if (write_one_liner_data_file(tmpfile, bkpinfo->serial_string)) {
|
---|
2499 | log_msg(1, "%ld: Failed to write serial string", __LINE__);
|
---|
2500 | }
|
---|
2501 | mr_free(tmpfile);
|
---|
2502 |
|
---|
2503 | mvaddstr_and_log_it(g_currentY, 0, "Preparing to archive your data");
|
---|
2504 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
2505 | openout_tape(); /* sets g_tape_stream */
|
---|
2506 | if (!g_tape_stream) {
|
---|
2507 | fatal_error("Cannot open backup (streaming) device");
|
---|
2508 | }
|
---|
2509 | log_msg(1, "Backup (stream) opened OK");
|
---|
2510 | write_data_disks_to_stream(data_disks_file);
|
---|
2511 | } else {
|
---|
2512 | if (bkpinfo->backup_media_type == usb) {
|
---|
2513 | log_msg(1, "Backing up to USB's");
|
---|
2514 | } else {
|
---|
2515 | log_msg(1, "Backing up to optical drive's");
|
---|
2516 | }
|
---|
2517 | }
|
---|
2518 | mr_free(data_disks_file);
|
---|
2519 |
|
---|
2520 | if (bkpinfo->netfs_remote_dir != NULL) {
|
---|
2521 | mr_asprintf(command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix);
|
---|
2522 | } else {
|
---|
2523 | mr_asprintf(command, "rm -f %s/%s-[1-9]*.iso", bkpinfo->isodir, bkpinfo->prefix);
|
---|
2524 | }
|
---|
2525 | paranoid_system(command);
|
---|
2526 | mr_free(command);
|
---|
2527 |
|
---|
2528 | wipe_archives(bkpinfo->scratchdir);
|
---|
2529 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
2530 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
2531 | write_header_block_to_stream((off_t)0, "start-of-tape", BLK_START_OF_TAPE);
|
---|
2532 | write_header_block_to_stream((off_t)0, "start-of-backup", BLK_START_OF_BACKUP);
|
---|
2533 | }
|
---|
2534 | return (retval);
|
---|
2535 | }
|
---|
2536 |
|
---|
2537 |
|
---|
2538 |
|
---|
2539 | /**
|
---|
2540 | * Call Mindi to generate boot and data disks.
|
---|
2541 | * @note This binds correctly to the new Perl version of mindi.
|
---|
2542 | * @param bkpinfo The backup information structure. Fields used:
|
---|
2543 | * - @c backup_media_type
|
---|
2544 | * - @c boot_loader
|
---|
2545 | * - @c boot_device
|
---|
2546 | * - @c compression_level
|
---|
2547 | * - @c differential
|
---|
2548 | * - @c image_devs
|
---|
2549 | * - @c kernel_path
|
---|
2550 | * - @c make_cd_use_lilo
|
---|
2551 | * - @c media_device
|
---|
2552 | * - @c media_size
|
---|
2553 | * - @c scratchdir
|
---|
2554 | * - @c tmpdir
|
---|
2555 | * - @c use_lzo
|
---|
2556 | *
|
---|
2557 | * @return The number of errors encountered (0 for success)
|
---|
2558 | * @bug The code to automagically determine the boot drive
|
---|
2559 | * is messy and system-dependent. In particular, it breaks
|
---|
2560 | * for Linux RAID and LVM users.
|
---|
2561 | * @ingroup MLarchiveGroup
|
---|
2562 | */
|
---|
2563 | int call_mindi_to_supply_boot_disks()
|
---|
2564 | {
|
---|
2565 | /*@ buffer ************************************************************ */
|
---|
2566 | char *tmp = NULL;
|
---|
2567 | char *tmp1 = NULL;
|
---|
2568 | char *tmp2 = NULL;
|
---|
2569 | char *command = NULL;
|
---|
2570 | char *use_lzo_sz = NULL;
|
---|
2571 | char *use_gzip_sz = NULL;
|
---|
2572 | char *use_lzma_sz = NULL;
|
---|
2573 | char *use_comp_sz = NULL;
|
---|
2574 | char *use_star_sz = NULL;
|
---|
2575 | char *bootldr_str = NULL;
|
---|
2576 | char *bootldr_ver = NULL;
|
---|
2577 | char *boot_type = NULL;
|
---|
2578 | char *tape_device = NULL;
|
---|
2579 | char *last_filelist_number = NULL;
|
---|
2580 | char *broken_bios_sz = NULL;
|
---|
2581 | char *cd_recovery_sz = NULL;
|
---|
2582 | char *tape_size_sz = NULL;
|
---|
2583 | char *use_lilo_sz = NULL;
|
---|
2584 | char *value = NULL;
|
---|
2585 | char *bootdev = NULL;
|
---|
2586 | char *ntapedev = NULL;
|
---|
2587 |
|
---|
2588 |
|
---|
2589 |
|
---|
2590 | /*@ char ************************************************************** */
|
---|
2591 | char ch = '\0';
|
---|
2592 |
|
---|
2593 | /*@ long ********************************************************** */
|
---|
2594 | long lines_in_filelist = 0L;
|
---|
2595 |
|
---|
2596 | /*@ int ************************************************************* */
|
---|
2597 | int res = 0;
|
---|
2598 | long estimated_total_noof_slices = 0L;
|
---|
2599 |
|
---|
2600 | assert(bkpinfo != NULL);
|
---|
2601 |
|
---|
2602 | mvaddstr_and_log_it(g_currentY, 0, "Calling MINDI to create boot+data disks");
|
---|
2603 | open_evalcall_form("Calling MINDI to create boot+data disks");
|
---|
2604 | mr_asprintf(tmp, "%s/filelist.full", bkpinfo->tmpdir);
|
---|
2605 | if (!does_file_exist(tmp)) {
|
---|
2606 | mr_free(tmp);
|
---|
2607 | mr_asprintf(tmp, "%s/tmpfs/filelist.full", bkpinfo->tmpdir);
|
---|
2608 | if (!does_file_exist(tmp)) {
|
---|
2609 | mr_free(tmp);
|
---|
2610 | fatal_error ("Cannot find filelist.full, so I cannot count its lines");
|
---|
2611 | }
|
---|
2612 | }
|
---|
2613 | lines_in_filelist = count_lines_in_file(tmp);
|
---|
2614 | mr_free(tmp);
|
---|
2615 |
|
---|
2616 | mr_asprintf(tmp, "%s/LAST-FILELIST-NUMBER", bkpinfo->tmpdir);
|
---|
2617 | mr_asprintf(last_filelist_number, "%s", last_line_of_file(tmp));
|
---|
2618 | mr_free(tmp);
|
---|
2619 |
|
---|
2620 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
2621 | mr_asprintf(tape_size_sz, "%ld", bkpinfo->media_size);
|
---|
2622 | ntapedev = get_non_rewind_dev(bkpinfo->media_device);
|
---|
2623 | if ((bkpinfo->use_obdr) && (ntapedev != NULL)) {
|
---|
2624 | mr_asprintf(bkpinfo->media_device, "%s", ntapedev);
|
---|
2625 | } else {
|
---|
2626 | if (ntapedev == NULL) {
|
---|
2627 | log_it("Not able to create OBDR - Restore will have to be done manually");
|
---|
2628 | }
|
---|
2629 | }
|
---|
2630 | mr_free(ntapedev);
|
---|
2631 | mr_asprintf(tape_device, "%s", bkpinfo->media_device);
|
---|
2632 | } else {
|
---|
2633 | mr_asprintf(tape_size_sz, "%ld", 0L);;
|
---|
2634 | mr_asprintf(tape_device, "");
|
---|
2635 | }
|
---|
2636 | if (bkpinfo->use_lzo) {
|
---|
2637 | mr_asprintf(use_lzo_sz, "yes");
|
---|
2638 | } else {
|
---|
2639 | mr_asprintf(use_lzo_sz, "no");
|
---|
2640 | }
|
---|
2641 | if (bkpinfo->use_gzip) {
|
---|
2642 | mr_asprintf(use_gzip_sz, "yes");
|
---|
2643 | } else {
|
---|
2644 | mr_asprintf(use_gzip_sz, "no");
|
---|
2645 | }
|
---|
2646 | if (bkpinfo->use_lzma) {
|
---|
2647 | mr_asprintf(use_lzma_sz, "yes");
|
---|
2648 | } else {
|
---|
2649 | mr_asprintf(use_lzma_sz, "no");
|
---|
2650 | }
|
---|
2651 | if (bkpinfo->use_star) {
|
---|
2652 | mr_asprintf(use_star_sz, "yes");
|
---|
2653 | } else {
|
---|
2654 | mr_asprintf(use_star_sz, "no");
|
---|
2655 | }
|
---|
2656 |
|
---|
2657 | if (bkpinfo->compression_level > 0) {
|
---|
2658 | mr_asprintf(use_comp_sz, "yes");
|
---|
2659 | } else {
|
---|
2660 | mr_asprintf(use_comp_sz, "no");
|
---|
2661 | }
|
---|
2662 |
|
---|
2663 | mr_asprintf(broken_bios_sz, "yes"); /* assume so */
|
---|
2664 | if (g_cd_recovery) {
|
---|
2665 | mr_asprintf(cd_recovery_sz, "yes");
|
---|
2666 | } else {
|
---|
2667 | mr_asprintf(cd_recovery_sz, "no");
|
---|
2668 | }
|
---|
2669 | if (bkpinfo->make_cd_use_lilo) {
|
---|
2670 | mr_asprintf(use_lilo_sz, "yes");
|
---|
2671 | } else {
|
---|
2672 | mr_asprintf(use_lilo_sz, "no");
|
---|
2673 | }
|
---|
2674 | if (bkpinfo->boot_type == UEFI) {
|
---|
2675 | mr_asprintf(boot_type, "UEFI");
|
---|
2676 | } else if (bkpinfo->boot_type == EFI) {
|
---|
2677 | mr_asprintf(boot_type, "EFI");
|
---|
2678 | } else if (bkpinfo->boot_type == BIOS) {
|
---|
2679 | mr_asprintf(boot_type, "BIOS");
|
---|
2680 | } else {
|
---|
2681 | mr_asprintf(boot_type, "UNKNOWN");
|
---|
2682 | }
|
---|
2683 |
|
---|
2684 | update_evalcall_form(2);
|
---|
2685 | if ((bkpinfo->boot_loader == '\0') || (bkpinfo->boot_device == NULL)) {
|
---|
2686 |
|
---|
2687 | #ifdef __FreeBSD__
|
---|
2688 | bootdev = call_program_and_get_last_line_of_output("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'");
|
---|
2689 | if (!bootdev[0]) {
|
---|
2690 | mr_free(bootdev);
|
---|
2691 | bootdev = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'");
|
---|
2692 | }
|
---|
2693 | #else
|
---|
2694 | /* Linux */
|
---|
2695 | bootdev = call_program_and_get_last_line_of_output("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'");
|
---|
2696 | if (strstr(bootdev, "/dev/cciss/")) {
|
---|
2697 | mr_free(bootdev);
|
---|
2698 | bootdev = call_program_and_get_last_line_of_output("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1");
|
---|
2699 | }
|
---|
2700 | if (!bootdev[0]) {
|
---|
2701 | mr_free(bootdev);
|
---|
2702 | bootdev = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'");
|
---|
2703 | if (strstr(bootdev, "/dev/cciss/")) {
|
---|
2704 | mr_free(bootdev);
|
---|
2705 | bootdev = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | cut -dp -f1");
|
---|
2706 | }
|
---|
2707 | }
|
---|
2708 | /* Linux */
|
---|
2709 | #endif
|
---|
2710 | if (bootdev[0])
|
---|
2711 | ch = which_boot_loader(bootdev);
|
---|
2712 | else
|
---|
2713 | ch = 'U';
|
---|
2714 | if (bkpinfo->boot_loader != '\0') {
|
---|
2715 | log_msg(2, "User specified boot loader. It is '%c'.", bkpinfo->boot_loader);
|
---|
2716 | } else {
|
---|
2717 | bkpinfo->boot_loader = ch;
|
---|
2718 | }
|
---|
2719 | if (bkpinfo->boot_device != NULL) {
|
---|
2720 | log_msg(2, "User specified boot device. It is '%s'.", bkpinfo->boot_device);
|
---|
2721 | } else {
|
---|
2722 | mr_asprintf(bkpinfo->boot_device, "%s", bootdev);
|
---|
2723 | }
|
---|
2724 | }
|
---|
2725 | mr_free(bootdev);
|
---|
2726 |
|
---|
2727 | if (
|
---|
2728 | #ifdef __FreeBSD__
|
---|
2729 | bkpinfo->boot_loader != 'B' && bkpinfo->boot_loader != 'D' &&
|
---|
2730 | #endif
|
---|
2731 | bkpinfo->boot_loader != 'L' && bkpinfo->boot_loader != 'G' && bkpinfo->boot_loader != 'R') {
|
---|
2732 | fatal_error("Please specify your boot loader and device, e.g. -l GRUB -f /dev/hda. Type 'man mondoarchive' to read the manual.");
|
---|
2733 | }
|
---|
2734 | if (bkpinfo->boot_loader == 'L') {
|
---|
2735 | mr_asprintf(bootldr_str, "LILO");
|
---|
2736 | if (!does_file_exist("/etc/lilo.conf")) {
|
---|
2737 | mr_free(bootldr_str);
|
---|
2738 | fatal_error("The de facto standard location for your boot loader's config file is /etc/lilo.conf but I cannot find it there. What is wrong with your Linux distribution?");
|
---|
2739 | }
|
---|
2740 | } else if (bkpinfo->boot_loader == 'G') {
|
---|
2741 | mr_asprintf(bootldr_str, "GRUB");
|
---|
2742 | if (!does_file_exist("/boot/grub/menu.lst") && does_file_exist("/boot/grub/grub.conf")) {
|
---|
2743 | run_program_and_log_output("ln -sf /boot/grub/grub.conf /boot/grub/menu.lst", 5);
|
---|
2744 | }
|
---|
2745 | if ((!does_file_exist("/boot/grub/menu.lst")) && (!does_file_exist("/boot/grub/grub.cfg")) && (!does_file_exist("/boot/grub2/grub.cfg"))) {
|
---|
2746 | /* if UEFI then search under /boot/efi */
|
---|
2747 | tmp = call_program_and_get_last_line_of_output("find /boot/efi -name grub.c*");
|
---|
2748 | if (strstr(tmp, "grub.c") == NULL) {
|
---|
2749 | mr_free(bootldr_str);
|
---|
2750 | fatal_error("The de facto standard location for your boot loader's config file is /boot/grub/menu.lst, /boot/grub/grub.cfg, or /boot/grub2/grub.cfg /boot/efi/.../grub.cfg but I cannot find it there. What is wrong with your Linux distribution?");
|
---|
2751 | }
|
---|
2752 | mr_free(tmp);
|
---|
2753 | }
|
---|
2754 | bootldr_ver = call_program_and_get_last_line_of_output("grub --version 2> /dev/null");
|
---|
2755 | if (strcmp(bootldr_ver,"") == 0) {
|
---|
2756 | mr_free(bootldr_ver);
|
---|
2757 | bootldr_ver = call_program_and_get_last_line_of_output("grub2-install --version");
|
---|
2758 | }
|
---|
2759 | } else if (bkpinfo->boot_loader == 'R') {
|
---|
2760 | mr_asprintf(bootldr_str, "RAW");
|
---|
2761 | }
|
---|
2762 | #ifdef __FreeBSD__
|
---|
2763 | else if (bkpinfo->boot_loader == 'D') {
|
---|
2764 | mr_asprintf(bootldr_str, "DD");
|
---|
2765 | }
|
---|
2766 |
|
---|
2767 | else if (bkpinfo->boot_loader == 'B') {
|
---|
2768 | mr_asprintf(bootldr_str, "BOOT0");
|
---|
2769 | }
|
---|
2770 | #endif
|
---|
2771 | else {
|
---|
2772 | mr_asprintf(bootldr_str, "unknown");
|
---|
2773 | }
|
---|
2774 | log_to_screen("Your boot loader is %s and it boots from %s", bootldr_str, bkpinfo->boot_device);
|
---|
2775 |
|
---|
2776 | if (bootldr_ver != NULL) {
|
---|
2777 | log_to_screen("Boot loader version string: %s", bootldr_ver);
|
---|
2778 | }
|
---|
2779 |
|
---|
2780 | mr_asprintf(tmp, "%s/BOOTLOADER.DEVICE", bkpinfo->tmpdir);
|
---|
2781 | if (write_one_liner_data_file(tmp, bkpinfo->boot_device)) {
|
---|
2782 | log_msg(1, "%ld: Unable to write one-liner boot device", __LINE__);
|
---|
2783 | }
|
---|
2784 | mr_free(tmp);
|
---|
2785 |
|
---|
2786 | switch (bkpinfo->backup_media_type) {
|
---|
2787 | case optical:
|
---|
2788 | mr_asprintf(value, "optical");
|
---|
2789 | break;
|
---|
2790 | case tape:
|
---|
2791 | mr_asprintf(value, "tape");
|
---|
2792 | break;
|
---|
2793 | case udev:
|
---|
2794 | mr_asprintf(value, "udev");
|
---|
2795 | break;
|
---|
2796 | case iso:
|
---|
2797 | mr_asprintf(value, "iso");
|
---|
2798 | break;
|
---|
2799 | case netfs:
|
---|
2800 | mr_asprintf(value, "netfs");
|
---|
2801 | break;
|
---|
2802 | case usb:
|
---|
2803 | mr_asprintf(value, "usb");
|
---|
2804 | break;
|
---|
2805 | default:
|
---|
2806 | fatal_error("Unknown backup_media_type");
|
---|
2807 | }
|
---|
2808 |
|
---|
2809 | if ((bkpinfo->backup_media_type == usb) && (bkpinfo->media_device)) {
|
---|
2810 | mr_asprintf(tmp2, "--usb %s", bkpinfo->media_device);
|
---|
2811 | } else {
|
---|
2812 | mr_asprintf(tmp2," ");
|
---|
2813 | }
|
---|
2814 |
|
---|
2815 | mr_asprintf(tmp, "%s/BACKUP-MEDIA-TYPE", bkpinfo->tmpdir);
|
---|
2816 | if (write_one_liner_data_file(tmp, value)) {
|
---|
2817 | res++;
|
---|
2818 | log_msg(1, "%ld: Unable to write one-liner backup-media-type", __LINE__);
|
---|
2819 | }
|
---|
2820 | mr_free(tmp);
|
---|
2821 |
|
---|
2822 | mr_asprintf(tmp, "%s/BOOTLOADER.NAME", bkpinfo->tmpdir);
|
---|
2823 | if (write_one_liner_data_file(tmp, bootldr_str)) {
|
---|
2824 | res++;
|
---|
2825 | log_msg(1, "%ld: Unable to write one-liner bootloader.name", __LINE__);
|
---|
2826 | }
|
---|
2827 | mr_free(bootldr_str);
|
---|
2828 | mr_free(tmp);
|
---|
2829 |
|
---|
2830 | mr_asprintf(tmp, "%s/BOOTLOADER.VER", bkpinfo->tmpdir);
|
---|
2831 | if (write_one_liner_data_file(tmp, bootldr_ver)) {
|
---|
2832 | res++;
|
---|
2833 | log_msg(1, "%ld: Unable to write one-liner bootloader.ver", __LINE__);
|
---|
2834 | }
|
---|
2835 | mr_free(bootldr_ver);
|
---|
2836 | mr_free(tmp);
|
---|
2837 |
|
---|
2838 | mr_asprintf(tmp, "%s/DIFFERENTIAL", bkpinfo->tmpdir);
|
---|
2839 | if (bkpinfo->differential) {
|
---|
2840 | res += write_one_liner_data_file(tmp, "1");
|
---|
2841 | } else {
|
---|
2842 | res += write_one_liner_data_file(tmp, "0");
|
---|
2843 | }
|
---|
2844 | mr_free(tmp);
|
---|
2845 |
|
---|
2846 | if (g_getfattr) {
|
---|
2847 | mr_asprintf(tmp1, "%s/XATTR", bkpinfo->tmpdir);
|
---|
2848 | if (write_one_liner_data_file(tmp1, "TRUE")) {
|
---|
2849 | log_msg(1, "%ld: Unable to write one-liner XATTR", __LINE__);
|
---|
2850 | }
|
---|
2851 | mr_free(tmp1);
|
---|
2852 | }
|
---|
2853 | if (g_getfacl) {
|
---|
2854 | mr_asprintf(tmp1, "%s/ACL", bkpinfo->tmpdir);
|
---|
2855 | if (write_one_liner_data_file(tmp1, "TRUE")) {
|
---|
2856 | log_msg(1, "%ld: Unable to write one-liner ACL", __LINE__);
|
---|
2857 | }
|
---|
2858 | mr_free(tmp1);
|
---|
2859 | }
|
---|
2860 | if (bkpinfo->use_obdr) {
|
---|
2861 | mr_asprintf(tmp1, "%s/OBDR", bkpinfo->tmpdir);
|
---|
2862 | if (write_one_liner_data_file(tmp1, "TRUE")) {
|
---|
2863 | log_msg(1, "%ld: Unable to write one-liner OBDR", __LINE__);
|
---|
2864 | }
|
---|
2865 | mr_free(tmp1);
|
---|
2866 | }
|
---|
2867 |
|
---|
2868 | estimated_total_noof_slices = size_of_all_biggiefiles_K() / bkpinfo->optimal_set_size + 1L;
|
---|
2869 |
|
---|
2870 | /* TODO: add netfs stuff here? */
|
---|
2871 | mr_asprintf(command, "mkdir -p %s/images", bkpinfo->scratchdir);
|
---|
2872 | if (system(command)) {
|
---|
2873 | res++;
|
---|
2874 | log_OS_error("Unable to make images directory");
|
---|
2875 | }
|
---|
2876 | mr_free(command);
|
---|
2877 | log_msg(1, "lines_in_filelist = %ld", lines_in_filelist);
|
---|
2878 | update_evalcall_form(3);
|
---|
2879 |
|
---|
2880 | unlink(MINDI_RUNFILE);
|
---|
2881 | mr_asprintf(command, "mindi %s --custom %s %s/images '%s' '%s' '%s' '%ld' '%s' '%s' '%s' '%s' '%s' '%ld' '%s' '%s' '%s' '%s' '%ld' '%d' '%s' '%s' '%s' '%s' 2>&1 >> %s",
|
---|
2882 | // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
---|
2883 | tmp2, // parameter #1
|
---|
2884 | bkpinfo->tmpdir, // parameter #2
|
---|
2885 | bkpinfo->scratchdir, // parameter #3
|
---|
2886 | bkpinfo->kernel_path, // parameter #4
|
---|
2887 | tape_device, // parameter #5
|
---|
2888 | tape_size_sz, // parameter #6
|
---|
2889 | lines_in_filelist, // parameter #7 (INT)
|
---|
2890 | use_lzo_sz, // parameter #8
|
---|
2891 | cd_recovery_sz, // parameter #9
|
---|
2892 | (bkpinfo->image_devs == NULL) ? "\"\"" : bkpinfo->image_devs,
|
---|
2893 | // parameter #10
|
---|
2894 | broken_bios_sz, // parameter #11
|
---|
2895 | last_filelist_number, // parameter #12 (STRING)
|
---|
2896 | estimated_total_noof_slices,
|
---|
2897 | // parameter #13 (INT)
|
---|
2898 | (bkpinfo->exclude_devs == NULL) ? "\"\"" : bkpinfo->exclude_devs,
|
---|
2899 | // parameter #14
|
---|
2900 | use_comp_sz, // parameter #15
|
---|
2901 | use_lilo_sz, // parameter #16
|
---|
2902 | use_star_sz, // parameter #17
|
---|
2903 | bkpinfo->internal_tape_block_size,
|
---|
2904 | // parameter #18 (LONG)
|
---|
2905 | bkpinfo->differential, // parameter #19 (INT)
|
---|
2906 | use_gzip_sz, // parameter #20 (STRING)
|
---|
2907 | use_lzma_sz, // parameter #21 (STRING)
|
---|
2908 | "no", // parameter #22 (STRING) bootable image ?
|
---|
2909 | boot_type, // parameter #23 (STRING)
|
---|
2910 | MINDI_RUNFILE // redirect to log file (#24)
|
---|
2911 | );
|
---|
2912 |
|
---|
2913 | mr_free(tmp2);
|
---|
2914 | mr_free(tape_device);
|
---|
2915 | mr_free(tape_size_sz);
|
---|
2916 | mr_free(use_lzo_sz);
|
---|
2917 | mr_free(boot_type);
|
---|
2918 | mr_free(cd_recovery_sz);
|
---|
2919 | mr_free(broken_bios_sz);
|
---|
2920 | mr_free(last_filelist_number);
|
---|
2921 | mr_free(use_comp_sz);
|
---|
2922 | mr_free(use_lilo_sz);
|
---|
2923 | mr_free(use_star_sz);
|
---|
2924 | mr_free(use_gzip_sz);
|
---|
2925 | mr_free(use_lzma_sz);
|
---|
2926 | mr_free(value);
|
---|
2927 |
|
---|
2928 | log_msg(2, command);
|
---|
2929 |
|
---|
2930 | // TODO old call :
|
---|
2931 | //res = run_program_and_log_output(command, FALSE);
|
---|
2932 | log_msg(1, "Call to mindi");
|
---|
2933 | log_msg(1, "-------------");
|
---|
2934 | res = run_external_binary_with_percentage_indicator_NEW("Calling MINDI for boot disk",command);
|
---|
2935 | /* May crash now that we changed the call
|
---|
2936 | update_evalcall_form(99);
|
---|
2937 | */
|
---|
2938 | paranoid_free(command);
|
---|
2939 | log_msg(1, "-------------");
|
---|
2940 | log_msg(1, "End of call to mindi");
|
---|
2941 |
|
---|
2942 | if (!res) {
|
---|
2943 | log_to_screen("Boot+data disks were created OK");
|
---|
2944 |
|
---|
2945 | /* For USB we already have everything on the key */
|
---|
2946 | if (bkpinfo->backup_media_type == usb) {
|
---|
2947 | mr_asprintf(command, "rm -rf %s/images", bkpinfo->scratchdir);
|
---|
2948 | run_program_and_log_output(command, FALSE);
|
---|
2949 | mr_free(command);
|
---|
2950 | } else {
|
---|
2951 | mr_asprintf(tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir, bkpinfo->tmpdir);
|
---|
2952 | if (system(tmp)) {
|
---|
2953 | fatal_error("Cannot find all.tar.gz in tmpdir");
|
---|
2954 | }
|
---|
2955 | mr_free(tmp);
|
---|
2956 | }
|
---|
2957 | if (res) {
|
---|
2958 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
2959 | } else {
|
---|
2960 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
2961 | }
|
---|
2962 | } else {
|
---|
2963 | log_to_screen("Mindi failed to create your boot+data disks.");
|
---|
2964 | mr_asprintf(command, "grep 'Fatal error' %s", MINDI_LOGFILE);
|
---|
2965 | tmp = call_program_and_get_last_line_of_output(command);
|
---|
2966 | mr_free(command);
|
---|
2967 |
|
---|
2968 | if (strlen(tmp) > 1) {
|
---|
2969 | popup_and_OK(tmp);
|
---|
2970 | }
|
---|
2971 | mr_free(tmp);
|
---|
2972 | }
|
---|
2973 | close_evalcall_form();
|
---|
2974 | return (res);
|
---|
2975 | }
|
---|
2976 |
|
---|
2977 |
|
---|
2978 |
|
---|
2979 | /**
|
---|
2980 | * Wrapper function for all the backup commands.
|
---|
2981 | * Calls these other functions: @c prepare_filelist(),
|
---|
2982 | * @c call_filelist_chopper(), @c copy_mondo_and_mindi_stuff_to_scratchdir(),
|
---|
2983 | * @c call_mindi_to_supply_boot_disks(), @c do_that_initial_phase(),
|
---|
2984 | * @c make_those_afios_phase(), @c make_those_slices_phase(), and
|
---|
2985 | * @c do_that_final_phase(). If anything fails before @c do_that_initial_phase(),
|
---|
2986 | * @c fatal_error is called with a suitable message.
|
---|
2987 | * @param bkpinfo The backup information structure. Uses most fields.
|
---|
2988 | * @return The number of non-fatal errors encountered (0 for success).
|
---|
2989 | * @ingroup archiveGroup
|
---|
2990 | */
|
---|
2991 | int backup_data()
|
---|
2992 | {
|
---|
2993 | int retval = 0, res = 0;
|
---|
2994 | char *tmp = NULL;
|
---|
2995 |
|
---|
2996 | assert(bkpinfo != NULL);
|
---|
2997 |
|
---|
2998 | if (bkpinfo->backup_media_type == optical) {
|
---|
2999 | if (bkpinfo->wipe_media_first) {
|
---|
3000 | if ((tmp = find_home_of_exe("dvd+rw-format")) == NULL) {
|
---|
3001 | mr_free(tmp);
|
---|
3002 | fatal_error("Cannot find dvd+rw-format. Please install it or fix your PATH.");
|
---|
3003 | }
|
---|
3004 | mr_free(tmp);
|
---|
3005 | }
|
---|
3006 | if ((tmp = find_home_of_exe("growisofs")) == NULL) {
|
---|
3007 | mr_free(tmp);
|
---|
3008 | fatal_error("Cannot find growisofs. Please install it or fix your PATH.");
|
---|
3009 | }
|
---|
3010 | mr_free(tmp);
|
---|
3011 | }
|
---|
3012 |
|
---|
3013 | if ((res = prepare_filelist())) { /* generate scratchdir/filelist.full */
|
---|
3014 | fatal_error("Failed to generate filelist catalog");
|
---|
3015 | }
|
---|
3016 | if (call_filelist_chopper()) {
|
---|
3017 | fatal_error("Failed to run filelist chopper");
|
---|
3018 | }
|
---|
3019 |
|
---|
3020 | mr_asprintf(tmp, "gzip -9 %s/archives/filelist.full", bkpinfo->scratchdir);
|
---|
3021 | if (run_program_and_log_output(tmp, 2)) {
|
---|
3022 | mr_free(tmp);
|
---|
3023 | fatal_error("Failed to gzip filelist.full");
|
---|
3024 | }
|
---|
3025 | mr_free(tmp);
|
---|
3026 |
|
---|
3027 | mr_asprintf(tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir, bkpinfo->tmpdir);
|
---|
3028 | if (run_program_and_log_output(tmp, 2)) {
|
---|
3029 | mr_free(tmp);
|
---|
3030 | fatal_error("Failed to copy to tmpdir");
|
---|
3031 | }
|
---|
3032 | mr_free(tmp);
|
---|
3033 |
|
---|
3034 | copy_mondo_and_mindi_stuff_to_scratchdir(); // payload, too, if it exists
|
---|
3035 | if ((res = call_mindi_to_supply_boot_disks())) {
|
---|
3036 | fatal_error("Failed to generate boot+data disks");
|
---|
3037 | }
|
---|
3038 | retval += do_that_initial_phase(); // prepare
|
---|
3039 | mr_asprintf(tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir);
|
---|
3040 | run_program_and_log_output(tmp, 1);
|
---|
3041 | mr_free(tmp);
|
---|
3042 |
|
---|
3043 | retval += make_those_afios_phase(); // backup regular files
|
---|
3044 | retval += make_those_slices_phase(); // backup BIG files
|
---|
3045 | retval += do_that_final_phase(); // clean up
|
---|
3046 | log_msg(1, "Creation of archives... complete.");
|
---|
3047 | if (bkpinfo->verify_data) {
|
---|
3048 | sleep(2);
|
---|
3049 | }
|
---|
3050 | return (retval);
|
---|
3051 | }
|
---|
3052 |
|
---|
3053 |
|
---|
3054 | /* @} - end of LLarchiveGroup */
|
---|
3055 |
|
---|
3056 | /**
|
---|
3057 | * Verify the user's data.
|
---|
3058 | * @param bkpinfo The backup information structure. Fields used:
|
---|
3059 | * - @c backup_data
|
---|
3060 | * - @c backup_media_type
|
---|
3061 | * - @c media_device
|
---|
3062 | * - @c verify_data
|
---|
3063 | *
|
---|
3064 | * @return The number of errors encountered (0 for success)
|
---|
3065 | * @ingroup verifyGroup
|
---|
3066 | */
|
---|
3067 | int verify_data()
|
---|
3068 | {
|
---|
3069 | int res = 0, retval = 0, cdno = 0;
|
---|
3070 | char *tmp = NULL;
|
---|
3071 | char *mds = NULL;
|
---|
3072 | long diffs = 0;
|
---|
3073 |
|
---|
3074 | assert(bkpinfo != NULL);
|
---|
3075 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
3076 | if (chdir("/")) {
|
---|
3077 | // FIXME
|
---|
3078 | }
|
---|
3079 | mvaddstr_and_log_it(g_currentY, 0, "Verifying archives against live filesystem");
|
---|
3080 | verify_tape_backups();
|
---|
3081 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
3082 | } else if (bkpinfo->backup_data)
|
---|
3083 | // bkpinfo->backup_media_type == cdr))
|
---|
3084 | {
|
---|
3085 | log_msg(2,
|
---|
3086 | "Not verifying again. Per-CD/ISO verification already carried out.");
|
---|
3087 | mr_asprintf(tmp, "cat %s/changed.files > %s/changed.files 2> /dev/null",bkpinfo->tmpdir, MONDO_CACHE);
|
---|
3088 | paranoid_system(tmp);
|
---|
3089 | mr_free(tmp);
|
---|
3090 | } else {
|
---|
3091 | g_current_media_number = cdno;
|
---|
3092 | if (bkpinfo->backup_media_type != iso) {
|
---|
3093 | mr_free(bkpinfo->media_device);
|
---|
3094 | bkpinfo->media_device = find_optical_device();
|
---|
3095 | }
|
---|
3096 | if (chdir("/")) {
|
---|
3097 | // FIXME
|
---|
3098 | }
|
---|
3099 | for (cdno = 1; cdno < 99 && bkpinfo->verify_data; cdno++) {
|
---|
3100 | if (cdno != g_current_media_number) {
|
---|
3101 | log_msg(2,
|
---|
3102 | "Warning - had to change g_current_media_number from %d to %d",
|
---|
3103 | g_current_media_number, cdno);
|
---|
3104 | g_current_media_number = cdno;
|
---|
3105 | }
|
---|
3106 | if (bkpinfo->backup_media_type != iso) {
|
---|
3107 | insist_on_this_cd_number(cdno);
|
---|
3108 | }
|
---|
3109 | res = verify_cd_image(); // sets verify_data to FALSE if it's time to stop verifying
|
---|
3110 | retval += res;
|
---|
3111 | if (res) {
|
---|
3112 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
---|
3113 | log_to_screen("Warnings/errors were reported while checking %s #%d", mds, g_current_media_number);
|
---|
3114 | mr_free(mds);
|
---|
3115 |
|
---|
3116 | }
|
---|
3117 | }
|
---|
3118 | mr_asprintf(tmp, "grep 'afio: ' %s | sed 's/afio: //' | grep -vE '^/dev/.*$' >> %s/changed.files", MONDO_LOGFILE, MONDO_CACHE);
|
---|
3119 | res = system(tmp);
|
---|
3120 | mr_free(tmp);
|
---|
3121 |
|
---|
3122 | mr_asprintf(tmp, "grep 'star: ' %s | sed 's/star: //' | grep -vE '^/dev/.*$' >> %s/changed.files", MONDO_LOGFILE, MONDO_CACHE);
|
---|
3123 | res = system(tmp);
|
---|
3124 | mr_free(tmp);
|
---|
3125 | run_program_and_log_output("umount " MNT_CDROM, FALSE);
|
---|
3126 | // if (bkpinfo->backup_media_type != iso && !bkpinfo->please_dont_eject_when_restoring)
|
---|
3127 | if (!bkpinfo->please_dont_eject) {
|
---|
3128 | eject_device(bkpinfo->media_device);
|
---|
3129 | }
|
---|
3130 | }
|
---|
3131 | mr_asprintf(tmp, "%s/changed.files", MONDO_CACHE);
|
---|
3132 | diffs = count_lines_in_file(tmp);
|
---|
3133 | mr_free(tmp);
|
---|
3134 |
|
---|
3135 | if (diffs > 0) {
|
---|
3136 | if (retval == 0) {
|
---|
3137 | retval = (int) (-diffs);
|
---|
3138 | }
|
---|
3139 | }
|
---|
3140 | return (retval);
|
---|
3141 | }
|
---|
3142 |
|
---|
3143 |
|
---|
3144 | void setenv_mondo_share(void) {
|
---|
3145 |
|
---|
3146 | setenv("MONDO_SHARE", MONDO_SHARE, 1);
|
---|
3147 | }
|
---|