source: MondoRescue/branches/2.2.10/mondo/src/mondorestore/mondo-rstr-compare.c@ 2508

Last change on this file since 2508 was 2508, checked in by Bruno Cornec, 14 years ago

r3287@localhost (orig r2285): bruno | 2009-07-20 11:36:47 +0200

r3285@localhost: bruno | 2009-07-20 11:17:35 +0200
Apply fix in 2.2.10 around multi USB device handling to 2.2.9 as well


r3291@localhost (orig r2288): bruno | 2009-07-21 16:48:31 +0200
Copy 2.2.10 test script in to 2.2.9 for memory problm analysis


r3293@localhost (orig r2290): bruno | 2009-07-22 14:03:44 +0200

  • Fix a printing error in mindi for the tar command
  • Fix all mr_asprintf which had no second param as a string


r3295@localhost (orig r2292): bruno | 2009-07-22 16:55:00 +0200

  • Fix #160 and #346 by rewriting the message.txt file with more valid information gathered in mindi


r3300@localhost (orig r2294): bruno | 2009-07-23 01:58:08 +0200

Man pages patch from Joe Ross (joe.ross_at_gmail.com)


r3303@localhost (orig r2297): bruno | 2009-07-23 17:43:49 +0200
Fix a remaining display error for 2.2.9. That version has been tested OK in a lab.


r3304@localhost (orig r2298): bruno | 2009-07-23 18:18:27 +0200

  • Remove memory leak for the last modification


r3308@localhost (orig r2302): bruno | 2009-07-24 21:18:50 +0200
Improve logging of mountlist.txt


r3310@localhost (orig r2304): bruno | 2009-07-27 19:45:10 +0200

  • popup_and_get_string needs an allocated buffer for the moment so fixing the calls with dyn. ones
  • Fix a bug in mem.c for mr_strcat, which wasn't modifying the right pointer level


r3311@localhost (orig r2305): bruno | 2009-07-27 19:49:35 +0200
Avoid a memory leak in the previous patch


r3314@localhost (orig r2308): bruno | 2009-07-27 20:59:06 +0200
Fix a bug in mr_strcat backported from 2.2.10. Should solve our seg faults.


r3315@localhost (orig r2309): bruno | 2009-07-28 02:14:23 +0200
Cosmetic changes to allow for quality to not giv false positive


r3343@localhost (orig r2311): bruno | 2009-08-18 02:13:43 +0200
Fix for initramfs detection with 2.6.30 (Hugo Vanwoerkom hvw59601_at_care2.com)


r3367@localhost (orig r2333): bruno | 2009-08-18 16:26:26 +0200
Adds a precision for -U option in man page on raw device usage and not partition name


r3373@localhost (orig r2336): bruno | 2009-08-20 17:37:41 +0200

  • Precise the combined usage of -E and -I in mondoarchive (Case 4601017223)


r3379@localhost (orig r2342): bruno | 2009-08-21 16:27:10 +0200


r3383@localhost (orig r2344): bruno | 2009-08-24 13:37:09 +0200

r3382@localhost: bruno | 2009-08-24 13:30:25 +0200
In NFS mode also propose access to expert, interactive, ... entry at boot prompt


r3388@localhost (orig r2346): bruno | 2009-08-27 11:41:16 +0200
Adds fdisk -l result in Log File at restore time


r3389@localhost (orig r2347): bruno | 2009-08-27 13:51:00 +0200

  • Solve tmp dir creation which sometimes was trying to create /%xx dirs. Should fix #293 for good


r3390@localhost (orig r2348): bruno | 2009-08-27 13:54:25 +0200
Improve logging (minor)


r3394@localhost (orig r2350): bruno | 2009-08-28 02:24:19 +0200
Change inerface of evaluate_mountlist and spread_flaws_across_three_lines in order to solve bugs linked to strings management in these functions. May fix a restoration crash seen by some customers


r3397@localhost (orig r2353): bruno | 2009-08-28 19:03:45 +0200

  • Addition of a nomd option to avoid starting mdadm
  • mpath is now already started if there was a mpath entry in mountlist


r3399@localhost (orig r2355): bruno | 2009-08-29 00:56:50 +0200
Remove function spread_flaws_across_three_lines and expand it at the single place where it was useful, and fix memory allocation issues in it.


r3402@localhost (orig r2358): bruno | 2009-09-01 19:02:35 +0200
P2V doc updated (Lester Wade lester.wade_at_hp.com)


r3404@localhost (orig r2360): bruno | 2009-09-01 19:26:53 +0200
Website update to refer to new P2V document


r3405@localhost (orig r2361): bruno | 2009-09-03 13:54:25 +0200

  • Fix a case where the NFS dir in restore mode was mounted rw (linked to bug #291 could create a huge problem)


r3407@localhost (orig r2363): bruno | 2009-09-03 14:46:46 +0200
More verbose at installation of additional tools


r3409@localhost (orig r2365): bruno | 2009-09-03 18:08:32 +0200

  • New update from Lester Wade (lester.wade_at_hp.com) for P2V doc


r3410@localhost (orig r2366): bruno | 2009-09-05 01:28:18 +0200
place the code of mondo_makefilelist before its call



r3411@localhost (orig r2367): bruno | 2009-09-06 01:51:26 +0200

  • Advertising for project-builder on the website added


r3412@localhost (orig r2368): bruno | 2009-09-07 15:36:23 +0200
Fix compilation issue


r3413@localhost (orig r2369): bruno | 2009-09-07 18:03:40 +0200
Another compilation issue fixed.


r3415@localhost (orig r2371): bruno | 2009-09-08 13:40:25 +0200

  • Fix a problem a error detection in evaluate_mountlist which casued nuke mode to abort. Error string should also be better now.


r3417@localhost (orig r2373): bruno | 2009-09-08 13:55:31 +0200
Avoid asking the Prefix name in NFS mode twice


r3418@localhost (orig r2374): bruno | 2009-09-08 20:04:07 +0200

  • Try to fix garbled screen progression in text mode based on 2.2.10 modifications which are working


r3424@localhost (orig r2380): bruno | 2009-09-09 20:30:47 +0200

  • Change NFS support into a NetFS support to allow for multiple protocol in addition to NFS (NEEDS TESTING)
  • Better logging to detect a potential nuke issue


r3425@localhost (orig r2381): bruno | 2009-09-10 02:05:55 +0200
Fix a missing param for sshfs call


r3428@localhost (orig r2384): bruno | 2009-09-10 13:02:56 +0200

  • Remove separate function look_for_duplicate_mountpoints used only once and whose interface created problems with caller


r3430@localhost (orig r2386): bruno | 2009-09-10 16:06:52 +0200
Be compatible on backup type by making old nfs recognized as netfs and proto forced


r3431@localhost (orig r2387): bruno | 2009-09-10 18:40:47 +0200
Fix a problem in netfs analysis in mondoarchive


r3432@localhost (orig r2388): bruno | 2009-09-10 20:25:13 +0200
Fix mondoarchive CLI analysis for NETFS type of requests


r3434@localhost (orig r2390): bruno | 2009-09-11 03:05:20 +0200

  • Adds ext3 initrd support for 2.6.30


r3437@localhost (orig r2393): bruno | 2009-09-11 11:56:52 +0200

  • Tries to add support for bzip2 and lzma initramfs (preliminary, not tested) for 2.6.30


r3438@localhost (orig r2394): bruno | 2009-09-12 02:53:02 +0200
Fix interface of evaluate_mountlist (remove 2nd param useless) and fix nuke mode which wasn't working.


r3441@localhost (orig r2397): bruno | 2009-09-14 18:54:34 +0200
Fix a format issue in text mode on percentage


r3452@localhost (orig r2398): bruno | 2009-09-15 16:00:13 +0200

  • Fix a bug where flaws_str could be NULL and wasn't tested correctly.


r3453@localhost (orig r2399): bruno | 2009-09-15 19:28:39 +0200

  • Use protocol name when displaying restore progress instead of netfs
  • Ask for network protocol name at restore time


r3455@localhost (orig r2401): bruno | 2009-09-15 19:34:19 +0200
Wrong structure member name was used


r3456@localhost (orig r2402): bruno | 2009-09-16 13:04:17 +0200
Use dir for shell related commands and dir1 for C related actions in open_and_list_dir to avoid missing some files with { in names e.g.


r3457@localhost (orig r2403): bruno | 2009-09-16 16:32:03 +0200

  • At restore time read the netfs protocol in the conf file


r3462@localhost (orig r2408): bruno | 2009-09-18 15:17:08 +0200
Remove useless script


r3463@localhost (orig r2409): bruno | 2009-09-18 15:25:35 +0200

  • Split deplist.txt into multiple conf files under deplist.d in the conf dir. This will allow to have a minimal.conf file for initrd content to analyze to improve support of new embedded feature in the future (sshfs, live install). The other conf files contain the additional commands to put in the all.tar.gz. For the moment, mindi is still working the same. THis infra will allow that support in a near future. deplist.txt is now reserved for the admin additional commands.


r3465@localhost (orig r2410): bruno | 2009-09-18 19:10:54 +0200

  • Better list of mandatory tools
  • Adds fuse and sshfs support in initrd


r3466@localhost (orig r2411): bruno | 2009-09-18 20:32:47 +0200
sshfs also needs ssh at restore time in initrd


r3478@localhost (orig r2418): bruno | 2009-09-23 23:22:39 +0200
Modify getfattr call to have all extended attributes, including non user ones. (patch from Kevin Ritzenthaler Kevin.Ritzenthaler_at_hp.com) and fix #357


r3479@localhost (orig r2419): bruno | 2009-09-23 23:50:34 +0200
star only supports ACL when used with exustar mode. Fix #356.


r3482@localhost (orig r2422): bruno | 2009-09-24 16:53:24 +0200

  • Adds support for bnx2x (BL 460 G6) and auth_rpcgss (Debian 2.6.31)


r3485@localhost (orig r2423): bruno | 2009-09-25 16:38:40 +0200
Fix an issue in is_this_device_mounted (string freed before last usage)


r3486@localhost (orig r2424): bruno | 2009-09-25 18:44:01 +0200

  • analyze-my-lvm now removes excluded devices from list coming from mondoarchive
  • new mr_make_devlist_from_pathlist which handle the new bkpinfo->exclude_devs field containing the excluded devices and remove corresponding code from libmondo-cli.c
  • Move DSF code into libmondo-devices.c for coherency, and only the previous function is made externally available
  • Remove dev_to_exclude in libmondo-archive.c which wasn't working correctly and replace it with bkpinfo->exclude_devs


r3487@localhost (orig r2425): bruno | 2009-09-25 18:58:23 +0200

  • Improving ssh support at restore time by providing a shadow file


r3489@localhost (orig r2426): bruno | 2009-09-25 19:42:09 +0200

  • Attempt to stay backward compatible without protocol for -n option


r3490@localhost (orig r2427): bruno | 2009-09-28 02:08:06 +0200
Avoids null param for excludes_devs for mindi call


r3492@localhost (orig r2429): bruno | 2009-09-28 11:46:16 +0200

  • Simplify GetInitrdFilesystemToUse which doesn't need to detect everything, but just know if it's initramfs (new mode) or a compressed FS ext2/3 (older mode) as initrd is anyway re-made by mindi. Should fix #353


r3494@localhost (orig r2431): bruno | 2009-09-28 13:16:18 +0200

  • Use only the AWK veriable everywhere and not the awk command


r3495@localhost (orig r2432): bruno | 2009-09-28 14:16:31 +0200
Warning emited in case of duplicate mountpoints or devices in fstab found


r3496@localhost (orig r2433): bruno | 2009-09-28 15:55:17 +0200
ssh in the restore env needs some dlopened libs (libnss_compat|files)


r3497@localhost (orig r2434): bruno | 2009-09-28 16:33:14 +0200
Compiler warning fixed


r3498@localhost (orig r2435): bruno | 2009-09-28 17:55:26 +0200
Improve user management for NetFS cases


r3499@localhost (orig r2436): bruno | 2009-09-29 01:48:32 +0200

  • Improve deplist.d/* files
  • adds libnss for ssh support in boot disk
  • Solve a memory management issue in DSF module (strtok => mr_strtok)
  • DSF now also supports partitions in addition to full disks
  • Adds debug in open_and_list_dir


r3500@localhost (orig r2437): bruno | 2009-09-29 10:41:56 +0200

  • Fix udev support in init for Mandriva 2009.1 (udevadm settle is blocking)


r3501@localhost (orig r2438): bruno | 2009-09-29 14:41:36 +0200

  • Improvements on sshfs/ssh management in restore mode
  • Include now all minimal requirements for sshfs


r3502@localhost (orig r2439): bruno | 2009-09-29 18:46:08 +0200

  • Avoids error message if some ssh conf files do not exist


r3503@localhost (orig r2440): bruno | 2009-09-29 18:57:13 +0200

  • Avoids comment analysis in the new code handling deplist.d


r3504@localhost (orig r2441): bruno | 2009-09-29 19:34:34 +0200

  • fuse device is needed at restore time for sshfs


r3505@localhost (orig r2442): bruno | 2009-09-29 20:02:36 +0200

  • Improves udev timeout handling


r3506@localhost (orig r2443): bruno | 2009-09-29 20:43:38 +0200

  • priority given to env var for tmpdir
  • fuse FS excluded from tmpdir computation


r3518@localhost (orig r2447): bruno | 2009-10-04 01:58:08 +0200

  • Iprove USB log in case of error by adding the conf file


r3519@localhost (orig r2448): bruno | 2009-10-05 11:06:13 +0200


r3520@localhost (orig r2449): bruno | 2009-10-06 01:10:35 +0200

  • Adds support for grub2 conf file grub.cfg in addition to menu.lst


r3521@localhost (orig r2450): bruno | 2009-10-06 01:24:02 +0200

  • Fix a mr_asprintf usage without & causing a seg fault.


r3523@localhost (orig r2452): bruno | 2009-10-06 12:47:56 +0200
CIFS mounts shouldn't be part of the mountlist analysis (should help solving #288)


r3524@localhost (orig r2453): bruno | 2009-10-07 10:17:03 +0200

  • Fix a bug in handling of -E option with real devices (bad report in function mr_make_devlist_from_pathlist of the test between -E and -I)


r3525@localhost (orig r2454): bruno | 2009-10-07 10:19:02 +0200

  • Fix an error in the test for grub conf files (or used instead of and)


r3526@localhost (orig r2455): bruno | 2009-10-07 16:14:59 +0200
afio is under /bin on Debian


r3527@localhost (orig r2456): bruno | 2009-10-07 17:31:26 +0200

  • Adds support for libcrc32c (needed by bnx2x)


r3532@localhost (orig r2457): bruno | 2009-10-09 13:33:44 +0200

  • Apply path from Matthew Cline (matt_at_nightrealms.com) in order to fix #359


r3533@localhost (orig r2458): bruno | 2009-10-09 13:41:02 +0200
Adds a conf file example for mindi and fix #360


r3535@localhost (orig r2459): bruno | 2009-10-09 15:13:01 +0200
MOde of conf file


r3546@localhost (orig r2461): bruno | 2009-10-14 01:12:24 +0200

  • umount freshly created VFAT partition on USB key as Ubunu has an automounter mounting it as soon as created (Steffen Neumann sneumann_at_ipb-halle.de)


r3566@localhost (orig r2463): bruno | 2009-10-26 01:34:16 +0100

  • Reset an error counter before blanking a DVD to avoid always returning an error (Vincent Raman vincent.raman_at_macqel.eu)


r3567@localhost (orig r2464): bruno | 2009-10-26 13:57:14 +0100
bzip2 is under /bin on Debian


r3568@localhost (orig r2465): bruno | 2009-10-28 01:46:30 +0100
some distro hold lvm commands under /usr/sbin


r3595@localhost (orig r2469): bruno | 2009-11-10 12:22:10 +0100
/dev/shm is now part of the default exclude list


r3596@localhost (orig r2470): bruno | 2009-11-10 12:32:40 +0100
Remove useless pb_log and MONDO_TRACEFILE


r3597@localhost (orig r2471): bruno | 2009-11-10 12:57:58 +0100
Improve analysis of kernel modules by printing whether it's a live or extra module which has not been found (Matthew Cline) as reported in #362


r3598@localhost (orig r2472): bruno | 2009-11-10 13:21:46 +0100

  • Default to DVD size when in iso or netfs mode


r3599@localhost (orig r2473): bruno | 2009-11-10 14:13:10 +0100

  • Fix #363 where exclude_paths was extended up to memory limit dumping core


r3600@localhost (orig r2474): bruno | 2009-11-10 14:31:14 +0100

  • Update deplist for Debian support


r3602@localhost (orig r2476): bruno | 2009-11-11 02:44:42 +0100

  • small improvement for loging in USB case


r3603@localhost (orig r2477): bruno | 2009-11-11 13:29:27 +0100

  • Adds a nolvm boot option at restore time


r3604@localhost (orig r2478): bruno | 2009-11-11 19:54:51 +0100

  • Fix #367 - the for loop doesn't make any test now, as it was computed before entering the loop, leading to an error, and was also made inside the loop anyway.


r3605@localhost (orig r2479): bruno | 2009-11-12 00:32:45 +0100

  • Add support for diskdumplib driver useful for RHEL 3 and IBM xseries 336


r3606@localhost (orig r2480): bruno | 2009-11-12 01:09:40 +0100

  • If using nolvm, mondorestore should also not nalyze and handle i-want-my-lvm


r3608@localhost (orig r2482): bruno | 2009-11-14 12:54:11 +0100
Fix bunzip2 on debian as well


r3610@localhost (orig r2484): bruno | 2009-11-15 00:44:19 +0100

  • Adds support for variable serial port console, with defalut to /dev/ttyS0, and a boot param to change it with serial=/dev/ttySx


r3615@localhost (orig r2485): bruno | 2009-11-15 01:34:33 +0100

r3614@localhost: bruno | 2009-11-15 01:34:12 +0100
Adds a space in exclude paths


r3623@localhost (orig r2487): bruno | 2009-11-18 20:41:40 +0100

r3620@localhost: bruno | 2009-11-18 10:31:36 +0100

  • Only link /dev/tty to serial port when there is indeed a serial port. If not breaks mondorestore on normal console


r3631@localhost (orig r2490): bruno | 2009-11-24 01:48:29 +0100
Put news below in the main page to make it more readable


r3648@localhost (orig r2492): bruno | 2009-11-25 23:50:13 +0100

r3647@localhost: bruno | 2009-11-25 23:49:11 +0100

  • Add warning for -f and SW Raid as in 2.2.10


r3650@localhost (orig r2493): bruno | 2009-11-26 00:19:52 +0100

r3649@localhost: bruno | 2009-11-26 00:18:27 +0100

  • Addition of the german translation made by Magnus Rasche (Magnus.rasche_at_gmx.de) and Website inclusion


r3652@localhost (orig r2495): bruno | 2009-11-27 15:55:55 +0100
cosmetic display fix
r3659@localhost (orig r2498): bruno | 2009-12-05 17:53:03 +0100
nfsopt restore boot time option added to support custom mount options for network restore


r3684@localhost (orig r2501): bruno | 2009-12-17 00:35:08 +0100
Fix #375 mondo will segfault if the partition in sensibly_set_tmpdir_and_scratchdir() is read-only (cylau)


r3685@localhost (orig r2502): bruno | 2009-12-17 01:02:47 +0100

  • Fix an issue in the function listing kernel modules when not found


r3686@localhost (orig r2503): bruno | 2009-12-17 01:15:01 +0100
Adds scsi_dump_register to mindi SCSI_MODS for RHEL3 + IBM servers


r3701@localhost (orig r2504): bruno | 2009-12-23 02:24:33 +0100

  • Addition of the Lab for Mondorescue


r3702@localhost (orig r2505): bruno | 2009-12-23 02:41:17 +0100
Web site update for Lab MondoRescue delivery


r3706@localhost (orig r2506): bruno | 2010-01-04 11:31:53 +0100

  • Fix a bug when isodir is / only when splitting it in iso_path and iso_mnt


r3707@localhost (orig r2507): bruno | 2010-01-04 13:22:49 +0100

  • Fix #377: Segfault in pause_and_ask_for_cdr() (ggeens)


  • Property svn:keywords set to Id
File size: 20.9 KB
Line 
1/***************************************************************************
2 cvsid : $Id: mondo-rstr-compare.c 2508 2010-01-04 18:21:55Z bruno $
3***************************************************************************/
4
5#include <pthread.h>
6#include "my-stuff.h"
7#include "mr_mem.h"
8#include "../common/mondostructures.h"
9#include "../common/libmondo.h"
10//#include "../../config.h"
11#include "mr-externs.h"
12#include "mondo-rstr-compare.h"
13#include "mondo-restore-EXT.h"
14#include "mondo-rstr-tools-EXT.h"
15
16extern char *MONDO_LOGFILE;
17
18/* Reference to global bkpinfo */
19extern struct s_bkpinfo *bkpinfo;
20
21extern char *g_mountlist_fname;
22
23//static char cvsid[] = "$Id: mondo-rstr-compare.c 2508 2010-01-04 18:21:55Z bruno $";
24
25void popup_changelist_from_file(char *);
26
27
28/**
29 * @addtogroup LLcompareGroup
30 * @{
31 */
32/**
33 * Compare biggiefile number @p bigfileno with the filesystem mounted on @p MNT_RESTORING.
34 * @param bkpinfo The backup information structure. Only used in insist_on_this_cd_number().
35 * @param bigfileno The biggiefile number (starting from 0) to compare.
36 * @note This function uses an MD5 checksum.
37 */
38int compare_a_biggiefile(long bigfileno)
39{
40
41 FILE *fin;
42 FILE *fout;
43
44 /** needs malloc *******/
45 char *checksum = NULL;
46 char *original_cksum = NULL;
47 char *bigfile_fname = NULL;
48 char *tmp = NULL;
49 char *command = NULL;
50
51 char *p;
52 int i;
53 int retval = 0;
54
55 struct s_filename_and_lstat_info biggiestruct;
56
57 /*********************************************************************
58 * allocate memory clear test sab 16 feb 2003 *
59 *********************************************************************/
60 assert(bkpinfo != NULL);
61 /** end **/
62
63 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
64 if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
65 insist_on_this_cd_number((++g_current_media_number));
66 } else {
67 log_msg(2, "No CD's left. No biggiefiles left. No prob, Bob.");
68 return (0);
69 }
70 }
71 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
72 log_to_screen("Cannot open bigfile %ld (NULL)'s info file", bigfileno + 1);
73 return (1);
74 }
75 fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin);
76 paranoid_fclose(fin);
77
78 mr_asprintf(checksum, "%s", biggiestruct.checksum);
79 mr_asprintf(bigfile_fname, "%s", biggiestruct.filename);
80
81 log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename);
82 log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum);
83
84 if (!g_text_mode) {
85 mr_asprintf(tmp, "Comparing %s", bigfile_fname);
86 newtDrawRootText(0, 22, tmp);
87 paranoid_free(tmp);
88 newtRefresh();
89 }
90 if (!checksum[0]) {
91 log_msg(2, "Warning - %s has no checksum", bigfile_fname);
92 }
93 if (!strncmp(bigfile_fname, "/dev/", 5)) {
94 log_msg(2, "IGNORING %s as begining with /dev", bigfile_fname);
95 mr_free(bigfile_fname);
96 return (1);
97 }
98
99 mr_asprintf(command, "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors", MNT_RESTORING, bigfile_fname);
100 log_msg(2, command);
101 i = system(command);
102 mr_free(command);
103
104 mr_asprintf(tmp, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE);
105 paranoid_system(tmp);
106 paranoid_free(tmp);
107
108 if (i) {
109 log_OS_error("Warning - command failed");
110 return (1);
111 } else {
112 if (!(fin = fopen("/tmp/md5sum.txt", "r"))) {
113 log_msg(2,
114 "Unable to open /tmp/md5sum.txt; can't get live checksum");
115 mr_free(bigfile_fname);
116 return (1);
117 } else {
118 mr_getline(original_cksum, fin);
119 paranoid_fclose(fin);
120 p = strchr(original_cksum, ' ');
121 if (p) {
122 *p = '\0';
123 }
124 }
125 }
126 mr_asprintf(tmp, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname);
127 if ((original_cksum != NULL) && (strcmp(checksum, original_cksum) == 0)) {
128 mr_strcat(tmp, " ... OK");
129 } else {
130 mr_strcat(tmp, "... changed");
131 retval++;
132 }
133 mr_free(checksum);
134 mr_free(original_cksum);
135
136 log_msg(1, tmp);
137 paranoid_free(tmp);
138
139 if (retval) {
140 if (!(fout = fopen(MONDO_CACHE"/changed.txt", "a"))) {
141 fatal_error("Cannot openout changed.txt");
142 }
143 fprintf(fout, "%s\n", bigfile_fname);
144 paranoid_fclose(fout);
145 }
146 mr_free(bigfile_fname);
147
148 return (retval);
149}
150
151/**************************************************************************
152 *END_COMPARE_A_BIGGIEFILE *
153 **************************************************************************/
154
155
156/**
157 * Compare all biggiefiles in the backup.
158 * @return 0 for success, nonzero for failure.
159 */
160int compare_all_biggiefiles()
161{
162 int retval = 0;
163 int res;
164 long noof_biggiefiles, bigfileno = 0;
165 char *tmp = NULL;
166
167 log_msg(1, "Comparing biggiefiles");
168
169 if (length_of_file(BIGGIELIST) < 6) {
170 log_msg(1,
171 "OK, really teeny-tiny biggielist; not comparing biggiefiles");
172 return (0);
173 }
174 noof_biggiefiles = count_lines_in_file(BIGGIELIST);
175 if (noof_biggiefiles <= 0) {
176 log_msg(1, "OK, no biggiefiles; not comparing biggiefiles");
177 return (0);
178 }
179 mvaddstr_and_log_it(g_currentY, 0,
180 "Comparing large files ");
181 open_progress_form("Comparing large files",
182 "I am now comparing the large files",
183 "against the filesystem. Please wait.", "",
184 noof_biggiefiles);
185 for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) {
186 mr_asprintf(tmp, "Comparing big file #%ld", bigfileno + 1);
187 log_msg(1, tmp);
188 update_progress_form(tmp);
189 mr_free(tmp);
190
191 res = compare_a_biggiefile(bigfileno);
192 retval += res;
193 g_current_progress++;
194 }
195 close_progress_form();
196 return (0);
197 if (retval) {
198 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
199 } else {
200 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
201 }
202 return (retval);
203}
204
205/**************************************************************************
206 *END_COMPARE_ALL_BIGGIEFILES *
207 **************************************************************************/
208
209
210/**
211 * Compare afioball @p tarball_fname against the filesystem.
212 * You must be chdir()ed to the directory where the filesystem is mounted
213 * before you call this function.
214 * @param tarball_fname The filename of the tarball to compare.
215 * @param current_tarball_number The fileset number contained in @p tarball_fname.
216 * @return 0 for success, nonzero for failure.
217 */
218int compare_a_tarball(char *tarball_fname, int current_tarball_number)
219{
220 int retval = 0;
221 int res;
222 long noof_lines;
223 long archiver_errors;
224 bool use_star;
225
226 /*** needs malloc *********/
227 char *command = NULL;
228 char *tmp = NULL;
229 char *archiver_exe = NULL;
230 char *tmp1 = NULL;
231 char *filelist_name = NULL;
232 char *logfile = NULL;
233 char *compressor_exe = NULL;
234
235 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
236 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
237 mr_asprintf(filelist_name, MNT_CDROM "/archives/filelist.%d", current_tarball_number);
238 noof_lines = count_lines_in_file(filelist_name);
239 mr_free(filelist_name);
240
241 if (strstr(tarball_fname, ".bz2")) {
242 mr_asprintf(compressor_exe, "bzip2");
243 } else if (strstr(tarball_fname, ".lzma")) {
244 mr_asprintf(compressor_exe, "lzma");
245 } else if (strstr(tarball_fname, ".gz")) {
246 mr_asprintf(compressor_exe, "gzip");
247 } else if (strstr(tarball_fname, ".lzo")) {
248 mr_asprintf(compressor_exe, "lzop");
249 }
250
251 if (use_star) {
252 mr_asprintf(archiver_exe, "star");
253 } else {
254 mr_asprintf(archiver_exe, "afio");
255 }
256
257 if (compressor_exe) {
258 tmp1 = find_home_of_exe(compressor_exe);
259 if (!tmp1) {
260 mr_free(tmp1);
261 mr_free(compressor_exe);
262 mr_free(archiver_exe);
263 fatal_error("(compare_a_tarball) Compression program missing");
264 }
265 mr_free(tmp1);
266
267 if (use_star) {
268 if (!strcmp(compressor_exe, "bzip2")) {
269 mr_strcat(archiver_exe, " -bz");
270 } else {
271 mr_free(compressor_exe);
272 mr_free(archiver_exe);
273 fatal_error("(compare_a_tarball) Please use only bzip2 with star");
274 }
275 } else {
276 // afio
277 mr_free(compressor_exe);
278 mr_asprintf(tmp, "%s", compressor_exe);
279 mr_asprintf(compressor_exe, "-P %s -Z", tmp);
280 mr_free(tmp);
281 }
282 }
283
284#ifdef __FreeBSD__
285#define BUFSIZE 512L
286#else
287#define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
288#endif
289 mr_asprintf(logfile, "/tmp/afio.log.%d", current_tarball_number);
290
291 if (use_star) {
292 // doesn't use compressor_exe
293 mr_asprintf(command, "%s -diff H=exustar file=%s >> %s 2>> %s", archiver_exe, tarball_fname, logfile, logfile);
294 } else {
295 mr_asprintf(command, "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", archiver_exe, TAPE_BLOCK_SIZE, BUFSIZE, compressor_exe, tarball_fname, logfile, logfile);
296 }
297 mr_free(compressor_exe);
298 paranoid_free(archiver_exe);
299
300#undef BUFSIZE
301
302 res = system(command);
303 retval += res;
304 if (res) {
305 log_OS_error(command);
306 log_msg(2, "Warning - afio returned error = %d", res);
307 }
308 mr_free(command);
309
310 if (length_of_file(logfile) > 5) {
311 mr_asprintf(command, "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vE \"^dev/.*\" >> "MONDO_CACHE"/changed.txt", logfile);
312 system(command);
313 mr_free(command);
314
315 archiver_errors = count_lines_in_file(logfile);
316 } else {
317 archiver_errors = 0;
318 }
319 if (archiver_errors) {
320 log_msg(1, "%ld difference%c in fileset #%d ", archiver_errors, (archiver_errors != 1) ? 's' : ' ', current_tarball_number);
321 }
322 unlink(logfile);
323 mr_free(logfile);
324
325 return (retval);
326}
327
328/**************************************************************************
329 *END_COMPARE_A_TARBALL *
330 **************************************************************************/
331
332
333/**
334 * Compare all afioballs in this backup.
335 * @param bkpinfo The backup media structure. Passed to other functions.
336 * @return 0 for success, nonzero for failure.
337 */
338int compare_all_tarballs()
339{
340 int retval = 0;
341 int res;
342 int current_tarball_number = 0;
343
344 /** needs malloc **********/
345
346 char *tarball_fname = NULL;
347 char *progress_str = NULL;
348 char *tmp = NULL;
349 char *mds = NULL;
350 long max_val;
351
352 assert(bkpinfo != NULL);
353 mvaddstr_and_log_it(g_currentY, 0, "Comparing archives");
354 tmp = read_cfg_var(g_mondo_cfg_file, "last-filelist-number");
355 max_val = atol(tmp);
356 mr_free(tmp);
357
358 mds = media_descriptor_string(bkpinfo->backup_media_type);
359 mr_asprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number);
360
361 open_progress_form("Comparing files",
362 "Comparing tarballs against filesystem.",
363 "Please wait. This may take some time.",
364 progress_str, max_val);
365
366 log_to_screen(progress_str);
367
368 for (;;) {
369 insist_on_this_cd_number(g_current_media_number);
370 update_progress_form(progress_str);
371 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number);
372
373 if (!does_file_exist(tarball_fname)) {
374 mr_free(tarball_fname);
375 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo", current_tarball_number);
376 }
377 if (!does_file_exist(tarball_fname)) {
378 mr_free(tarball_fname);
379 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzma", current_tarball_number);
380 }
381 if (!does_file_exist(tarball_fname)) {
382 mr_free(tarball_fname);
383 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.gz", current_tarball_number);
384 }
385 if (!does_file_exist(tarball_fname)) {
386 mr_free(tarball_fname);
387 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.", current_tarball_number);
388 }
389 if (!does_file_exist(tarball_fname)) {
390 mr_free(tarball_fname);
391 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2", current_tarball_number);
392 }
393 if (!does_file_exist(tarball_fname)) {
394 mr_free(tarball_fname);
395 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.star.", current_tarball_number);
396 }
397 if (!does_file_exist(tarball_fname)) {
398 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST") ||
399 system("find " MNT_CDROM
400 "/archives/slice* > /dev/null 2> /dev/null")
401 == 0) {
402 log_msg(2, "OK, I think I'm done with tarballs...");
403 mr_free(tarball_fname);
404 break;
405 }
406 log_msg(2, "OK, I think it's time for another CD...");
407 g_current_media_number++;
408
409 mr_free(progress_str);
410 mr_asprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number);
411 log_to_screen(progress_str);
412 } else {
413 res = compare_a_tarball(tarball_fname, current_tarball_number);
414
415 g_current_progress++;
416 current_tarball_number++;
417 }
418 mr_free(tarball_fname);
419 }
420 mr_free(progress_str);
421 mr_free(mds);
422
423 close_progress_form();
424 if (retval) {
425 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
426 } else {
427 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
428 }
429 return (retval);
430}
431
432/**************************************************************************
433 *END_COMPARE_ALL_TARBALLS *
434 **************************************************************************/
435
436/* @} - end LLcompareGroup */
437
438
439/**
440 * @addtogroup compareGroup
441 * @{
442 */
443/**
444 * Compare all data on a CD-R/CD-RW/DVD/ISO/NFS-based backup.
445 * @param bkpinfo The backup information structure. Passed to other functions.
446 * @return 0 for success, nonzero for failure.
447 */
448int compare_to_CD()
449{
450 /** needs malloc *********/
451 char *tmp = NULL;
452 char *cwd, *new;
453 char *command = NULL;
454 int resA = 0;
455 int resB = 0;
456 long noof_changed_files;
457
458 malloc_string(cwd);
459 malloc_string(new);
460
461 assert(bkpinfo != NULL);
462
463 getcwd(cwd, MAX_STR_LEN - 1);
464 chdir(bkpinfo->restore_path);
465 getcwd(new, MAX_STR_LEN - 1);
466 insist_on_this_cd_number(g_current_media_number);
467 unlink(MONDO_CACHE"/changed.txt");
468
469 resA = compare_all_tarballs();
470 resB = compare_all_biggiefiles();
471 chdir(cwd);
472 noof_changed_files = count_lines_in_file(MONDO_CACHE"/changed.txt");
473 if (noof_changed_files) {
474 mr_asprintf(tmp, "%ld files do not match the backup ", noof_changed_files);
475 log_to_screen(tmp);
476 mr_free(tmp);
477
478 mr_asprintf(command, "cat "MONDO_CACHE"/changed.txt >> %s", MONDO_LOGFILE);
479 paranoid_system(command);
480 mr_free(command);
481 } else {
482 mr_asprintf(tmp, "All files match the backup ");
483 mvaddstr_and_log_it(g_currentY++, 0, tmp);
484 log_to_screen(tmp);
485 mr_free(tmp);
486 }
487
488 paranoid_free(cwd);
489 paranoid_free(new);
490
491 return (resA + resB);
492}
493
494/**************************************************************************
495 *END_COMPARE_TO_CD *
496 **************************************************************************/
497
498
499
500
501/**
502 * Compare all data in the user's backup.
503 * This function will mount filesystems, compare afioballs and biggiefiles,
504 * and show the user the differences.
505 * @param bkpinfo The backup information structure. Passed to other functions.
506 * @param mountlist The mountlist containing partitions to mount.
507 * @param raidlist The raidlist containing the user's RAID devices.
508 * @return The number of errors/differences found.
509 */
510int
511compare_mode(struct mountlist_itself *mountlist,
512 struct raidlist_itself *raidlist)
513{
514 int retval = 0;
515 int res = 0;
516 long q;
517 char *tmp = NULL;
518 char *new;
519 char *cwd;
520
521 malloc_string(new);
522 malloc_string(cwd);
523
524 /**************************************************************************
525 * also deletes tmp/filelist.full & tmp/biggielist.txt _and_ tries to *
526 * restore them from start of tape, if available *
527 **************************************************************************/
528 assert(bkpinfo != NULL);
529 assert(mountlist != NULL);
530 assert(raidlist != NULL);
531
532 while (get_cfg_file_from_archive()) {
533 if (!ask_me_yes_or_no
534 ("Failed to find config file/archives. Choose another source?"))
535 {
536 fatal_error("Unable to find config file/archives. Aborting.");
537 }
538 interactively_obtain_media_parameters_from_user(FALSE);
539 }
540
541 read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
542
543 /* edit_mountlist if wanted */
544 log_it("About to edit mountlist");
545 if (g_text_mode) {
546 save_mountlist_to_disk(mountlist, g_mountlist_fname);
547 mr_asprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname);
548 res = system(tmp);
549 mr_free(tmp);
550
551 load_mountlist(mountlist, g_mountlist_fname);
552 } else {
553 res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
554 }
555 log_it("Finished editing mountlist");
556 if (res) {
557 paranoid_MR_finish(1);
558 }
559 save_mountlist_to_disk(mountlist, g_mountlist_fname);
560 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
561
562 g_current_media_number = 1;
563 mvaddstr_and_log_it(1, 30, "Comparing Automatically");
564 log_it("Pre-MAD");
565 retval = mount_all_devices(mountlist, FALSE);
566 log_it("Post-MAD");
567 if (retval) {
568 unmount_all_devices(mountlist);
569 return (retval);
570 }
571 if (bkpinfo->backup_media_type == tape
572 || bkpinfo->backup_media_type == udev) {
573 retval += compare_to_tape();
574 } else if (bkpinfo->backup_media_type == cdstream) {
575 retval += compare_to_cdstream();
576 } else {
577 retval += compare_to_CD();
578 }
579 if (retval) {
580 mvaddstr_and_log_it(g_currentY++,
581 0,
582 "Warning - differences found during the compare phase");
583 }
584
585 if (count_lines_in_file(MONDO_CACHE"/changed.txt") > 0) {
586 mvaddstr_and_log_it(g_currentY++, 0,
587 "Differences found while files were being compared.");
588 streamline_changes_file(MONDO_CACHE"/changed.files", MONDO_CACHE"/changed.txt");
589 if (count_lines_in_file(MONDO_CACHE"/changed.files") <= 0) {
590 mvaddstr_and_log_it(g_currentY++, 0,
591 "...but they were logfiles and temporary files. Your archives are fine.");
592 log_to_screen
593 ("The differences were logfiles and temporary files. Your archives are fine.");
594 } else {
595 q = count_lines_in_file(MONDO_CACHE"/changed.files");
596 mr_asprintf(tmp, "%ld significant difference%s found.", q, (q != 1) ? "s" : "");
597 mvaddstr_and_log_it(g_currentY++, 0, tmp);
598 log_to_screen(tmp);
599 mr_free(tmp);
600
601 mr_asprintf(tmp, "Type 'less /tmp/changed.files' for a list of non-matching files");
602 mvaddstr_and_log_it(g_currentY++, 0, tmp);
603 log_to_screen(tmp);
604 mr_free(tmp);
605
606 log_msg(2, "calling popup_changelist_from_file()");
607 getcwd(cwd, MAX_STR_LEN - 1);
608 chdir(bkpinfo->restore_path);
609 getcwd(new, MAX_STR_LEN - 1);
610 popup_changelist_from_file(MONDO_CACHE"/changed.files");
611 chdir(cwd);
612 log_msg(2, "Returning from popup_changelist_from_file()");
613 }
614 } else {
615 log_to_screen
616 ("No significant differences were found. Your backup is perfect.");
617 }
618 retval += unmount_all_devices(mountlist);
619
620 kill_petris();
621 paranoid_free(new);
622 paranoid_free(cwd);
623 return (retval);
624}
625
626/**************************************************************************
627 *END_COMPARE_MODE *
628 **************************************************************************/
629
630/**
631 * Compare all data on a cdstream-based backup.
632 * @param bkpinfo The backup information structure. Fields used:
633 * - @c bkpinfo->disaster_recovery
634 * - @c bkpinfo->media_device
635 * - @c bkpinfo->restore_path
636 * @return 0 for success, nonzero for failure.
637 */
638int compare_to_cdstream()
639{
640 int res;
641
642 /** needs malloc **/
643 char *dir;
644 char *command = NULL;
645
646 assert(bkpinfo != NULL);
647 malloc_string(dir);
648 getcwd(dir, MAX_STR_LEN);
649 chdir(bkpinfo->restore_path);
650
651 mvaddstr_and_log_it(g_currentY,
652 0, "Verifying archives against filesystem");
653
654 mr_free(bkpinfo->media_device);
655 if (bkpinfo->disaster_recovery && does_file_exist(MINDI_CACHE"/CDROM-LIVES-HERE")) {
656 bkpinfo->media_device = last_line_of_file(MINDI_CACHE"/CDROM-LIVES-HERE");
657 } else {
658 bkpinfo->media_device = find_cdrom_device(FALSE);
659 }
660 res = verify_tape_backups();
661 chdir(dir);
662 if (length_of_file(MONDO_CACHE"/changed.txt") > 2
663 && length_of_file(MONDO_CACHE"/changed.files") > 2) {
664 log_msg(0,
665 "Type 'less "MONDO_CACHE"/changed.files' to see which files don't match the archives");
666 log_msg(2, "Calling popup_changelist_from_file()");
667 popup_changelist_from_file(MONDO_CACHE"/changed.files");
668 log_msg(2, "Returned from popup_changelist_from_file()");
669 }
670
671 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
672 paranoid_free(dir);
673 return (res);
674}
675
676/**************************************************************************
677 *END_COMPARE_CD_STREAM *
678 **************************************************************************/
679
680
681/**
682 * Compare all data on a tape-based backup.
683 * @param bkpinfo The backup information structure. Field used: @c bkpinfo->restore_path.
684 * @return 0 for success, nonzero for failure.
685 */
686/**************************************************************************
687 * F@COMPARE_TO_TAPE() *
688 * compare_to_tape() - gots me?? *
689 * *
690 * returns: int *
691 **************************************************************************/
692int compare_to_tape()
693{
694 int res;
695 char *dir;
696 char *command = NULL;
697
698 assert(bkpinfo != NULL);
699 malloc_string(dir);
700
701 getcwd(dir, MAX_STR_LEN);
702 chdir(bkpinfo->restore_path);
703
704 mvaddstr_and_log_it(g_currentY,
705 0, "Verifying archives against filesystem");
706 res = verify_tape_backups();
707 chdir(dir);
708 if (res) {
709 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
710 } else {
711 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
712 }
713 paranoid_free(dir);
714 return (res);
715}
716
717/**************************************************************************
718 *END_COMPARE_TO_TAPE *
719 **************************************************************************/
720
721/* @} - end compareGroup */
Note: See TracBrowser for help on using the repository browser.