Changeset 2424 in MondoRescue


Ignore:
Timestamp:
Sep 25, 2009, 6:44:01 PM (15 years ago)
Author:
Bruno Cornec
Message:
  • 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
Location:
branches/2.2.9
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi/analyze-my-lvm

    r2342 r2424  
    177177
    178178ListLvmDrivesAndPartitions() {
    179     $LVMCMD vgdisplay -v 2> /dev/null | grep "PV Name" | sed 's/(#)//' | awk '{print $3}' > $MINDI_TMP/vg.tmp
    180     if [ -f /etc/multipath.conf ]; then
    181         # If multipath check which type of devidec are given, mpath prefered
    182         for d in `cat  $MINDI_TMP/vg.tmp`; do
     179    for d in `$LVMCMD vgdisplay -v 2> /dev/null | grep "PV Name" | sed 's/(#)//' | awk '{print $3}'`; do
     180        # Skip devices excluded, coming from mondoarchive
     181        if [ "$EXCLUDE_DEVS" ] && [ "`echo " $EXCLUDE_DEVS " | grep " $d "`" ]; then
     182            continue
     183        fi
     184        # If multipath check which type of devides are given, mpath prefered
     185        if [ -f /etc/multipath.conf ]; then
    183186            GiveMapperOfdm $d
    184         done
    185     else
    186         cat $MINDI_TMP/vg.tmp
    187     fi
    188     rm -f $MINDI_TMP/vg.tmp
     187        else
     188            echo $d
     189        fi
     190    done
    189191}
    190192
  • branches/2.2.9/mindi/mindi

    r2422 r2424  
    999999            LVM="false"
    10001000        fi
    1001         all_partitions=`cat $MINDI_TMP/lvm.res | grep -F ">>>" | cut -d' ' -f2-32`
     1001        all_partitions=`cat $MINDI_TMP/lvm.res | grep -F ">>>" | cut -d' ' -f2-`
    10021002    fi
    10031003    all_partitions="$all_partitions `ListAllPartitions 2> /dev/null`"
     
    27652765        LAST_FILELIST_NUMBER=${12}
    27662766        ESTIMATED_TOTAL_NOOF_SLICES=${13}
    2767         EXCLUDE_DEVS="${14}"
     2767        export EXCLUDE_DEVS="${14}"
    27682768        USE_COMP="${15}"
    27692769        USE_LILO="${16}"
  • branches/2.2.9/mondo/src/common/libmondo-archive.c

    r2419 r2424  
    522522    char *cd_recovery_sz = NULL;
    523523    char *tape_size_sz = NULL;
    524     char *devs_to_exclude = NULL;
    525524    char *use_lilo_sz = NULL;   /* BCO: shared between LILO/ELILO */
    526525    char *value = NULL;
     
    541540
    542541    assert(bkpinfo != NULL);
    543     mr_asprintf(&tmp, "echo '%s' | tr -s ' ' '\n' | grep -E '^/dev/.*$' | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'",
    544             bkpinfo->exclude_paths);
    545     mr_asprintf(&devs_to_exclude, "%s", call_program_and_get_last_line_of_output(tmp));
    546     mr_free(tmp);
    547 
    548     mr_asprintf(&tmp, "devs_to_exclude = '%s'", devs_to_exclude);
    549     log_msg(2, tmp);
    550     mr_free(tmp);
    551542
    552543    mvaddstr_and_log_it(g_currentY, 0,
     
    884875            last_filelist_number,   // parameter #12 (STRING)
    885876            estimated_total_noof_slices,    // parameter #13 (INT)
    886             devs_to_exclude,    // parameter #14
     877            bkpinfo->exclude_devs,  // parameter #14
    887878            use_comp_sz,        // parameter #15
    888879            use_lilo_sz,        // parameter #16
     
    892883            use_gzip_sz);       // parameter #20 (STRING)
    893884
    894     mr_free(devs_to_exclude);
    895885    mr_free(last_filelist_number);
    896886    mr_free(tape_device);
  • branches/2.2.9/mondo/src/common/libmondo-cli.c

    r2388 r2424  
    3838
    3939extern void setup_tmpdir(char *path);
     40void mr_make_devlist_from_pathlist(char *pathlist, char mode);
    4041extern double g_kernel_version;
    4142extern int g_current_media_number;
    4243extern pid_t g_main_pid;
    4344extern char *resolve_softlinks_to_get_to_actual_device_file(char *);
    44 
    45 /* Stuff that handles the -I and -E option when a whole disk DSF is used */
    46 typedef struct mounted_fs_struct {
    47     char device[MAX_STR_LEN];       /* The name of the device */
    48     char mount_point[MAX_STR_LEN];  /* The devices mount point */
    49     unsigned char check;            /* 1 == included on DSF */
    50     struct mounted_fs_struct *next;
    51 } MOUNTED_FS_STRUCT;
    52 static MOUNTED_FS_STRUCT *DSF_Head = NULL;      /* Points to the first entry of mounted_fs_struct list */
    53 static MOUNTED_FS_STRUCT *DSF_Tail = NULL;      /* Points to the last entry of mounted_fs_struct list */
    54 static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr);
    55 static void free_mounted_fs_list (void);
    56 static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list);
    57 static int create_list_of_non_NETFS_mounted_file_systems (void);
    58 static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point);
    59 static MOUNTED_FS_STRUCT *find_device_in_list (char *device);
    6045
    6146/* Do we use extended attributes and acl ?
     
    177162
    178163/**
    179  * Frees the memory for all of the structures on the linked list of
    180  * all of the non-NETFS mounted file systems.
    181  */
    182 static void free_mounted_fs_list (void) {
    183     MOUNTED_FS_STRUCT *DSFptr = NULL;
    184     MOUNTED_FS_STRUCT *DSFnext = NULL;
    185  
    186     DSFptr = DSF_Head;
    187     while (DSFptr != NULL) {
    188         DSFnext = DSFptr->next;
    189         paranoid_free(DSFptr);
    190         DSFptr = DSFnext;
    191     }
    192     DSF_Head = NULL;
    193     DSF_Tail = NULL;
    194 }
    195 
    196 /**
    197  * Creates a singly linked list of all of the non-NETFS mounted file systems.
    198  * @param DSFptr A pointer  to the structure MOUNTED_FS_STRUCT used to hold
    199  * the list of mounted file systems.
    200  * @return None.
    201  */
    202 static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr)
    203 {
    204     assert (DSFptr);
    205     if (DSF_Head == NULL) {
    206         DSF_Head = DSFptr;
    207     } else {
    208         DSF_Tail->next = DSFptr;
    209     }
    210     DSFptr->next = NULL;
    211     DSF_Tail = DSFptr;
    212 }
    213 
    214 /**
    215  * Find the structure, in the singly linked list of all of the non-NETFS
    216  * mounted file systems, that contains the specified device.
    217  * @param device The device to find
    218  * @return NULL if it didn't find the device, a pointer to the
    219  * structure if it did.
    220  */
    221 static MOUNTED_FS_STRUCT *find_device_in_list (char *device)
    222 {
    223     MOUNTED_FS_STRUCT *DSFptr = NULL;
    224 
    225     DSFptr = DSF_Head;
    226     while (DSFptr != NULL) {
    227         if (!strcmp(DSFptr->device, device)) {
    228             break;
    229         }
    230         DSFptr = DSFptr->next;
    231     }
    232     return (DSFptr);
    233 }
    234 
    235 /**
    236  * Find the structure, in the singly linked list of all of the non-NETFS
    237  * mounted file systems, that contains the specified mount point.
    238  * @param mount_point The mount point to find
    239  * @return NULL is it didn't find the mount point, a pointer to the
    240  * structure if it did.
    241  */
    242 static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point)
    243 {
    244     MOUNTED_FS_STRUCT *DSFptr = NULL;
    245 
    246     DSFptr = DSF_Head;
    247     while (DSFptr != NULL) {
    248         if (!strcmp(DSFptr->mount_point, mount_point)) {
    249             break;
    250         }
    251         DSFptr = DSFptr->next;
    252     }
    253     return (DSFptr);
    254 }
    255 
    256 /**
    257  * Creates a linked list of all of the non-NETFS mounted file systems.
    258  * We use a linked list because we don't know how many  mounted file
    259  * there are (and there can be a lot).
    260  * @return 0 on success and greated than 0 on failure.
    261  */
    262 static int create_list_of_non_NETFS_mounted_file_systems (void)
    263 {
    264     int i = 0;
    265     int mount_cnt = 0;
    266     char *mounted_file_system = NULL;
    267     char *command = NULL;
    268     char *token = NULL;
    269     char token_chars[] =" :\t\r\f\a\0";
    270     MOUNTED_FS_STRUCT *DSFptr = NULL;
    271 
    272     free_mounted_fs_list();
    273     /********
    274     * Find the number of mounted file system entries and their respective mount points.
    275     * I can't return all of the entries as one string because it's length can be longer
    276     * than MAX_STR_LEN which is used in call_program_and_get_last_line_of_output().
    277     * So start looping and get the number of  mounted file systems and query them one by one.
    278     ********/
    279     /* Get the number of mounted file systems ((those that start with "/dev/" */
    280     mr_asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");
    281     log_msg(5, "Running: %s", command);
    282     mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
    283     paranoid_free(command);
    284 
    285     mount_cnt = atoi(mounted_file_system);
    286     log_msg (5, "mount_cnt: %d", mount_cnt);
    287     paranoid_free(mounted_file_system);
    288 
    289     for (i=mount_cnt; i > 0; i--) {
    290         mr_asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);
    291         log_msg(5, "Running: %s", command);
    292         mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
    293         paranoid_free(command);
    294 
    295         log_msg (5, "mounted_file_system: %s", mounted_file_system);
    296         if ((token = strtok(mounted_file_system, token_chars)) == NULL) {
    297             log_msg (4, "Could not get the list of mounted file systems");
    298             paranoid_free(mounted_file_system);
    299             mr_free(token);
    300             return (1);
    301         }
    302         if (token) {
    303             log_msg (5, "token: %s", token);
    304         }
    305         while (token != NULL) {
    306             log_msg (5, "token: %s", token);
    307             if ((DSFptr = (MOUNTED_FS_STRUCT *) calloc(1, sizeof(MOUNTED_FS_STRUCT))) == NULL) {
    308                 fatal_error ("Cannot allocate memory");
    309             }
    310             add_mounted_fs_struct(DSFptr);
    311             strcpy(DSFptr->device, token);
    312             mr_free(token);
    313             if ((token = strtok(NULL, token_chars)) == NULL) {
    314                 log_msg (5, "Ran out of entries on the mounted file systems list");
    315                 paranoid_free(mounted_file_system);
    316                 mr_free(token);
    317                 return (1);
    318             }
    319             log_msg (5, "token: %s", token);
    320             strcpy(DSFptr->mount_point, token);
    321             mr_free(token);
    322             token = strtok(NULL, token_chars);
    323         }
    324         paranoid_free(mounted_file_system);
    325     }
    326     /********
    327     * DSFptr = DSF_Head;
    328     * while (DSFptr != NULL) {
    329     * printf ("Dev: %s  MP: %s  Check: %d\n", DSFptr->device, DSFptr->mount_point, DSFptr->check);
    330     * DSFptr = DSFptr->next;
    331     * }
    332     ********/
    333     return (0);
    334 }
    335 
    336 /**
    337  * Given a whole disk device special file, determine which mounted file systems
    338  * are on the dsf's partitions and which mounted file systems are not.
    339  * @param dsf The whole disk device special file.
    340  * @param included_dsf_list A char pointer used to hold the list of mount points
    341  * that are on the dsf. Memory for the array will be allocated within the function.
    342  * @param excluded_dsf_list A char pointer used to hold the list of mount points
    343  * that are not on the dsf. Memory for the array will be allocated within the function.
    344  * @return 0 on success, -1 if no device special file was passed in, -2 if a device
    345  * special file was passed in but it has no partitions on it, or 1 on failure
    346  */
    347 static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list) {
    348     int i = 0;
    349     int c = 0;
    350     int lastpos = 0;
    351     char VG[MAX_STR_LEN];
    352     char *tmp = NULL;
    353     char *command = NULL;
    354     char *partition_list = NULL;
    355     char partitions[64][MAX_STR_LEN];
    356     char *mount_list = NULL;
    357     char *token = NULL;
    358     char token_chars[] =" \t\r\f\a\0";
    359     MOUNTED_FS_STRUCT *DSFptr = NULL;
    360 
    361     memset((char *)partitions, 0, sizeof(partitions));
    362 
    363     log_msg(5, "dsf: %s", dsf);
    364 
    365     /********
    366     * See if a device special file was passed in (i.e. it must start with /dev/
    367     ********/
    368     if (strncmp(dsf, "/dev/", 5)) {
    369         log_msg (5, "%s does not start with /dev/ and (probably) is not a  device special file", dsf);
    370         return (-1);
    371     }
    372     log_msg(5, "  %s looks like a device special file", dsf);
    373     /* Verify that the dsf exists */
    374     mr_asprintf(&command, "ls -al %s 2>/dev/null | wc -l", dsf);
    375     log_msg(5, "  Executing: %s", command);
    376     mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    377     paranoid_free(command);
    378 
    379     log_msg(5, "  Return value: %s", tmp);
    380     c = atoi(tmp);
    381     paranoid_free(tmp);
    382 
    383     if (!c) {
    384         log_to_screen("Cannot find device special file %s", dsf);
    385         return (1);
    386     }
    387     log_msg(5, "  %s device special file exists", dsf);
    388 
    389     /* Get a list of the mounted file systems */
    390     if (create_list_of_non_NETFS_mounted_file_systems()) {
    391         log_to_screen ("Could not get the list of mounted file systems");
    392         return (1);
    393     }
    394     log_msg (5, "Processing dsf: %s", dsf);
    395     /********
    396     * Get a list of the dsf's partitions. There could be no partitions on the disk
    397     * or a dsf of a partition was passed in (e.g. /dev/sda1 instead of /dev/sda).
    398     * Either way, it's an error.
    399     ********/
    400     mr_asprintf(&command, "parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
    401     log_msg(4, "Executing: %s", command);
    402     mr_asprintf(&partition_list, "%s", call_program_and_get_last_line_of_output(command));
    403     paranoid_free(command);
    404     log_msg(4, "Partition list for %s: %s", dsf, partition_list);
    405     if (!strlen(partition_list)) {
    406         /* There were no partitions on the disk */
    407         log_msg(4, "Cannot find any partitions on device special file %s", dsf);
    408         return (-2);
    409     }
    410 
    411     /* Fill the partition list */
    412     i = 0;
    413     lastpos = 0;
    414     while ((token = mr_strtok(partition_list, token_chars, &lastpos)) != NULL) {
    415         log_msg (5, "Found partition: %s", token);
    416         strcpy(partitions[i++], token);
    417         mr_free(token);
    418     }
    419     paranoid_free(partition_list);
    420  
    421     /********
    422      * At this point, we have a list of all of the partitions on the dsf. Now try to
    423      * see which partitions have a file system on them.
    424      *
    425      * Loop through each partition on the disk and:
    426      *
    427      * - If the partition is swap, it ignores it.
    428      *
    429      * - If the partition is mounted (e.g. /dev/sda1 is mounted on /boot), it adds an entry
    430      *  to the linked list, copies to it the device name and mount point, and sets check == 1.
    431      *
    432      * - If the partition is part of a Volume Group that has Logical Volumes mounted, it adds
    433      *  an entry to the linked list for each mounted Logical Volume in that Volume Group, copying
    434      *  to it the device name and mount point, and sets check == 1. Note that if the Volume Group
    435      *  contains more than one disk, it will still add the entry even if the Logical Volume's
    436      *  extents are not on the dsf that was passed in to the function. For example, Volume Group
    437      *  VolGroup00 contains the disks /dev/sda1 and /dev/sdb1, and the Logical Volumes LogVol01,
    438      *  which is mounted on /var and has all of its extents on /dev/sda1, and LogVol02, which is
    439      *  mounted as /usr and has all of its extents on /dev/sdb1. If you pass /dev/sda into the
    440      *  function, both /var and /usr will be archived even though /usr is actually on/dev/sdb.
    441      *
    442      * - If the partition is part of a Volume Group that has Logical Volumes used in a mounted
    443      *  software raid device, it adds an entry to the linked list, copies to it the software raid
    444      *  device name and mount point, and sets check == 1.
    445      *
    446      * - If the partition is part of a mounted software raid device, it adds an entry to the linked
    447      *  list, copies to it the software raid device name and mount point, and sets check == 1.
    448      *
    449      ********/
    450     for (i=0; strlen(partitions[i]); i++) {
    451         log_msg(4, "Processing partition: %s", partitions[i]);
    452         /* See if it's swap. If it is, ignore it. */
    453         mr_asprintf(&command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'",
    454           dsf, partitions[i]);
    455         log_msg(4, "  Running: %s", command);
    456         mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    457         paranoid_free(command);
    458         log_msg(4, "  Return value: %s", tmp);
    459         c = strlen(tmp);
    460         paranoid_free(tmp);
    461         if (c) {
    462             log_msg(4, "It's swap. Ignoring partition %s", partitions[i]);
    463             continue;
    464         }
    465         /* It's not swap. See if we can find the mount point from the mount command. */
    466         mr_asprintf(&command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
    467         mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    468         paranoid_free(command);
    469         if (strlen(tmp)) {
    470             log_msg(4, "  %s is mounted: %s", partitions[i], tmp);
    471             if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) {
    472                 log_msg (4, "Can't find mount point %s in mounted file systems list", tmp);
    473                 paranoid_free(tmp);
    474                 return (1);
    475             }
    476             DSFptr->check = 1;
    477             paranoid_free(tmp);
    478             continue;
    479         }
    480         paranoid_free(tmp);
    481         /* It's not swap and it's not mounted. See if it's LVM */
    482         log_msg(4, "  It's not mounted. Checking to see if it's LVM...");
    483         /* Get the partition ID; 8e for LVM */
    484         mr_asprintf(&command, "parted2fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]);
    485         log_msg(4, "  Running: %s", command);
    486         mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    487         paranoid_free(command);
    488         if (strlen(tmp)) {
    489             log_msg(4, "  Partition ID: %s", tmp);
    490             if (!strcasecmp(tmp, "8e")) {
    491                 /* It's LVM: Find the VG it's in */
    492                 log_msg(4, "  It's LVM: Find the VG it's in...");
    493                 mr_asprintf(&command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
    494                 log_msg(4, "  Running: %s", command);
    495                 strcpy(VG, call_program_and_get_last_line_of_output(command));
    496                 paranoid_free(command);
    497                 log_msg(4, "  Volume Group: %s", VG);
    498                 if (strlen(VG)) {
    499                     /* Found the Volume Group. Now find all of the VG's mount points */
    500                     log_msg(4, "  Found the Volume Group. Now find all of the VG's mount points");
    501                     mr_asprintf(&command, "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", VG, VG);
    502                     log_msg(4, "  Running: %s", command);
    503                     mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
    504                     paranoid_free(command);
    505                     log_msg(4, "  VG %s mount_list: %s", VG, mount_list);
    506                     lastpos = 0;
    507                     while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
    508                         log_msg (5, "mount point token: %s", token);
    509                         if ((DSFptr = find_mount_point_in_list(token)) == NULL) {
    510                             log_msg (4, "Can't find mount point %s in mounted file systems list", token);
    511                             paranoid_free(tmp);
    512                             mr_free(token);
    513                             return (1);
    514                         }
    515                         DSFptr->check = 1;
    516                         mr_free(token);
    517                     }
    518                     /********
    519                      * Now we want to see if there are any software raid devices using
    520                      * any of the Logical Volumes on the Volume Group.
    521                      *******/
    522                     paranoid_free(mount_list);
    523                     mr_asprintf(&command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    524                     log_msg (5, "Running: %s", command);
    525                     mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
    526                     paranoid_free(command);
    527                     log_msg(4, "  Software raid device list: %s", mount_list);
    528                     lastpos = 0;
    529                     while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
    530                         mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
    531                         log_msg (5, "Running: %s", command);
    532                         paranoid_free(tmp);
    533                         mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    534                         paranoid_free(command);
    535                         log_msg(4, "Number of Software raid device: %s", tmp);
    536                         if (atoi(tmp)) {
    537                             /* This device is on our disk */
    538                             if ((DSFptr = find_device_in_list(token)) == NULL) {
    539                                 log_msg (4, "Can't find device %s in mounted file systems list", token);
    540                                 paranoid_free(tmp);
    541                                 mr_free(token);
    542                                 return (1);
    543                             }
    544                             DSFptr->check = 1;
    545                         }
    546                     }
    547                     mr_free(token);
    548                     paranoid_free(mount_list);
    549                 } else {
    550                     log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
    551                     paranoid_free(tmp);
    552                     return (1);
    553                 }
    554                 paranoid_free(tmp);
    555                 continue;
    556             }
    557         } else {
    558             log_msg (4, "Error finding partition type for the partition %s", partitions[i]);
    559         }
    560         paranoid_free(tmp);
    561         /********
    562          * It's not swap, mounted, or LVM. See if it's used in a software raid device.
    563          ********/
    564         log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device.");
    565         mr_asprintf(&command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
    566         log_msg(4, "  Running: %s", command);
    567         mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    568         paranoid_free(command);
    569         if (!strlen(tmp)) {
    570             log_msg(4, "  Partition %s is not used in a non-LVM software raid device", partitions[i]);
    571             paranoid_free(tmp);
    572             continue;
    573         }
    574         log_msg (5, "  UUID: %s", tmp);
    575         /* Get the Software raid device list */
    576         mr_asprintf(&command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    577         log_msg (5, "  Running: %s", command);
    578         mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
    579         paranoid_free(command);
    580         log_msg(4, "  Software raid device list: %s", mount_list);
    581         /* Loop through the software raid device list to see if we can find the partition */
    582         lastpos = 0;
    583         while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
    584             mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
    585             log_msg(4, "  Running: %s", command);
    586             paranoid_free(tmp);
    587             mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    588             paranoid_free(command);
    589             if (!atoi(tmp)) {
    590                 log_msg (4,"  Didn't find partition %s in software raid device %s", partitions[i], token);
    591             } else {
    592                 if ((DSFptr = find_device_in_list(token)) == NULL) {
    593                     log_msg (4, "Can't find device %s in mounted file systems list", token);
    594                     paranoid_free(tmp);
    595                     mr_free(token);
    596                     return (1);
    597                 }
    598                 DSFptr->check = 1;
    599                 break;
    600             }
    601             mr_free(token);
    602         }
    603         paranoid_free(tmp);
    604     }
    605     paranoid_free(partition_list);
    606     paranoid_free(mount_list);
    607 
    608     /* Determine how much memory to allocate for included_dsf_list and excluded_dsf_list */
    609     i = 0;
    610     DSFptr= DSF_Head;
    611     while (DSFptr != NULL) {
    612         i += strlen(DSFptr->mount_point) + 1;
    613         DSFptr = DSFptr->next;
    614     }
    615     log_msg (5, "i: %d", i);
    616     if ((*included_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {
    617         fatal_error ("Cannot allocate memory");
    618     }
    619     if ((*excluded_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {
    620         fatal_error ("Cannot allocate memory");
    621     }
    622     DSFptr= DSF_Head;
    623     while (DSFptr != NULL) {
    624         if (DSFptr->check) {
    625             log_msg (5, "%s is mounted on %s and is on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf);
    626             strcat(*included_dsf_list, DSFptr->mount_point);
    627             strcat(*included_dsf_list, " ");
    628         } else {
    629             log_msg (4, "%s is mounted on %s and is NOT on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf);
    630             strcat(*excluded_dsf_list, DSFptr->mount_point);
    631             strcat(*excluded_dsf_list, " ");
    632         }
    633         DSFptr = DSFptr->next;
    634     }
    635     log_msg (5, "included_dsf_list: %s", *included_dsf_list);
    636     log_msg (5, "excluded_dsf_list: %s", *excluded_dsf_list);
    637     return (0);
    638 }
    639 
    640 
    641 /**
    642164 * Process mondoarchive's command-line switches.
    643165 * @param bkpinfo The backup information structure to populate.
     
    665187    char *p = NULL;
    666188    char *q = NULL;
    667     char *token = NULL;
    668     char *mounted_on_dsf = NULL;
    669     char *not_mounted_on_dsf = NULL;
    670     char token_chars[] =" \t\r\f\a\0";
    671189
    672190    long itbs = 0L;
     
    785303        }
    786304        paranoid_free(tmp1);
    787         while ((token = mr_strtok(flag_val['I'], token_chars, &lastpos)) != NULL) {
    788             switch (get_dsf_mount_list(token, &mounted_on_dsf, &not_mounted_on_dsf)) {
    789             /* It's a dsf but not a whole disk dsf */
    790             case -2:
    791                 log_to_screen("Could %s be a partition instead of a whole disk device special file?\n Ignored.", token);
    792                 break;
    793             /* Fatal error; exit */
    794             case 1:
    795                 fatal_error("Error processing -I option");
    796             /* Everything is OK; process to archive data */
    797             case 0:
    798                 log_to_screen("Archiving only the following file systems on %s:\n", token);
    799                 log_to_screen("  %s\n", mounted_on_dsf);
    800                 strcpy(bkpinfo->include_paths, "/");
    801                 if (strlen(not_mounted_on_dsf)) {
    802                     log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf);
    803                     log_to_screen("Not archiving the following file systems:\n");
    804                     log_to_screen("  %s\n", not_mounted_on_dsf);
    805                     strcat(bkpinfo->exclude_paths, not_mounted_on_dsf);
    806                     strcat(bkpinfo->exclude_paths, "");
    807                 }
    808                 break;
    809             /* A device special file was not passed in. Process it as a path. */
    810             case -1:
    811                     strcat(bkpinfo->include_paths, token);
    812                     strcat(bkpinfo->include_paths, " ");
    813                 break;
    814             }
    815             mr_free(token);
    816         }
    817         log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
    818         if (bkpinfo->exclude_paths != NULL) {
    819             log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths);
    820         }
     305        mr_make_devlist_from_pathlist(flag_val['I'], 'I');
    821306        log_msg(4, "Finished with the -I option");
    822307    }
     
    1152637        paranoid_free(tmp1);
    1153638        lastpos = 0;
    1154         while ((token = mr_strtok(flag_val['E'], token_chars, &lastpos)) != NULL) {
    1155             switch (get_dsf_mount_list(token, &mounted_on_dsf, &not_mounted_on_dsf)) {
    1156             case 1:
    1157                 log_msg(1, "WARNING ! a path doesn't exist in -E option");
    1158                 break;
    1159             /* Everything is OK; proceed to archive data */
    1160             case 0:
    1161                 if (strlen(mounted_on_dsf)) {
    1162                     log_to_screen("Excluding the following file systems on %s:\n", token);
    1163                     log_to_screen("  %s\n", mounted_on_dsf);
    1164                     log_msg (5, "Adding to bkpinfo->exclude_paths due to -E option: %s", mounted_on_dsf);
    1165                     strcat(bkpinfo->exclude_paths, mounted_on_dsf);
    1166                     strcat(bkpinfo->exclude_paths, " ");
    1167                 }
    1168                 break;
    1169             /* It's a dsf but not a whole disk dsf */
    1170             case -2:
    1171                 log_to_screen("Could %s be a partition instead of a whole disk device special file?\nIgnored.", token);
    1172                 break;
    1173             /* A device special file was not passed in. Process it as a path. */
    1174             case -1:
    1175                 strcat(bkpinfo->exclude_paths, token);
    1176                 strcat(bkpinfo->exclude_paths, " ");
    1177                 break;
    1178             }
    1179             mr_free(token);
    1180         }
    1181         log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths);
     639
     640        mr_make_devlist_from_pathlist(flag_val['E'], 'E');
    1182641        log_msg(4, "Finished with the -E option");
    1183642    }
  • branches/2.2.9/mondo/src/common/libmondo-devices.c

    r2423 r2424  
    6161extern struct s_bkpinfo *bkpinfo;
    6262
    63 
     63/* Stuff that handles the -I and -E option when a whole disk DSF is used */
     64typedef struct mounted_fs_struct {
     65    char device[MAX_STR_LEN];       /* The name of the device */
     66    char mount_point[MAX_STR_LEN];  /* The devices mount point */
     67    unsigned char check;            /* 1 == included on DSF */
     68    struct mounted_fs_struct *next;
     69} MOUNTED_FS_STRUCT;
     70
     71static MOUNTED_FS_STRUCT *DSF_Head = NULL;      /* Points to the first entry of mounted_fs_struct list */
     72static MOUNTED_FS_STRUCT *DSF_Tail = NULL;      /* Points to the last entry of mounted_fs_struct list */
    6473
    6574
     
    20742083    log_it("prefix = %s", bkpinfo->prefix);
    20752084    log_it("compression = %ld", bkpinfo->compression_level);
    2076     log_it("include_paths = '%s'", bkpinfo->include_paths);
    2077     log_it("exclude_paths = '%s'", bkpinfo->exclude_paths);
     2085
     2086    /* Handle devices passed in bkpinfo and print result */
     2087    mr_make_devlist_from_pathlist(bkpinfo->exclude_paths, 'E');
     2088    mr_make_devlist_from_pathlist(bkpinfo->include_paths, 'I');
     2089
    20782090    log_it("scratchdir = '%s'", bkpinfo->scratchdir);
    20792091    log_it("tmpdir = '%s'", bkpinfo->tmpdir);
     
    26092621/* @} - end of deviceGroup */
    26102622
    2611 
    26122623/**
    26132624 * Return the type of partition format (GPT or MBR)
     
    26402651}
    26412652
     2653/**
     2654 * Frees the memory for all of the structures on the linked list of
     2655 * all of the non-NETFS mounted file systems.
     2656 */
     2657static void free_mounted_fs_list (void) {
     2658    MOUNTED_FS_STRUCT *DSFptr = NULL;
     2659    MOUNTED_FS_STRUCT *DSFnext = NULL;
     2660 
     2661    DSFptr = DSF_Head;
     2662    while (DSFptr != NULL) {
     2663        DSFnext = DSFptr->next;
     2664        paranoid_free(DSFptr);
     2665        DSFptr = DSFnext;
     2666    }
     2667    DSF_Head = NULL;
     2668    DSF_Tail = NULL;
     2669}
     2670
     2671/**
     2672 * Creates a singly linked list of all of the non-NETFS mounted file systems.
     2673 * @param DSFptr A pointer  to the structure MOUNTED_FS_STRUCT used to hold
     2674 * the list of mounted file systems.
     2675 * @return None.
     2676 */
     2677static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr)
     2678{
     2679    assert (DSFptr);
     2680    if (DSF_Head == NULL) {
     2681        DSF_Head = DSFptr;
     2682    } else {
     2683        DSF_Tail->next = DSFptr;
     2684    }
     2685    DSFptr->next = NULL;
     2686    DSF_Tail = DSFptr;
     2687}
     2688
     2689/**
     2690 * Find the structure, in the singly linked list of all of the non-NETFS
     2691 * mounted file systems, that contains the specified device.
     2692 * @param device The device to find
     2693 * @return NULL if it didn't find the device, a pointer to the
     2694 * structure if it did.
     2695 */
     2696static MOUNTED_FS_STRUCT *find_device_in_list (char *device)
     2697{
     2698    MOUNTED_FS_STRUCT *DSFptr = NULL;
     2699
     2700    DSFptr = DSF_Head;
     2701    while (DSFptr != NULL) {
     2702        if (!strcmp(DSFptr->device, device)) {
     2703            break;
     2704        }
     2705        DSFptr = DSFptr->next;
     2706    }
     2707    return (DSFptr);
     2708}
     2709
     2710/**
     2711 * Find the structure, in the singly linked list of all of the non-NETFS
     2712 * mounted file systems, that contains the specified mount point.
     2713 * @param mount_point The mount point to find
     2714 * @return NULL is it didn't find the mount point, a pointer to the
     2715 * structure if it did.
     2716 */
     2717static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point)
     2718{
     2719    MOUNTED_FS_STRUCT *DSFptr = NULL;
     2720
     2721    DSFptr = DSF_Head;
     2722    while (DSFptr != NULL) {
     2723        if (!strcmp(DSFptr->mount_point, mount_point)) {
     2724            break;
     2725        }
     2726        DSFptr = DSFptr->next;
     2727    }
     2728    return (DSFptr);
     2729}
     2730
     2731/**
     2732 * Creates a linked list of all of the non-NETFS mounted file systems.
     2733 * We use a linked list because we don't know how many  mounted file
     2734 * there are (and there can be a lot).
     2735 * @return 0 on success and greated than 0 on failure.
     2736 */
     2737static int create_list_of_non_NETFS_mounted_file_systems (void)
     2738{
     2739    int i = 0;
     2740    int mount_cnt = 0;
     2741    char *mounted_file_system = NULL;
     2742    char *command = NULL;
     2743    char *token = NULL;
     2744    char token_chars[] =" :\t\r\f\a\0";
     2745    MOUNTED_FS_STRUCT *DSFptr = NULL;
     2746
     2747    free_mounted_fs_list();
     2748    /********
     2749    * Find the number of mounted file system entries and their respective mount points.
     2750    * I can't return all of the entries as one string because it's length can be longer
     2751    * than MAX_STR_LEN which is used in call_program_and_get_last_line_of_output().
     2752    * So start looping and get the number of  mounted file systems and query them one by one.
     2753    ********/
     2754    /* Get the number of mounted file systems ((those that start with "/dev/" */
     2755    mr_asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");
     2756    log_msg(5, "Running: %s", command);
     2757    mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
     2758    paranoid_free(command);
     2759
     2760    mount_cnt = atoi(mounted_file_system);
     2761    log_msg (5, "mount_cnt: %d", mount_cnt);
     2762    paranoid_free(mounted_file_system);
     2763
     2764    for (i=mount_cnt; i > 0; i--) {
     2765        mr_asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);
     2766        log_msg(5, "Running: %s", command);
     2767        mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
     2768        paranoid_free(command);
     2769
     2770        log_msg (5, "mounted_file_system: %s", mounted_file_system);
     2771        if ((token = strtok(mounted_file_system, token_chars)) == NULL) {
     2772            log_msg (4, "Could not get the list of mounted file systems");
     2773            paranoid_free(mounted_file_system);
     2774            mr_free(token);
     2775            return (1);
     2776        }
     2777        if (token) {
     2778            log_msg (5, "token: %s", token);
     2779        }
     2780        while (token != NULL) {
     2781            log_msg (5, "token: %s", token);
     2782            if ((DSFptr = (MOUNTED_FS_STRUCT *) calloc(1, sizeof(MOUNTED_FS_STRUCT))) == NULL) {
     2783                fatal_error ("Cannot allocate memory");
     2784            }
     2785            add_mounted_fs_struct(DSFptr);
     2786            strcpy(DSFptr->device, token);
     2787            mr_free(token);
     2788            if ((token = strtok(NULL, token_chars)) == NULL) {
     2789                log_msg (5, "Ran out of entries on the mounted file systems list");
     2790                paranoid_free(mounted_file_system);
     2791                mr_free(token);
     2792                return (1);
     2793            }
     2794            log_msg (5, "token: %s", token);
     2795            strcpy(DSFptr->mount_point, token);
     2796            mr_free(token);
     2797            token = strtok(NULL, token_chars);
     2798        }
     2799        paranoid_free(mounted_file_system);
     2800    }
     2801    /********
     2802    * DSFptr = DSF_Head;
     2803    * while (DSFptr != NULL) {
     2804    * printf ("Dev: %s  MP: %s  Check: %d\n", DSFptr->device, DSFptr->mount_point, DSFptr->check);
     2805    * DSFptr = DSFptr->next;
     2806    * }
     2807    ********/
     2808    return (0);
     2809}
     2810
     2811
     2812
     2813/**
     2814 * Given a whole disk device special file, determine which mounted file systems
     2815 * are on the dsf's partitions and which mounted file systems are not.
     2816 * @param dsf The whole disk device special file.
     2817 * @param included_dsf_list A char pointer used to hold the list of mount points
     2818 * that are on the dsf. Memory for the array will be allocated within the function.
     2819 * @param excluded_dsf_list A char pointer used to hold the list of mount points
     2820 * that are not on the dsf. Memory for the array will be allocated within the function.
     2821 * @return 0 on success, -1 if no device special file was passed in, -2 if a device
     2822 * special file was passed in but it has no partitions on it, or 1 on failure
     2823 */
     2824static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list) {
     2825    int i = 0;
     2826    int c = 0;
     2827    int lastpos = 0;
     2828    char VG[MAX_STR_LEN];
     2829    char *tmp = NULL;
     2830    char *command = NULL;
     2831    char *partition_list = NULL;
     2832    char partitions[64][MAX_STR_LEN];
     2833    char *mount_list = NULL;
     2834    char *token = NULL;
     2835    char token_chars[] =" \t\r\f\a\0";
     2836    MOUNTED_FS_STRUCT *DSFptr = NULL;
     2837
     2838    memset((char *)partitions, 0, sizeof(partitions));
     2839
     2840    log_msg(5, "dsf: %s", dsf);
     2841
     2842    /********
     2843    * See if a device special file was passed in (i.e. it must start with /dev/
     2844    ********/
     2845    if (strncmp(dsf, "/dev/", 5)) {
     2846        log_msg (5, "%s does not start with /dev/ and (probably) is not a  device special file", dsf);
     2847        return (-1);
     2848    }
     2849    log_msg(5, "  %s looks like a device special file", dsf);
     2850    /* Verify that the dsf exists */
     2851    mr_asprintf(&command, "ls -al %s 2>/dev/null | wc -l", dsf);
     2852    log_msg(5, "  Executing: %s", command);
     2853    mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     2854    paranoid_free(command);
     2855
     2856    log_msg(5, "  Return value: %s", tmp);
     2857    c = atoi(tmp);
     2858    paranoid_free(tmp);
     2859
     2860    if (!c) {
     2861        log_to_screen("Cannot find device special file %s", dsf);
     2862        return (1);
     2863    }
     2864    log_msg(5, "  %s device special file exists", dsf);
     2865
     2866    /* Get a list of the mounted file systems */
     2867    if (create_list_of_non_NETFS_mounted_file_systems()) {
     2868        log_to_screen ("Could not get the list of mounted file systems");
     2869        return (1);
     2870    }
     2871    log_msg (5, "Processing dsf: %s", dsf);
     2872    /********
     2873    * Get a list of the dsf's partitions. There could be no partitions on the disk
     2874    * or a dsf of a partition was passed in (e.g. /dev/sda1 instead of /dev/sda).
     2875    * Either way, it's an error.
     2876    ********/
     2877    mr_asprintf(&command, "parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
     2878    log_msg(4, "Executing: %s", command);
     2879    mr_asprintf(&partition_list, "%s", call_program_and_get_last_line_of_output(command));
     2880    paranoid_free(command);
     2881    log_msg(4, "Partition list for %s: %s", dsf, partition_list);
     2882    if (!strlen(partition_list)) {
     2883        /* There were no partitions on the disk */
     2884        log_msg(4, "Cannot find any partitions on device special file %s", dsf);
     2885        return (-2);
     2886    }
     2887
     2888    /* Fill the partition list */
     2889    i = 0;
     2890    lastpos = 0;
     2891    while ((token = mr_strtok(partition_list, token_chars, &lastpos)) != NULL) {
     2892        log_msg (5, "Found partition: %s", token);
     2893        strcpy(partitions[i++], token);
     2894        mr_free(token);
     2895    }
     2896    paranoid_free(partition_list);
     2897 
     2898    /********
     2899     * At this point, we have a list of all of the partitions on the dsf. Now try to
     2900     * see which partitions have a file system on them.
     2901     *
     2902     * Loop through each partition on the disk and:
     2903     *
     2904     * - If the partition is swap, it ignores it.
     2905     *
     2906     * - If the partition is mounted (e.g. /dev/sda1 is mounted on /boot), it adds an entry
     2907     *  to the linked list, copies to it the device name and mount point, and sets check == 1.
     2908     *
     2909     * - If the partition is part of a Volume Group that has Logical Volumes mounted, it adds
     2910     *  an entry to the linked list for each mounted Logical Volume in that Volume Group, copying
     2911     *  to it the device name and mount point, and sets check == 1. Note that if the Volume Group
     2912     *  contains more than one disk, it will still add the entry even if the Logical Volume's
     2913     *  extents are not on the dsf that was passed in to the function. For example, Volume Group
     2914     *  VolGroup00 contains the disks /dev/sda1 and /dev/sdb1, and the Logical Volumes LogVol01,
     2915     *  which is mounted on /var and has all of its extents on /dev/sda1, and LogVol02, which is
     2916     *  mounted as /usr and has all of its extents on /dev/sdb1. If you pass /dev/sda into the
     2917     *  function, both /var and /usr will be archived even though /usr is actually on/dev/sdb.
     2918     *
     2919     * - If the partition is part of a Volume Group that has Logical Volumes used in a mounted
     2920     *  software raid device, it adds an entry to the linked list, copies to it the software raid
     2921     *  device name and mount point, and sets check == 1.
     2922     *
     2923     * - If the partition is part of a mounted software raid device, it adds an entry to the linked
     2924     *  list, copies to it the software raid device name and mount point, and sets check == 1.
     2925     *
     2926     ********/
     2927    for (i=0; strlen(partitions[i]); i++) {
     2928        log_msg(4, "Processing partition: %s", partitions[i]);
     2929        /* See if it's swap. If it is, ignore it. */
     2930        mr_asprintf(&command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'",
     2931          dsf, partitions[i]);
     2932        log_msg(4, "  Running: %s", command);
     2933        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     2934        paranoid_free(command);
     2935        log_msg(4, "  Return value: %s", tmp);
     2936        c = strlen(tmp);
     2937        paranoid_free(tmp);
     2938        if (c) {
     2939            log_msg(4, "It's swap. Ignoring partition %s", partitions[i]);
     2940            continue;
     2941        }
     2942        /* It's not swap. See if we can find the mount point from the mount command. */
     2943        mr_asprintf(&command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
     2944        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     2945        paranoid_free(command);
     2946        if (strlen(tmp)) {
     2947            log_msg(4, "  %s is mounted: %s", partitions[i], tmp);
     2948            if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) {
     2949                log_msg (4, "Can't find mount point %s in mounted file systems list", tmp);
     2950                paranoid_free(tmp);
     2951                return (1);
     2952            }
     2953            DSFptr->check = 1;
     2954            paranoid_free(tmp);
     2955            continue;
     2956        }
     2957        paranoid_free(tmp);
     2958        /* It's not swap and it's not mounted. See if it's LVM */
     2959        log_msg(4, "  It's not mounted. Checking to see if it's LVM...");
     2960        /* Get the partition ID; 8e for LVM */
     2961        mr_asprintf(&command, "parted2fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]);
     2962        log_msg(4, "  Running: %s", command);
     2963        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     2964        paranoid_free(command);
     2965        if (strlen(tmp)) {
     2966            log_msg(4, "  Partition ID: %s", tmp);
     2967            if (!strcasecmp(tmp, "8e")) {
     2968                /* It's LVM: Find the VG it's in */
     2969                log_msg(4, "  It's LVM: Find the VG it's in...");
     2970                mr_asprintf(&command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
     2971                log_msg(4, "  Running: %s", command);
     2972                strcpy(VG, call_program_and_get_last_line_of_output(command));
     2973                paranoid_free(command);
     2974                log_msg(4, "  Volume Group: %s", VG);
     2975                if (strlen(VG)) {
     2976                    /* Found the Volume Group. Now find all of the VG's mount points */
     2977                    log_msg(4, "  Found the Volume Group. Now find all of the VG's mount points");
     2978                    mr_asprintf(&command, "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", VG, VG);
     2979                    log_msg(4, "  Running: %s", command);
     2980                    mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
     2981                    paranoid_free(command);
     2982                    log_msg(4, "  VG %s mount_list: %s", VG, mount_list);
     2983                    lastpos = 0;
     2984                    while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
     2985                        log_msg (5, "mount point token: %s", token);
     2986                        if ((DSFptr = find_mount_point_in_list(token)) == NULL) {
     2987                            log_msg (4, "Can't find mount point %s in mounted file systems list", token);
     2988                            paranoid_free(tmp);
     2989                            mr_free(token);
     2990                            return (1);
     2991                        }
     2992                        DSFptr->check = 1;
     2993                        mr_free(token);
     2994                    }
     2995                    /********
     2996                     * Now we want to see if there are any software raid devices using
     2997                     * any of the Logical Volumes on the Volume Group.
     2998                     *******/
     2999                    paranoid_free(mount_list);
     3000                    mr_asprintf(&command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
     3001                    log_msg (5, "Running: %s", command);
     3002                    mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
     3003                    paranoid_free(command);
     3004                    log_msg(4, "  Software raid device list: %s", mount_list);
     3005                    lastpos = 0;
     3006                    while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
     3007                        mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
     3008                        log_msg (5, "Running: %s", command);
     3009                        paranoid_free(tmp);
     3010                        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     3011                        paranoid_free(command);
     3012                        log_msg(4, "Number of Software raid device: %s", tmp);
     3013                        if (atoi(tmp)) {
     3014                            /* This device is on our disk */
     3015                            if ((DSFptr = find_device_in_list(token)) == NULL) {
     3016                                log_msg (4, "Can't find device %s in mounted file systems list", token);
     3017                                paranoid_free(tmp);
     3018                                mr_free(token);
     3019                                return (1);
     3020                            }
     3021                            DSFptr->check = 1;
     3022                        }
     3023                    }
     3024                    mr_free(token);
     3025                    paranoid_free(mount_list);
     3026                } else {
     3027                    log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
     3028                    paranoid_free(tmp);
     3029                    return (1);
     3030                }
     3031                paranoid_free(tmp);
     3032                continue;
     3033            }
     3034        } else {
     3035            log_msg (4, "Error finding partition type for the partition %s", partitions[i]);
     3036        }
     3037        paranoid_free(tmp);
     3038        /********
     3039         * It's not swap, mounted, or LVM. See if it's used in a software raid device.
     3040         ********/
     3041        log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device.");
     3042        mr_asprintf(&command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
     3043        log_msg(4, "  Running: %s", command);
     3044        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     3045        paranoid_free(command);
     3046        if (!strlen(tmp)) {
     3047            log_msg(4, "  Partition %s is not used in a non-LVM software raid device", partitions[i]);
     3048            paranoid_free(tmp);
     3049            continue;
     3050        }
     3051        log_msg (5, "  UUID: %s", tmp);
     3052        /* Get the Software raid device list */
     3053        mr_asprintf(&command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
     3054        log_msg (5, "  Running: %s", command);
     3055        mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
     3056        paranoid_free(command);
     3057        log_msg(4, "  Software raid device list: %s", mount_list);
     3058        /* Loop through the software raid device list to see if we can find the partition */
     3059        lastpos = 0;
     3060        while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
     3061            mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
     3062            log_msg(4, "  Running: %s", command);
     3063            paranoid_free(tmp);
     3064            mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     3065            paranoid_free(command);
     3066            if (!atoi(tmp)) {
     3067                log_msg (4,"  Didn't find partition %s in software raid device %s", partitions[i], token);
     3068            } else {
     3069                if ((DSFptr = find_device_in_list(token)) == NULL) {
     3070                    log_msg (4, "Can't find device %s in mounted file systems list", token);
     3071                    paranoid_free(tmp);
     3072                    mr_free(token);
     3073                    return (1);
     3074                }
     3075                DSFptr->check = 1;
     3076                break;
     3077            }
     3078            mr_free(token);
     3079        }
     3080        paranoid_free(tmp);
     3081    }
     3082    paranoid_free(partition_list);
     3083    paranoid_free(mount_list);
     3084
     3085    /* Determine how much memory to allocate for included_dsf_list and excluded_dsf_list */
     3086    i = 0;
     3087    DSFptr= DSF_Head;
     3088    while (DSFptr != NULL) {
     3089        i += strlen(DSFptr->mount_point) + 1;
     3090        DSFptr = DSFptr->next;
     3091    }
     3092    log_msg (5, "i: %d", i);
     3093    if ((*included_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {
     3094        fatal_error ("Cannot allocate memory");
     3095    }
     3096    if ((*excluded_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {
     3097        fatal_error ("Cannot allocate memory");
     3098    }
     3099    DSFptr= DSF_Head;
     3100    while (DSFptr != NULL) {
     3101        if (DSFptr->check) {
     3102            log_msg (5, "%s is mounted on %s and is on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf);
     3103            strcat(*included_dsf_list, DSFptr->mount_point);
     3104            strcat(*included_dsf_list, " ");
     3105        } else {
     3106            log_msg (4, "%s is mounted on %s and is NOT on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf);
     3107            strcat(*excluded_dsf_list, DSFptr->mount_point);
     3108            strcat(*excluded_dsf_list, " ");
     3109        }
     3110        DSFptr = DSFptr->next;
     3111    }
     3112    log_msg (5, "included_dsf_list: %s", *included_dsf_list);
     3113    log_msg (5, "excluded_dsf_list: %s", *excluded_dsf_list);
     3114    return (0);
     3115}
     3116
     3117
     3118/* Update the bkpinfo structure for exclude & include paths
     3119 * in order to handle correctly paths corresponding to devices */
     3120void mr_make_devlist_from_pathlist(char *pathlist, char mode) {
     3121
     3122char *token = NULL;
     3123int lastpos = 0;
     3124char *mounted_on_dsf = NULL;
     3125char *not_mounted_on_dsf = NULL;
     3126char token_chars[] =" \t\r\f\a\0";
     3127
     3128while ((token = mr_strtok(pathlist, token_chars, &lastpos)) != NULL) {
     3129    switch (get_dsf_mount_list(token, &mounted_on_dsf, &not_mounted_on_dsf)) {
     3130    case 1:
     3131        if (mode == 'E') {
     3132            log_msg(1, "WARNING ! %s doesn't exist in -E option", token);
     3133        } else {
     3134            fatal_error("Error processing -I option");
     3135        }
     3136        break;
     3137    /* Everything is OK; proceed to archive data */
     3138    case 0:
     3139        if (mode == 'E') {
     3140            if (strlen(mounted_on_dsf)) {
     3141                log_to_screen("Excluding the following file systems on %s:\n", token);
     3142                log_to_screen("  %s\n", mounted_on_dsf);
     3143                log_msg (5, "Adding to bkpinfo->exclude_paths due to -E option: %s", mounted_on_dsf);
     3144                strcat(bkpinfo->exclude_paths, mounted_on_dsf);
     3145                strcat(bkpinfo->exclude_paths, " ");
     3146                mr_strcat(bkpinfo->exclude_devs, " %s ", token);
     3147            } else {
     3148                log_to_screen("Archiving only the following file systems on %s:\n", token);
     3149                log_to_screen("  %s\n", mounted_on_dsf);
     3150                strcpy(bkpinfo->include_paths, "/");
     3151                if (strlen(not_mounted_on_dsf)) {
     3152                    log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf);
     3153                    log_to_screen("Not archiving the following file systems:\n");
     3154                    log_to_screen("  %s\n", not_mounted_on_dsf);
     3155                    strcat(bkpinfo->exclude_paths, not_mounted_on_dsf);
     3156                    strcat(bkpinfo->exclude_paths, "");
     3157                }
     3158            }
     3159        }
     3160        break;
     3161    /* It's a dsf but not a whole disk dsf */
     3162    case -2:
     3163        log_to_screen("Could %s be a partition instead of a whole disk device special file?\nIgnored.", token);
     3164        break;
     3165    /* A device special file was not passed in. Process it as a path. */
     3166    case -1:
     3167        if (mode == 'E') {
     3168            strcat(bkpinfo->exclude_paths, token);
     3169            strcat(bkpinfo->exclude_paths, " ");
     3170        } else {
     3171            strcat(bkpinfo->include_paths, token);
     3172            strcat(bkpinfo->include_paths, " ");
     3173        }
     3174        break;
     3175    }
     3176    mr_free(token);
     3177
     3178    if (bkpinfo->include_paths != NULL) {
     3179        log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
     3180    }
     3181    if (bkpinfo->exclude_paths != NULL) {
     3182        log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths);
     3183    }
     3184    if (bkpinfo->exclude_devs != NULL) {
     3185        log_msg(1, "exclude_devs is now '%s'", bkpinfo->exclude_devs);
     3186    }
     3187}
     3188}
     3189
     3190
     3191
     3192
    26423193/* @} - end of deviceGroup */
  • branches/2.2.9/mondo/src/common/libmondo-tools.c

    r2380 r2424  
    840840    bkpinfo->include_paths[0] = '\0';
    841841    bkpinfo->exclude_paths[0] = '\0';
     842    bkpinfo->exclude_devs = NULL;
    842843    bkpinfo->restore_path[0] = '\0';
    843844    bkpinfo->call_before_iso[0] = '\0';
  • branches/2.2.9/mondo/src/common/mondostructures.h

    r2380 r2424  
    523523   */
    524524    char exclude_paths[MAX_STR_LEN*4];
     525
     526  /**
     527   * Devices to NOT back up.
     528   * Multiple devices should be separated by spaces.
     529   */
     530    char *exclude_devs;
    525531
    526532  /**
  • branches/2.2.9/mondo/src/common/newt-specific.c

    r2397 r2424  
    447447        mr_free(bkpinfo->netfs_user);
    448448        mr_free(bkpinfo->netfs_proto);
     449        mr_free(bkpinfo->exclude_devs);
    449450
    450451        /* Then free the structure */
Note: See TracChangeset for help on using the changeset viewer.