Changeset 2428 in MondoRescue
- Timestamp:
- Sep 28, 2009, 2:29:12 AM (15 years ago)
- Location:
- branches/2.2.10
- Files:
-
- 8 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mindi/analyze-my-lvm
r2351 r2428 177 177 178 178 ListLvmDrivesAndPartitions() { 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 183 186 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 189 191 } 190 192 -
branches/2.2.10/mindi/mindi
r2415 r2428 57 57 PCMCIA_MODS="pcmcia_core ds yenta_socket" 58 58 USB_MODS="usb-storage usb-ohci usb-uhci usbcore usb_storage input hid uhci_hcd ehci_hcd uhci-hcd ehci-hcd ohci-hcd ohci_hcd usbkbd usbhid keybdev mousedev libusual scsi_mod ff-memless" 59 NET_MODS=" sunrpc nfs nfs_acl lockd fscache loop mii 3c59x e100 bcm5700 bnx2e1000 e1000e igb eepro100 ne2k-pci tg3 libphy pcnet32 8139cp 8139too 8390 forcedeth vmxnet vmnet exportfs fuse"59 NET_MODS="auth_rpcgss sunrpc nfs nfs_acl lockd fscache loop mii 3c59x e100 bcm5700 bnx2 bnx2x e1000 e1000e igb eepro100 ne2k-pci tg3 libphy pcnet32 8139cp 8139too 8390 forcedeth vmxnet vmnet exportfs fuse" 60 60 CDROM_MODS="$TAPE_MODS $IDE_MODS $USB_MODS $PCMCIA_MODS $SCSI_MODS $NET_MODS af_packet cdrom isocd isofs inflate_fs nls_iso8859-1 nls_base nls_cp437 nls_utf8 sg sr_mod zlib_inflate iso9660" 61 61 # Those modules will only go on the backup media, not the boot media. … … 979 979 LVM="false" 980 980 fi 981 all_partitions=`cat $MINDI_TMP/lvm.res | grep -F ">>>" | cut -d' ' -f2- 32`981 all_partitions=`cat $MINDI_TMP/lvm.res | grep -F ">>>" | cut -d' ' -f2-` 982 982 fi 983 983 all_partitions="$all_partitions `ListAllPartitions 2> /dev/null`" … … 2744 2744 LAST_FILELIST_NUMBER=${12} 2745 2745 ESTIMATED_TOTAL_NOOF_SLICES=${13} 2746 EXCLUDE_DEVS="${14}"2746 export EXCLUDE_DEVS="${14}" 2747 2747 USE_COMP="${15}" 2748 2748 USE_LILO="${16}" -
branches/2.2.10/mindi/rootfs/etc/passwd
r30 r2428 16 16 guest:x:405:100:guest:/dev/null:/dev/null 17 17 nobody:x:65534:100:nobody:/dev/null: 18 alfa::1001:0:alfa:/alfa: -
branches/2.2.10/mondo/src/common/libmondo-archive.c
r2421 r2428 517 517 char *cd_recovery_sz = NULL; 518 518 char *tape_size_sz = NULL; 519 char *devs_to_exclude = NULL;520 519 char *use_lilo_sz = NULL; /* BCO: shared between LILO/ELILO */ 521 520 char *value = NULL; … … 536 535 537 536 assert(bkpinfo != NULL); 538 if (bkpinfo->exclude_paths) {539 mr_asprintf(tmp, "echo '%s' | tr -s ' ' '\n' | grep -E '^/dev/.*$' | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'", bkpinfo->exclude_paths);540 devs_to_exclude = call_program_and_get_last_line_of_output(tmp);541 mr_free(tmp);542 543 log_msg(2, "devs_to_exclude = '%s'", devs_to_exclude);544 }545 537 546 538 mr_asprintf(tmp, "%s/filelist.full", bkpinfo->tmpdir); … … 815 807 last_filelist_number, // parameter #12 (STRING) 816 808 estimated_total_noof_slices, // parameter #13 (INT) 817 ( devs_to_exclude == NULL) ? "\"\"" : devs_to_exclude, // parameter #14809 (bkpinfo->exclude_devs == NULL) ? "\"\"" : bkpinfo->exclude_devs, // parameter #14 818 810 use_comp_sz, // parameter #15 819 811 use_lilo_sz, // parameter #16 … … 826 818 827 819 mr_free(tmp2); 828 mr_free(devs_to_exclude);829 820 mr_free(last_filelist_number); 830 821 mr_free(tape_device); -
branches/2.2.10/mondo/src/common/libmondo-cli.c
r2405 r2428 38 38 39 39 extern void setup_tmpdir(char *path); 40 void mr_make_devlist_from_pathlist(char *pathlist, char mode); 40 41 extern double g_kernel_version; 41 42 extern int g_current_media_number; 42 43 extern pid_t g_main_pid; 43 44 extern 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 (const char *mount_point);59 static MOUNTED_FS_STRUCT *find_device_in_list (const char *device);60 45 61 46 /* Do we use extended attributes and acl ? … … 161 146 162 147 /** 163 * Frees the memory for all of the structures on the linked list of164 * all of the non-NETFS mounted file systems.165 */166 static void free_mounted_fs_list (void) {167 MOUNTED_FS_STRUCT *DSFptr = NULL;168 MOUNTED_FS_STRUCT *DSFnext = NULL;169 170 DSFptr = DSF_Head;171 while (DSFptr != NULL) {172 DSFnext = DSFptr->next;173 mr_free(DSFptr);174 DSFptr = DSFnext;175 }176 DSF_Head = NULL;177 DSF_Tail = NULL;178 }179 180 /**181 * Creates a singly linked list of all of the non-NETFS mounted file systems.182 * @param DSFptr A pointer to the structure MOUNTED_FS_STRUCT used to hold183 * the list of mounted file systems.184 * @return None.185 */186 static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr)187 {188 assert (DSFptr);189 if (DSF_Head == NULL) {190 DSF_Head = DSFptr;191 } else {192 DSF_Tail->next = DSFptr;193 }194 DSFptr->next = NULL;195 DSF_Tail = DSFptr;196 }197 198 /**199 * Find the structure, in the singly linked list of all of the non-NETFS200 * mounted file systems, that contains the specified device.201 * @param device The device to find202 * @return NULL if it didn't find the device, a pointer to the203 * structure if it did.204 */205 static MOUNTED_FS_STRUCT *find_device_in_list (const char *device)206 {207 MOUNTED_FS_STRUCT *DSFptr = NULL;208 209 DSFptr = DSF_Head;210 while (DSFptr != NULL) {211 if (!strcmp(DSFptr->device, device)) {212 break;213 }214 DSFptr = DSFptr->next;215 }216 return (DSFptr);217 }218 219 /**220 * Find the structure, in the singly linked list of all of the non-NETFS221 * mounted file systems, that contains the specified mount point.222 * @param mount_point The mount point to find223 * @return NULL is it didn't find the mount point, a pointer to the224 * structure if it did.225 */226 static MOUNTED_FS_STRUCT *find_mount_point_in_list (const char *mount_point)227 {228 MOUNTED_FS_STRUCT *DSFptr = NULL;229 230 DSFptr = DSF_Head;231 while (DSFptr != NULL) {232 if (!strcmp(DSFptr->mount_point, mount_point)) {233 break;234 }235 DSFptr = DSFptr->next;236 }237 return (DSFptr);238 }239 240 /**241 * Creates a linked list of all of the non-NETFS mounted file systems.242 * We use a linked list because we don't know how many mounted file243 * there are (and there can be a lot).244 * @return 0 on success and greated than 0 on failure.245 */246 static int create_list_of_non_NETFS_mounted_file_systems (void)247 {248 int i = 0;249 int mount_cnt = 0;250 char *mounted_file_system = NULL;251 char *command = NULL;252 char *token = NULL;253 char token_chars[] =" :\t\r\f\a\0";254 MOUNTED_FS_STRUCT *DSFptr = NULL;255 256 free_mounted_fs_list();257 /********258 * Find the number of mounted file system entries and their respective mount points.259 * I can't return all of the entries as one string because it's length can be longer260 * than MAX_STR_LEN which is used in call_program_and_get_last_line_of_output().261 * So start looping and get the number of mounted file systems and query them one by one.262 ********/263 /* Get the number of mounted file systems ((those that start with "/dev/" */264 mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");265 log_msg(5, "Running: %s", command);266 mounted_file_system = call_program_and_get_last_line_of_output(command);267 mr_free(command);268 269 mount_cnt = atoi(mounted_file_system);270 log_msg (5, "mount_cnt: %d", mount_cnt);271 mr_free(mounted_file_system);272 273 for (i=mount_cnt; i > 0; i--) {274 mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);275 log_msg(5, "Running: %s", command);276 mounted_file_system = call_program_and_get_last_line_of_output(command);277 mr_free(command);278 279 log_msg (5, "mounted_file_system: %s", mounted_file_system);280 if ((token = strtok(mounted_file_system, token_chars)) == NULL) {281 log_msg (4, "Could not get the list of mounted file systems");282 mr_free(mounted_file_system);283 mr_free(token);284 return (1);285 }286 if (token) {287 log_msg (5, "token: %s", token);288 }289 while (token != NULL) {290 log_msg (5, "token: %s", token);291 if ((DSFptr = (MOUNTED_FS_STRUCT *) calloc(1, sizeof(MOUNTED_FS_STRUCT))) == NULL) {292 fatal_error ("Cannot allocate memory");293 }294 add_mounted_fs_struct(DSFptr);295 strcpy(DSFptr->device, token);296 mr_free(token);297 if ((token = strtok(NULL, token_chars)) == NULL) {298 log_msg (5, "Ran out of entries on the mounted file systems list");299 mr_free(mounted_file_system);300 mr_free(token);301 return (1);302 }303 log_msg (5, "token: %s", token);304 strcpy(DSFptr->mount_point, token);305 mr_free(token);306 token = strtok(NULL, token_chars);307 }308 mr_free(mounted_file_system);309 }310 /********311 * DSFptr = DSF_Head;312 * while (DSFptr != NULL) {313 * printf ("Dev: %s MP: %s Check: %d\n", DSFptr->device, DSFptr->mount_point, DSFptr->check);314 * DSFptr = DSFptr->next;315 * }316 ********/317 return (0);318 }319 320 /**321 * Given a whole disk device special file, determine which mounted file systems322 * are on the dsf's partitions and which mounted file systems are not.323 * @param dsf The whole disk device special file.324 * @param included_dsf_list A char pointer used to hold the list of mount points325 * that are on the dsf. Memory for the array will be allocated within the function.326 * @param excluded_dsf_list A char pointer used to hold the list of mount points327 * that are not on the dsf. Memory for the array will be allocated within the function.328 * @return 0 on success, -1 if no device special file was passed in, -2 if a device329 * special file was passed in but it has no partitions on it, or 1 on failure330 */331 static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list) {332 int i = 0;333 int c = 0;334 int lastpos = 0;335 char *VG = NULL;336 char *tmp = NULL;337 char *command = NULL;338 char *partition_list = NULL;339 char partitions[64][MAX_STR_LEN];340 char *mount_list = NULL;341 char *token = NULL;342 char token_chars[] =" \t\r\f\a\0";343 MOUNTED_FS_STRUCT *DSFptr = NULL;344 345 memset((char *)partitions, 0, sizeof(partitions));346 347 log_msg(5, "dsf: %s", dsf);348 349 /********350 * See if a device special file was passed in (i.e. it must start with /dev/351 ********/352 if (strncmp(dsf, "/dev/", 5)) {353 log_msg (5, "%s does not start with /dev/ and (probably) is not a device special file", dsf);354 return (-1);355 }356 log_msg(5, " %s looks like a device special file", dsf);357 /* Verify that the dsf exists */358 mr_asprintf(command, "ls -al %s 2>/dev/null | wc -l", dsf);359 log_msg(5, " Executing: %s", command);360 tmp = call_program_and_get_last_line_of_output(command);361 mr_free(command);362 363 log_msg(5, " Return value: %s", tmp);364 c = atoi(tmp);365 mr_free(tmp);366 367 if (!c) {368 log_to_screen("Cannot find device special file %s", dsf);369 return (1);370 }371 log_msg(5, " %s device special file exists", dsf);372 373 /* Get a list of the mounted file systems */374 if (create_list_of_non_NETFS_mounted_file_systems()) {375 log_to_screen ("Could not get the list of mounted file systems");376 return (1);377 }378 log_msg (5, "Processing dsf: %s", dsf);379 /********380 * Get a list of the dsf's partitions. There could be no partitions on the disk381 * or a dsf of a partition was passed in (e.g. /dev/sda1 instead of /dev/sda).382 * Either way, it's an error.383 ********/384 mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);385 log_msg(4, "Executing: %s", command);386 partition_list = call_program_and_get_last_line_of_output(command);387 mr_free(command);388 log_msg(4, "Partition list for %s: %s", dsf, partition_list);389 if (!strlen(partition_list)) {390 /* There were no partitions on the disk */391 log_msg(4, "Cannot find any partitions on device special file %s", dsf);392 return (-2);393 }394 395 /* Fill the partition list */396 i = 0;397 lastpos = 0;398 while ((token = mr_strtok(partition_list, token_chars, &lastpos)) != NULL) {399 log_msg (5, "Found partition: %s", token);400 strcpy(partitions[i++], token);401 mr_free(token);402 }403 mr_free(partition_list);404 405 /********406 * At this point, we have a list of all of the partitions on the dsf. Now try to407 * see which partitions have a file system on them.408 *409 * Loop through each partition on the disk and:410 *411 * - If the partition is swap, it ignores it.412 *413 * - If the partition is mounted (e.g. /dev/sda1 is mounted on /boot), it adds an entry414 * to the linked list, copies to it the device name and mount point, and sets check == 1.415 *416 * - If the partition is part of a Volume Group that has Logical Volumes mounted, it adds417 * an entry to the linked list for each mounted Logical Volume in that Volume Group, copying418 * to it the device name and mount point, and sets check == 1. Note that if the Volume Group419 * contains more than one disk, it will still add the entry even if the Logical Volume's420 * extents are not on the dsf that was passed in to the function. For example, Volume Group421 * VolGroup00 contains the disks /dev/sda1 and /dev/sdb1, and the Logical Volumes LogVol01,422 * which is mounted on /var and has all of its extents on /dev/sda1, and LogVol02, which is423 * mounted as /usr and has all of its extents on /dev/sdb1. If you pass /dev/sda into the424 * function, both /var and /usr will be archived even though /usr is actually on/dev/sdb.425 *426 * - If the partition is part of a Volume Group that has Logical Volumes used in a mounted427 * software raid device, it adds an entry to the linked list, copies to it the software raid428 * device name and mount point, and sets check == 1.429 *430 * - If the partition is part of a mounted software raid device, it adds an entry to the linked431 * list, copies to it the software raid device name and mount point, and sets check == 1.432 *433 ********/434 for (i=0; strlen(partitions[i]); i++) {435 log_msg(4, "Processing partition: %s", partitions[i]);436 /* See if it's swap. If it is, ignore it. */437 mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'",438 dsf, partitions[i]);439 log_msg(4, " Running: %s", command);440 tmp = call_program_and_get_last_line_of_output(command);441 mr_free(command);442 443 log_msg(4, " Return value: %s", tmp);444 c = strlen(tmp);445 mr_free(tmp);446 447 if (c) {448 log_msg(4, "It's swap. Ignoring partition %s", partitions[i]);449 continue;450 }451 /* It's not swap. See if we can find the mount point from the mount command. */452 mr_asprintf(command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);453 tmp = call_program_and_get_last_line_of_output(command);454 mr_free(command);455 456 if (strlen(tmp)) {457 log_msg(4, " %s is mounted: %s", partitions[i], tmp);458 if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) {459 log_msg (4, "Can't find mount point %s in mounted file systems list", tmp);460 mr_free(tmp);461 return (1);462 }463 DSFptr->check = 1;464 mr_free(tmp);465 continue;466 }467 mr_free(tmp);468 /* It's not swap and it's not mounted. See if it's LVM */469 log_msg(4, " It's not mounted. Checking to see if it's LVM...");470 /* Get the partition ID; 8e for LVM */471 mr_asprintf(command, "parted2fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]);472 log_msg(4, " Running: %s", command);473 tmp = call_program_and_get_last_line_of_output(command);474 mr_free(command);475 if (strlen(tmp)) {476 log_msg(4, " Partition ID: %s", tmp);477 if (!strcasecmp(tmp, "8e")) {478 /* It's LVM: Find the VG it's in */479 log_msg(4, " It's LVM: Find the VG it's in...");480 mr_asprintf(command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);481 log_msg(4, " Running: %s", command);482 VG = call_program_and_get_last_line_of_output(command);483 mr_free(command);484 log_msg(4, " Volume Group: %s", VG);485 if (strlen(VG)) {486 /* Found the Volume Group. Now find all of the VG's mount points */487 log_msg(4, " Found the Volume Group. Now find all of the VG's mount points");488 mr_asprintf(command, "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", VG, VG);489 log_msg(4, " Running: %s", command);490 mount_list = call_program_and_get_last_line_of_output(command);491 mr_free(command);492 493 log_msg(4, " VG %s mount_list: %s", VG, mount_list);494 lastpos = 0;495 while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {496 log_msg (5, "mount point token: %s", token);497 if ((DSFptr = find_mount_point_in_list(token)) == NULL) {498 log_msg (4, "Can't find mount point %s in mounted file systems list", token);499 mr_free(tmp);500 mr_free(token);501 mr_free(VG);502 return (1);503 }504 DSFptr->check = 1;505 mr_free(token);506 }507 /********508 * Now we want to see if there are any software raid devices using509 * any of the Logical Volumes on the Volume Group.510 *******/511 mr_free(mount_list);512 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");513 log_msg (5, "Running: %s", command);514 mount_list = call_program_and_get_last_line_of_output(command);515 mr_free(command);516 log_msg(4, " Software raid device list: %s", mount_list);517 lastpos = 0;518 while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {519 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);520 log_msg (5, "Running: %s", command);521 mr_free(tmp);522 523 tmp = call_program_and_get_last_line_of_output(command);524 mr_free(command);525 526 log_msg(4, "Number of Software raid device: %s", tmp);527 if (atoi(tmp)) {528 /* This device is on our disk */529 if ((DSFptr = find_device_in_list(token)) == NULL) {530 log_msg (4, "Can't find device %s in mounted file systems list", token);531 mr_free(tmp);532 mr_free(token);533 mr_free(VG);534 return (1);535 }536 DSFptr->check = 1;537 }538 mr_free(token);539 }540 mr_free(mount_list);541 } else {542 log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);543 mr_free(tmp);544 mr_free(VG);545 return (1);546 }547 mr_free(tmp);548 mr_free(VG);549 continue;550 }551 } else {552 log_msg (4, "Error finding partition type for the partition %s", partitions[i]);553 }554 mr_free(tmp);555 /********556 * It's not swap, mounted, or LVM. See if it's used in a software raid device.557 ********/558 log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device.");559 mr_asprintf(command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);560 log_msg(4, " Running: %s", command);561 tmp = call_program_and_get_last_line_of_output(command);562 mr_free(command);563 if (!strlen(tmp)) {564 log_msg(4, " Partition %s is not used in a non-LVM software raid device", partitions[i]);565 mr_free(tmp);566 continue;567 }568 log_msg (5, " UUID: %s", tmp);569 /* Get the Software raid device list */570 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");571 log_msg (5, " Running: %s", command);572 mount_list = call_program_and_get_last_line_of_output(command);573 mr_free(command);574 log_msg(4, " Software raid device list: %s", mount_list);575 /* Loop through the software raid device list to see if we can find the partition */576 lastpos = 0;577 while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {578 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);579 log_msg(4, " Running: %s", command);580 mr_free(tmp);581 tmp = call_program_and_get_last_line_of_output(command);582 mr_free(command);583 if (!atoi(tmp)) {584 log_msg (4," Didn't find partition %s in software raid device %s", partitions[i], token);585 } else {586 if ((DSFptr = find_device_in_list(token)) == NULL) {587 log_msg (4, "Can't find device %s in mounted file systems list", token);588 mr_free(tmp);589 mr_free(token);590 return (1);591 }592 DSFptr->check = 1;593 break;594 }595 mr_free(token);596 }597 mr_free(tmp);598 }599 mr_free(partition_list);600 mr_free(mount_list);601 602 /* Determine how much memory to allocate for included_dsf_list and excluded_dsf_list */603 i = 0;604 DSFptr= DSF_Head;605 while (DSFptr != NULL) {606 i += strlen(DSFptr->mount_point) + 1;607 DSFptr = DSFptr->next;608 }609 log_msg (5, "i: %d", i);610 if ((*included_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {611 fatal_error ("Cannot allocate memory");612 }613 if ((*excluded_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {614 fatal_error ("Cannot allocate memory");615 }616 DSFptr= DSF_Head;617 while (DSFptr != NULL) {618 if (DSFptr->check) {619 log_msg (5, "%s is mounted on %s and is on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf);620 strcat(*included_dsf_list, DSFptr->mount_point);621 strcat(*included_dsf_list, " ");622 } else {623 log_msg (4, "%s is mounted on %s and is NOT on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf);624 strcat(*excluded_dsf_list, DSFptr->mount_point);625 strcat(*excluded_dsf_list, " ");626 }627 DSFptr = DSFptr->next;628 }629 log_msg (5, "included_dsf_list: %s", *included_dsf_list);630 log_msg (5, "excluded_dsf_list: %s", *excluded_dsf_list);631 return (0);632 }633 634 635 /**636 148 * Process mondoarchive's command-line switches. 637 149 * @param bkpinfo The backup information structure to populate. … … 659 171 char *p = NULL; 660 172 char *q = NULL; 661 char *token = NULL;662 char *mounted_on_dsf = NULL;663 char *not_mounted_on_dsf = NULL;664 char token_chars[] =" \t\r\f\a\0";665 173 666 174 long itbs = 0L; … … 777 285 } 778 286 mr_free(tmp1); 779 while ((token = mr_strtok(flag_val['I'], token_chars, &lastpos)) != NULL) { 780 switch (get_dsf_mount_list(token, &mounted_on_dsf, ¬_mounted_on_dsf)) { 781 /* It's a dsf but not a whole disk dsf */ 782 case -2: 783 log_to_screen("Could %s be a partition instead of a whole disk device special file?\n Ignored.", token); 784 break; 785 /* Fatal error; exit */ 786 case 1: 787 mr_free(token); 788 fatal_error("Error processing -I option"); 789 /* Everything is OK; process to archive data */ 790 case 0: 791 log_to_screen("Archiving only the following file systems on %s:\n", token); 792 log_to_screen(" %s\n", mounted_on_dsf); 793 mr_asprintf(p, "/"); 794 mr_free(bkpinfo->include_paths); 795 bkpinfo->include_paths = p; 796 if (strlen(not_mounted_on_dsf)) { 797 log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf); 798 log_to_screen("Not archiving the following file systems:\n"); 799 log_to_screen(" %s\n", not_mounted_on_dsf); 800 mr_strcat(bkpinfo->exclude_paths, " %s ", not_mounted_on_dsf); 801 } 802 break; 803 /* A device special file was not passed in. Process it as a path. */ 804 case -1: 805 mr_strcat(bkpinfo->include_paths, " %s ", token); 806 break; 807 } 808 mr_free(token); 809 } 810 if (bkpinfo->include_paths != NULL) { 811 mr_strip_spaces(bkpinfo->include_paths); 812 log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths); 813 } 814 if (bkpinfo->exclude_paths != NULL) { 815 mr_strip_spaces(bkpinfo->exclude_paths); 816 log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths); 817 } 287 mr_make_devlist_from_pathlist(flag_val['I'], 'I'); 818 288 log_msg(4, "Finished with the -I option"); 819 289 } … … 978 448 } 979 449 /* test for protocol */ 980 p = str chr(bkpinfo->netfs_mount, ':');450 p = strstr(bkpinfo->netfs_mount, "://"); 981 451 if (p == NULL) { 982 /* protocol not found abort */ 983 fatal_error("No protocol specified for remote share mount. Please do man mondoarchive as syntax changed"); 452 /* protocol not found assuming NFS for compatibility */ 453 mr_asprintf(q,"nfs"); 454 455 p = strchr(bkpinfo->netfs_mount, ':'); 456 if (p == NULL) { 457 fatal_error("No protocol specified for remote share mount, nor any old NFS syntax found.\nPlease do man mondoarchive as syntax changed"); 458 } 459 /* p points on to the string server:/path */ 460 p = bkpinfo->netfs_mount; 461 984 462 } else { 985 /* Proto found. Store the 2 values */ 986 bkpinfo->netfs_proto = bkpinfo->netfs_mount; 463 /* Isolate the protocol */ 464 *p = '\0'; 465 mr_asprintf(q,"%s",bkpinfo->netfs_mount); 466 467 /* Skip proto now */ 987 468 p++; 988 if (*p != '/') {989 fatal_error("No protocol correctly specified for remote share mount. Use protocol://server:share");990 }991 469 p++; 992 if (*p != '/') {993 fatal_error("No protocol correctly specified for remote share mount. Use protocol://server:share");994 }995 470 p++; 996 /* p points on to the string server:/path */ 997 bkpinfo->netfs_mount = p; 998 999 /* new netfs mount - remove :// from proto */ 1000 /* going back to protocol */ 1001 p--; 1002 p--; 1003 p--; 1004 *p = '\0'; 1005 } 471 } 472 /* whatever done before proto is pointed to by q */ 473 bkpinfo->netfs_proto = q; 474 475 /* p points on to the string server:/path */ 476 /* Store the 2 values */ 477 bkpinfo->netfs_mount = p; 478 1006 479 /* test if we specified a user */ 1007 480 p = strchr(bkpinfo->netfs_mount, '@'); … … 1134 607 mr_free(tmp1); 1135 608 lastpos = 0; 1136 while ((token = mr_strtok(flag_val['E'], token_chars, &lastpos)) != NULL) { 1137 switch (get_dsf_mount_list(token, &mounted_on_dsf, ¬_mounted_on_dsf)) { 1138 case 1: 1139 log_msg(1, "WARNING ! a path doesn't exist in -E option"); 1140 break; 1141 /* Everything is OK; proceed to archive data */ 1142 case 0: 1143 if (strlen(mounted_on_dsf)) { 1144 log_to_screen("Excluding the following file systems on %s:\n", token); 1145 log_to_screen(" %s\n", mounted_on_dsf); 1146 log_msg (5, "Adding to bkpinfo->exclude_paths due to -E option: %s", mounted_on_dsf); 1147 mr_strcat(bkpinfo->exclude_paths, " %s ", mounted_on_dsf); 1148 } 1149 break; 1150 /* It's a dsf but not a whole disk dsf */ 1151 case -2: 1152 log_to_screen("Could %s be a partition instead of a whole disk device special file?\nIgnored.", token); 1153 break; 1154 /* A device special file was not passed in. Process it as a path. */ 1155 case -1: 1156 mr_strcat(bkpinfo->exclude_paths, " %s ", token); 1157 break; 1158 } 1159 mr_free(token); 1160 } 1161 if (bkpinfo->exclude_paths != NULL) { 1162 log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths); 1163 } 609 610 mr_make_devlist_from_pathlist(flag_val['E'], 'E'); 1164 611 log_msg(4, "Finished with the -E option"); 1165 612 } -
branches/2.2.10/mondo/src/common/libmondo-devices.c
r2421 r2428 10 10 #include "my-stuff.h" 11 11 #include "mr_mem.h" 12 #include "mr_str.h" 12 13 #include "mondostructures.h" 13 14 #include "libmondo-files-EXT.h" … … 61 62 extern struct s_bkpinfo *bkpinfo; 62 63 63 64 /* Stuff that handles the -I and -E option when a whole disk DSF is used */ 65 typedef struct mounted_fs_struct { 66 char device[MAX_STR_LEN]; /* The name of the device */ 67 char mount_point[MAX_STR_LEN]; /* The devices mount point */ 68 unsigned char check; /* 1 == included on DSF */ 69 struct mounted_fs_struct *next; 70 } MOUNTED_FS_STRUCT; 71 72 static MOUNTED_FS_STRUCT *DSF_Head = NULL; /* Points to the first entry of mounted_fs_struct list */ 73 static MOUNTED_FS_STRUCT *DSF_Tail = NULL; /* Points to the last entry of mounted_fs_struct list */ 64 74 65 75 … … 1073 1083 mr_free(incoming); 1074 1084 mr_free(device_with_tab); 1075 mr_free(device_with_space);1076 1085 paranoid_pclose(fin); 1077 1086 mr_asprintf(tmp, "%s | grep -E \"^%s\" > /dev/null 2> /dev/null", SWAPLIST_COMMAND, device_with_space); 1087 mr_free(device_with_space); 1078 1088 log_msg(4, "tmp (command) = '%s'", tmp); 1079 1089 if (!system(tmp)) { … … 1100 1110 int i = 2; 1101 1111 1102 tmp = call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate") );1112 tmp = call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate"); 1103 1113 i = atoi(tmp); 1104 1114 mr_free(tmp); … … 1390 1400 1391 1401 /* @} - end of deviceGroup */ 1392 1393 1394 /**1395 * Ask user for details of backup/restore information.1396 * Called when @c mondoarchive doesn't get any parameters.1397 * @param bkpinfo The backup information structure to fill out with the user's data.1398 * @param archiving_to_media TRUE if archiving, FALSE if restoring.1399 * @return 0, always.1400 * @bug No point of `int' return value.1401 * @ingroup archiveGroup1402 */1403 int interactively_obtain_media_parameters_from_user(bool archiving_to_media)1404 // archiving_to_media is TRUE if I'm being called by mondoarchive1405 // archiving_to_media is FALSE if I'm being called by mondorestore1406 {1407 char *tmp = NULL;1408 char *p = NULL;1409 char *mds = NULL;1410 char *sz_size = NULL;1411 char *command = NULL;1412 char *comment = NULL;1413 int i;1414 FILE *fin;1415 1416 assert(bkpinfo != NULL);1417 bkpinfo->nonbootable_backup = FALSE;1418 1419 // Tape, CD, NETFS, ...?1420 srandom(getpid());1421 bkpinfo->backup_media_type =1422 (g_restoring_live_from_cd) ? cdr :1423 which_backup_media_type(bkpinfo->restore_data);1424 if (bkpinfo->backup_media_type == none) {1425 log_to_screen("User has chosen not to backup the PC");1426 finish(1);1427 }1428 /* Why asking to remove the media with tape ?1429 if (bkpinfo->backup_media_type == tape && bkpinfo->restore_data) {1430 popup_and_OK("Please remove media from drive(s)");1431 }1432 */1433 tmp = bkptype_to_string(bkpinfo->backup_media_type);1434 log_msg(3, "media type = %s", tmp);1435 mr_free(tmp);1436 1437 bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4;1438 bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1 : 5;1439 bkpinfo->use_lzo = (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE;1440 mvaddstr_and_log_it(2, 0, " ");1441 1442 // Find device's /dev (or SCSI) entry1443 switch (bkpinfo->backup_media_type) {1444 case cdr:1445 case cdrw:1446 case dvd:1447 case usb:1448 /* Never try to eject a USB device */1449 if (bkpinfo->backup_media_type == usb) {1450 bkpinfo->please_dont_eject = TRUE;1451 }1452 if (archiving_to_media) {1453 if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) {1454 if (ask_me_yes_or_no("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) {1455 bkpinfo->manual_cd_tray = TRUE;1456 }1457 }1458 if ((bkpinfo->compression_level = which_compression_level()) == -1) {1459 log_to_screen("User has chosen not to backup the PC");1460 finish(1);1461 }1462 mds = media_descriptor_string(bkpinfo->backup_media_type);1463 mr_asprintf(comment, "What speed is your %s (re)writer?", mds);1464 mr_free(bkpinfo->media_device);1465 if (bkpinfo->backup_media_type == dvd) {1466 bkpinfo->media_device = find_dvd_device();1467 mr_asprintf(tmp, "1");1468 mr_asprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB1469 log_msg(1, "Setting to DVD defaults");1470 } else {1471 mr_asprintf(bkpinfo->media_device, "%s", VANILLA_SCSI_CDROM);1472 mr_asprintf(tmp, "4");1473 mr_asprintf(sz_size, "%d", 650);1474 log_msg(1, "Setting to CD defaults");1475 }1476 if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) {1477 p = popup_and_get_string("Speed", comment, tmp);1478 mr_free(tmp);1479 1480 if (p == NULL) {1481 log_to_screen("User has chosen not to backup the PC");1482 mr_free(comment);1483 finish(1);1484 }1485 /* tmp now has the new value given by the user */1486 tmp = p;1487 }1488 mr_free(comment);1489 1490 bkpinfo->cdrw_speed = atoi(tmp); // if DVD then this shouldn't ever be used anyway :)1491 mr_free(tmp);1492 1493 mr_asprintf(comment, "How much data (in Megabytes) will each %s store?", mds);1494 mr_free(mds);1495 p = popup_and_get_string("Size", comment, sz_size);1496 mr_free(sz_size);1497 mr_free(comment);1498 1499 if (p == NULL) {1500 log_to_screen("User has chosen not to backup the PC");1501 finish(1);1502 }1503 sz_size = p;1504 1505 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {1506 bkpinfo->media_size[i] = atoi(sz_size);1507 }1508 1509 if (bkpinfo->media_size[0] <= 0) {1510 log_to_screen("User has chosen not to backup the PC");1511 finish(1);1512 }1513 }1514 /* No break because we continue even for usb */1515 case cdstream:1516 mds = media_descriptor_string(bkpinfo->backup_media_type);1517 1518 mr_free(bkpinfo->media_device);1519 if ((bkpinfo->disaster_recovery) && (bkpinfo->backup_media_type != usb)) {1520 mr_asprintf(bkpinfo->media_device, "/dev/cdrom");1521 log_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device);1522 } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb)) || bkpinfo->backup_media_type == dvd) {1523 if ((bkpinfo->backup_media_type == dvd) || ((bkpinfo->media_device = find_cdrom_device(FALSE)) != NULL)) {1524 mr_asprintf(comment, "Please specify your %s drive's /dev entry", mds);1525 p = popup_and_get_string("Device?", comment, bkpinfo->media_device);1526 mr_free(comment);1527 1528 if (p == NULL) {1529 log_to_screen("User has chosen not to backup the PC");1530 finish(1);1531 }1532 mr_free(bkpinfo->media_device);1533 bkpinfo->media_device = p;1534 }1535 if (bkpinfo->media_device != NULL) {1536 log_msg(2, "%s device found at %s", mds, bkpinfo->media_device);1537 } else {1538 log_msg(2, "%s device not found (bkpinfo->media_device is NULL)", mds);1539 }1540 } else {1541 if (((bkpinfo->media_device = find_cdrw_device()) != NULL) && (bkpinfo->backup_media_type != usb)) {1542 mr_free(bkpinfo->media_device);1543 }1544 if (bkpinfo->media_device != NULL) {1545 if (bkpinfo->backup_media_type == usb) {1546 mr_asprintf(tmp, "I think your %s media corresponds to %s. Is this correct?", mds, bkpinfo->media_device);1547 } else {1548 mr_asprintf(tmp, "I think I've found your %s burner at SCSI node %s. Is this correct? (Say no if you have an IDE burner and you are running a 2.6 kernel. You will then be prompted for further details.)", mds, bkpinfo->media_device);1549 }1550 if (!ask_me_yes_or_no(tmp)) {1551 mr_free(bkpinfo->media_device);1552 }1553 mr_free(tmp);1554 }1555 if (!bkpinfo->media_device) {1556 if (bkpinfo->backup_media_type == usb) {1557 p = popup_and_get_string("/dev entry?", "What is the /dev entry of your USB Disk/Key, please?", NULL);1558 } else {1559 if (g_kernel_version < 2.6) {1560 p = popup_and_get_string("Device node?", "What is the SCSI node of your CD (re)writer, please?", NULL);1561 } else {1562 p = popup_and_get_string("/dev entry?", "What is the /dev entry of your CD (re)writer, please?", NULL);1563 }1564 }1565 if (p == NULL) {1566 log_to_screen("User has chosen not to backup the PC");1567 finish(1);1568 }1569 bkpinfo->media_device = p;1570 }1571 }1572 mr_free(mds);1573 1574 if (bkpinfo->backup_media_type == cdstream) {1575 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {1576 bkpinfo->media_size[i] = 650;1577 }1578 }1579 break;1580 case udev:1581 if (!ask_me_yes_or_no1582 ("This option is for advanced users only. Are you sure?")) {1583 log_to_screen("User has chosen not to backup the PC");1584 finish(1);1585 }1586 case tape:1587 1588 mr_free(bkpinfo->media_device);1589 if ((!bkpinfo->restore_mode) && ((bkpinfo->media_device = mr_find_tape_device()) == NULL)) {1590 log_msg(3, "Ok, using vanilla scsi tape.");1591 mr_asprintf(bkpinfo->media_device, "%s", VANILLA_SCSI_TAPE);1592 if ((fin = fopen(bkpinfo->media_device, "r"))) {1593 paranoid_fclose(fin);1594 } else {1595 mr_free(bkpinfo->media_device);1596 mr_asprintf(bkpinfo->media_device, "/dev/osst0");1597 }1598 }1599 if (bkpinfo->media_device != NULL) {1600 if ((fin = fopen(bkpinfo->media_device, "r"))) {1601 paranoid_fclose(fin);1602 } else {1603 if (does_file_exist("/tmp/mondo-restore.cfg")) {1604 mr_free(bkpinfo->media_device);1605 bkpinfo->media_device = read_cfg_var("/tmp/mondo-restore.cfg", "media-dev");1606 }1607 }1608 }1609 if (bkpinfo->media_device != NULL) {1610 mr_asprintf(tmp, "I think I've found your tape streamer at %s; am I right on the money?", bkpinfo->media_device);1611 if (!ask_me_yes_or_no(tmp)) {1612 mr_free(bkpinfo->media_device);1613 }1614 mr_free(tmp);1615 }1616 if (bkpinfo->media_device == NULL) {1617 p = popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", bkpinfo->media_device);1618 if (p == NULL) {1619 log_to_screen("User has chosen not to backup the PC");1620 finish(1);1621 }1622 bkpinfo->media_device = p;1623 }1624 mr_asprintf(tmp, "ls -l %s", bkpinfo->media_device);1625 if (run_program_and_log_output(tmp, FALSE)) {1626 log_to_screen("User has not specified a valid /dev entry");1627 finish(1);1628 }1629 mr_free(tmp);1630 1631 bkpinfo->use_obdr = ask_me_yes_or_no("Do you want to activate OBDR support for your tapes ?");1632 bkpinfo->media_size[0] = 0;1633 log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]);1634 if (bkpinfo->media_size[0] <= 0) {1635 bkpinfo->media_size[0] = 0;1636 }1637 for (i = 1; i <= MAX_NOOF_MEDIA; i++) {1638 bkpinfo->media_size[i] = bkpinfo->media_size[0];1639 }1640 if (archiving_to_media) {1641 if ((bkpinfo->compression_level =1642 which_compression_level()) == -1) {1643 log_to_screen("User has chosen not to backup the PC");1644 finish(1);1645 }1646 }1647 break;1648 1649 1650 1651 case netfs:1652 /* Never try to eject a NETFS device */1653 bkpinfo->please_dont_eject = TRUE;1654 1655 /* Initiate bkpinfo netfs_mount path from running environment if not already done */1656 if (bkpinfo->netfs_mount == NULL) {1657 bkpinfo->netfs_mount = call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1");1658 }1659 #ifdef __FreeBSD__1660 if (TRUE)1661 #else1662 if (!bkpinfo->disaster_recovery)1663 #endif1664 {1665 p = popup_and_get_string("Network shared dir.", "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)", bkpinfo->netfs_mount);1666 if (p == NULL) {1667 log_to_screen("User has chosen not to backup the PC");1668 finish(1);1669 }1670 mr_free(bkpinfo->netfs_mount);1671 bkpinfo->netfs_mount = p;1672 if (!bkpinfo->restore_data) {1673 if ((bkpinfo->compression_level =1674 which_compression_level()) == -1) {1675 log_to_screen("User has chosen not to backup the PC");1676 finish(1);1677 }1678 }1679 // check whether already mounted - we better remove1680 // surrounding spaces and trailing '/' for this1681 mr_strip_spaces(bkpinfo->netfs_mount);1682 if (bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] == '/')1683 bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] = '\0';1684 mr_asprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", bkpinfo->netfs_mount);1685 mr_free(bkpinfo->isodir);1686 bkpinfo->isodir = call_program_and_get_last_line_of_output(command);1687 mr_free(command);1688 1689 if (!bkpinfo->restore_data) {1690 mr_asprintf(comment, "How much data (in Megabytes) will each media store?");1691 // BERLIOS: 4480 shouldn't be hardcoded here1692 sz_size = popup_and_get_string("Size", comment, "4480");1693 mr_free(comment);1694 if (sz_size == NULL) {1695 log_to_screen("User has chosen not to backup the PC");1696 finish(1);1697 }1698 } else {1699 mr_asprintf(sz_size, "0");1700 }1701 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {1702 bkpinfo->media_size[i] = atoi(sz_size);1703 }1704 mr_free(sz_size);1705 if (bkpinfo->media_size[0] < 0) {1706 log_to_screen("User has chosen not to backup the PC");1707 finish(1);1708 }1709 }1710 if (bkpinfo->disaster_recovery) {1711 mr_asprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir);1712 (void)system(command);1713 mr_free(command);1714 1715 p = popup_and_get_string("Network protocol", "Which Network protocol should I use?", bkpinfo->netfs_proto);1716 if (p == NULL) {1717 log_to_screen("User has chosen not to backup the PC");1718 finish(1);1719 }1720 mr_free(bkpinfo->netfs_proto);1721 bkpinfo->netfs_proto = p;1722 1723 p = popup_and_get_string("Network share", "Which remote Network share should I mount?", bkpinfo->netfs_mount);1724 if (p == NULL) {1725 log_to_screen("User has chosen not to backup the PC");1726 finish(1);1727 }1728 mr_free(bkpinfo->netfs_mount);1729 bkpinfo->netfs_mount = p;1730 }1731 /* Initiate bkpinfo isodir path from running environment if mount already done */1732 mr_free(bkpinfo->isodir);1733 if (is_this_device_mounted(bkpinfo->netfs_mount)) {1734 bkpinfo->isodir = call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1");1735 1736 } else {1737 mr_asprintf(bkpinfo->isodir, "%s/netfsdir", bkpinfo->tmpdir);1738 mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir);1739 run_program_and_log_output(command, 5);1740 mr_free(command);1741 1742 if (bkpinfo->restore_data) {1743 if (strstr(bkpinfo->netfs_proto, "sshfs")) {1744 mr_asprintf(tmp, "sshfs -o ro %s %s", bkpinfo->netfs_mount, bkpinfo->isodir);1745 } else {1746 mr_asprintf(tmp, "mount -t %s -o nolock,ro %s %s", bkpinfo->netfs_proto, bkpinfo->netfs_mount, bkpinfo->isodir);1747 }1748 } else {1749 if (strstr(bkpinfo->netfs_proto, "sshfs")) {1750 mr_asprintf(tmp, "sshfs %s %s", bkpinfo->netfs_mount, bkpinfo->isodir);1751 } else {1752 mr_asprintf(tmp, "mount -t %s -o nolock %s %s", bkpinfo->netfs_proto, bkpinfo->netfs_mount, bkpinfo->isodir);1753 }1754 }1755 run_program_and_log_output(tmp, 3);1756 mr_free(tmp);1757 1758 malloc_string(g_selfmounted_isodir);1759 strcpy(g_selfmounted_isodir, bkpinfo->isodir);1760 }1761 if (!is_this_device_mounted(bkpinfo->netfs_mount)) {1762 popup_and_OK("Please mount that partition before you try to backup to or restore from it.");1763 finish(1);1764 }1765 p = popup_and_get_string("Directory", "Which directory within that mountpoint?", bkpinfo->netfs_remote_dir);1766 if (p == NULL) {1767 log_to_screen("User has chosen not to backup the PC");1768 finish(1);1769 }1770 mr_free(bkpinfo->netfs_remote_dir);1771 bkpinfo->netfs_remote_dir = p;1772 1773 // check whether writable - we better remove surrounding spaces for this1774 mr_strip_spaces(bkpinfo->netfs_remote_dir);1775 1776 p = popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix);1777 if (p == NULL) {1778 log_to_screen("User has chosen not to backup the PC");1779 finish(1);1780 }1781 mr_free(bkpinfo->prefix);1782 bkpinfo->prefix = p;1783 log_msg(3, "prefix set to %s", bkpinfo->prefix);1784 1785 log_msg(3, "Just set netfs_remote_dir to %s", bkpinfo->netfs_remote_dir);1786 log_msg(3, "isodir is still %s", bkpinfo->isodir);1787 break;1788 1789 case iso:1790 if (!bkpinfo->disaster_recovery) {1791 p = popup_and_get_string("Storage dir.", "Please enter the full path name to the directory for your ISO images. Example: /mnt/raid0_0", bkpinfo->isodir);1792 if (p == NULL) {1793 log_to_screen("User has chosen not to backup the PC");1794 finish(1);1795 }1796 bkpinfo->isodir = p;1797 1798 if (archiving_to_media) {1799 if ((bkpinfo->compression_level =1800 which_compression_level()) == -1) {1801 log_to_screen("User has chosen not to backup the PC");1802 finish(1);1803 }1804 p = popup_and_get_string("ISO size.", "Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s or DVD's you plan to backup to.", sz_size);1805 if (p == NULL) {1806 log_to_screen("User has chosen not to backup the PC");1807 finish(1);1808 }1809 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {1810 bkpinfo->media_size[i] = atoi(p);1811 }1812 mr_free(p);1813 } else {1814 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {1815 bkpinfo->media_size[i] = 650;1816 }1817 }1818 }1819 p = popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix);1820 if (p == NULL) {1821 log_to_screen("User has chosen not to backup the PC");1822 finish(1);1823 }1824 mr_free(bkpinfo->prefix);1825 bkpinfo->prefix = p;1826 log_msg(3, "prefix set to %s", bkpinfo->prefix);1827 break;1828 1829 default:1830 fatal_error1831 ("I, Mojo Jojo, shall defeat those pesky Powerpuff Girls!");1832 }1833 1834 if (archiving_to_media) {1835 1836 mr_free(bkpinfo->boot_device);1837 #ifdef __FreeBSD__1838 #define EXAMPLEBD "/dev/ad0"1839 bkpinfo->boot_device = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'");1840 #else1841 #define EXAMPLEBD "/dev/hda"1842 bkpinfo->boot_device = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'");1843 #endif1844 i = which_boot_loader(bkpinfo->boot_device);1845 if (i == 'U') // unknown1846 {1847 1848 p = popup_and_get_string("Boot device", "What is your boot device? (e.g. "EXAMPLEBD")", bkpinfo->boot_device);1849 #undef EXAMPLEBD1850 if (p == NULL) {1851 log_to_screen("User has chosen not to backup the PC");1852 finish(1);1853 }1854 mr_free(bkpinfo->boot_device);1855 bkpinfo->boot_device = p;1856 #ifdef __FreeBSD__1857 i = which_boot_loader(bkpinfo->boot_device);1858 #else1859 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) {1860 i = 'L';1861 } else1862 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "ELILO")) {1863 i = 'E';1864 } else1865 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "GRUB")) {1866 i = 'G';1867 } else {1868 i = 'U';1869 }1870 #endif1871 if (i == 'U') {1872 if (ask_me_yes_or_no("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?")) {1873 i = 'R'; // raw1874 } else {1875 log_to_screen("I cannot find your boot loader. Please run mondoarchive with parameters.");1876 finish(1);1877 }1878 }1879 }1880 bkpinfo->boot_loader = i;1881 mr_free(bkpinfo->include_paths);1882 mr_asprintf(p, "/");1883 bkpinfo->include_paths = p;1884 1885 p = popup_and_get_string("Backup paths", "Please enter paths which you want me to backup. The default is '/' (i.e. everything).", bkpinfo->include_paths);1886 if (p == NULL) {1887 log_to_screen("User has chosen not to backup the PC");1888 finish(1);1889 }1890 mr_free(bkpinfo->include_paths);1891 bkpinfo->include_paths = p;1892 1893 mr_asprintf(tmp, "%s", list_of_NETFS_mounts_only());1894 if (strlen(tmp) > 2) {1895 mr_strcat(bkpinfo->exclude_paths, " %s",tmp);1896 }1897 mr_free(tmp);1898 // NTFS1899 tmp = call_program_and_get_last_line_of_output("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'");1900 if (strlen(tmp) > 2) {1901 p = popup_and_get_string("NTFS partitions", "Please enter/confirm the NTFS partitions you wish to backup as well.", tmp);1902 1903 if (p == NULL) {1904 log_to_screen("User has chosen not to backup the PC");1905 finish(1);1906 }1907 mr_free(bkpinfo->image_devs);1908 bkpinfo->image_devs = p;1909 }1910 1911 1912 p = popup_and_get_string("Exclude paths", "Please enter paths which you do NOT want to backup. Separate them with spaces. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup.", bkpinfo->exclude_paths);1913 if (p == NULL) {1914 log_to_screen("User has chosen not to backup the PC");1915 finish(1);1916 }1917 mr_free(bkpinfo->exclude_paths);1918 bkpinfo->exclude_paths = p;1919 1920 p = popup_and_get_string("Temporary directory", "Please enter your temporary directory.", bkpinfo->tmpdir);1921 if (p == NULL) {1922 log_to_screen("User has chosen not to backup the PC");1923 finish(1);1924 }1925 mr_free(bkpinfo->tmpdir);1926 bkpinfo->tmpdir = p;1927 1928 p = popup_and_get_string("Scratch directory", "Please enter your scratch directory.", bkpinfo->scratchdir);1929 if (p == NULL) {1930 log_to_screen("User has chosen not to backup the PC");1931 finish(1);1932 }1933 mr_free(bkpinfo->scratchdir);1934 bkpinfo->scratchdir = p;1935 1936 // Interactive mode:1937 #ifdef __IA64__1938 bkpinfo->make_cd_use_lilo = TRUE;1939 #else1940 bkpinfo->make_cd_use_lilo = FALSE;1941 #endif1942 bkpinfo->backup_data = TRUE;1943 bkpinfo->verify_data =1944 ask_me_yes_or_no1945 ("Will you want to verify your backups after Mondo has created them?");1946 1947 #ifndef __FreeBSD__1948 if (!ask_me_yes_or_no1949 ("Are you confident that your kernel is a sane, sensible, standard Linux kernel? Say 'no' if you are using a Gentoo <1.4 or Debian <3.0, please."))1950 #endif1951 {1952 mr_free(bkpinfo->kernel_path);1953 mr_asprintf(bkpinfo->kernel_path, "FAILSAFE");1954 }1955 1956 if (!ask_me_yes_or_no1957 ("Are you sure you want to proceed? Hit 'no' to abort.")) {1958 log_to_screen("User has chosen not to backup the PC");1959 finish(1);1960 }1961 } else {1962 bkpinfo->restore_data = TRUE; // probably...1963 }1964 1965 if (bkpinfo->backup_media_type == iso1966 || bkpinfo->backup_media_type == netfs) {1967 g_ISO_restore_mode = TRUE;1968 }1969 #ifdef __FreeSD__1970 // skip1971 #else1972 if (bkpinfo->backup_media_type == netfs) {1973 log_msg(3, "I think the Remote mount is mounted at %s", bkpinfo->isodir);1974 }1975 log_it("isodir = %s", bkpinfo->isodir);1976 if (bkpinfo->netfs_mount) {1977 log_it("netfs_mount = '%s'", bkpinfo->netfs_mount);1978 }1979 if (bkpinfo->netfs_user) {1980 log_it("netfs_user = '%s'", bkpinfo->netfs_user);1981 }1982 if (bkpinfo->netfs_proto) {1983 log_it("netfs_proto = '%s'", bkpinfo->netfs_proto);1984 }1985 #endif1986 1987 log_it("media device = %s", bkpinfo->media_device);1988 log_it("media size = %ld", bkpinfo->media_size[1]);1989 tmp = bkptype_to_string(bkpinfo->backup_media_type);1990 log_it("media type = %s", tmp);1991 mr_free(tmp);1992 1993 if (bkpinfo->prefix) {1994 log_it("prefix = %s", bkpinfo->prefix);1995 }1996 log_it("compression = %ld", bkpinfo->compression_level);1997 if (bkpinfo->include_paths) {1998 log_it("include_paths = '%s'", bkpinfo->include_paths);1999 }2000 if (bkpinfo->exclude_paths) {2001 log_it("exclude_paths = '%s'", bkpinfo->exclude_paths);2002 }2003 log_it("scratchdir = '%s'", bkpinfo->scratchdir);2004 log_it("tmpdir = '%s'", bkpinfo->tmpdir);2005 if (bkpinfo->image_devs) {2006 log_it("image_devs = '%s'", bkpinfo->image_devs);2007 }2008 log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, bkpinfo->boot_loader);2009 if (bkpinfo->media_size[0] < 0) {2010 if (archiving_to_media) {2011 fatal_error("Media size is less than zero.");2012 } else {2013 log_msg(2, "Warning - media size is less than zero.");2014 bkpinfo->media_size[0] = 0;2015 }2016 }2017 paranoid_free(sz_size);2018 return (0);2019 }2020 2021 1402 2022 1403 … … 2542 1923 /* @} - end of deviceGroup */ 2543 1924 2544 2545 1925 /** 2546 1926 * Return the type of partition format (GPT or MBR) … … 2573 1953 } 2574 1954 1955 /** 1956 * Frees the memory for all of the structures on the linked list of 1957 * all of the non-NETFS mounted file systems. 1958 */ 1959 static void free_mounted_fs_list (void) { 1960 MOUNTED_FS_STRUCT *DSFptr = NULL; 1961 MOUNTED_FS_STRUCT *DSFnext = NULL; 1962 1963 DSFptr = DSF_Head; 1964 while (DSFptr != NULL) { 1965 DSFnext = DSFptr->next; 1966 paranoid_free(DSFptr); 1967 DSFptr = DSFnext; 1968 } 1969 DSF_Head = NULL; 1970 DSF_Tail = NULL; 1971 } 1972 1973 /** 1974 * Creates a singly linked list of all of the non-NETFS mounted file systems. 1975 * @param DSFptr A pointer to the structure MOUNTED_FS_STRUCT used to hold 1976 * the list of mounted file systems. 1977 * @return None. 1978 */ 1979 static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr) 1980 { 1981 assert (DSFptr); 1982 if (DSF_Head == NULL) { 1983 DSF_Head = DSFptr; 1984 } else { 1985 DSF_Tail->next = DSFptr; 1986 } 1987 DSFptr->next = NULL; 1988 DSF_Tail = DSFptr; 1989 } 1990 1991 /** 1992 * Find the structure, in the singly linked list of all of the non-NETFS 1993 * mounted file systems, that contains the specified device. 1994 * @param device The device to find 1995 * @return NULL if it didn't find the device, a pointer to the 1996 * structure if it did. 1997 */ 1998 static MOUNTED_FS_STRUCT *find_device_in_list (char *device) 1999 { 2000 MOUNTED_FS_STRUCT *DSFptr = NULL; 2001 2002 DSFptr = DSF_Head; 2003 while (DSFptr != NULL) { 2004 if (!strcmp(DSFptr->device, device)) { 2005 break; 2006 } 2007 DSFptr = DSFptr->next; 2008 } 2009 return (DSFptr); 2010 } 2011 2012 /** 2013 * Find the structure, in the singly linked list of all of the non-NETFS 2014 * mounted file systems, that contains the specified mount point. 2015 * @param mount_point The mount point to find 2016 * @return NULL is it didn't find the mount point, a pointer to the 2017 * structure if it did. 2018 */ 2019 static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point) 2020 { 2021 MOUNTED_FS_STRUCT *DSFptr = NULL; 2022 2023 DSFptr = DSF_Head; 2024 while (DSFptr != NULL) { 2025 if (!strcmp(DSFptr->mount_point, mount_point)) { 2026 break; 2027 } 2028 DSFptr = DSFptr->next; 2029 } 2030 return (DSFptr); 2031 } 2032 2033 /** 2034 * Creates a linked list of all of the non-NETFS mounted file systems. 2035 * We use a linked list because we don't know how many mounted file 2036 * there are (and there can be a lot). 2037 * @return 0 on success and greated than 0 on failure. 2038 */ 2039 static int create_list_of_non_NETFS_mounted_file_systems (void) 2040 { 2041 int i = 0; 2042 int mount_cnt = 0; 2043 char *mounted_file_system = NULL; 2044 char *command = NULL; 2045 char *token = NULL; 2046 char token_chars[] =" :\t\r\f\a\0"; 2047 MOUNTED_FS_STRUCT *DSFptr = NULL; 2048 2049 free_mounted_fs_list(); 2050 /******** 2051 * Find the number of mounted file system entries and their respective mount points. 2052 * I can't return all of the entries as one string because it's length can be longer 2053 * than MAX_STR_LEN which is used in call_program_and_get_last_line_of_output(). 2054 * So start looping and get the number of mounted file systems and query them one by one. 2055 ********/ 2056 /* Get the number of mounted file systems ((those that start with "/dev/" */ 2057 mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l"); 2058 log_msg(5, "Running: %s", command); 2059 mounted_file_system = call_program_and_get_last_line_of_output(command); 2060 mr_free(command); 2061 2062 mount_cnt = atoi(mounted_file_system); 2063 log_msg (5, "mount_cnt: %d", mount_cnt); 2064 mr_free(mounted_file_system); 2065 2066 for (i=mount_cnt; i > 0; i--) { 2067 mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i); 2068 log_msg(5, "Running: %s", command); 2069 mounted_file_system = call_program_and_get_last_line_of_output(command); 2070 mr_free(command); 2071 2072 log_msg (5, "mounted_file_system: %s", mounted_file_system); 2073 if ((token = strtok(mounted_file_system, token_chars)) == NULL) { 2074 log_msg (4, "Could not get the list of mounted file systems"); 2075 mr_free(mounted_file_system); 2076 mr_free(token); 2077 return (1); 2078 } 2079 if (token) { 2080 log_msg (5, "token: %s", token); 2081 } 2082 while (token != NULL) { 2083 log_msg (5, "token: %s", token); 2084 if ((DSFptr = (MOUNTED_FS_STRUCT *) calloc(1, sizeof(MOUNTED_FS_STRUCT))) == NULL) { 2085 fatal_error ("Cannot allocate memory"); 2086 } 2087 add_mounted_fs_struct(DSFptr); 2088 strcpy(DSFptr->device, token); 2089 mr_free(token); 2090 if ((token = strtok(NULL, token_chars)) == NULL) { 2091 log_msg (5, "Ran out of entries on the mounted file systems list"); 2092 mr_free(mounted_file_system); 2093 mr_free(token); 2094 return (1); 2095 } 2096 log_msg (5, "token: %s", token); 2097 strcpy(DSFptr->mount_point, token); 2098 mr_free(token); 2099 token = strtok(NULL, token_chars); 2100 } 2101 mr_free(mounted_file_system); 2102 } 2103 return (0); 2104 } 2105 2106 2107 2108 /** 2109 * Given a whole disk device special file, determine which mounted file systems 2110 * are on the dsf's partitions and which mounted file systems are not. 2111 * @param dsf The whole disk device special file. 2112 * @param included_dsf_list A char pointer used to hold the list of mount points 2113 * that are on the dsf. Memory for the array will be allocated within the function. 2114 * @param excluded_dsf_list A char pointer used to hold the list of mount points 2115 * that are not on the dsf. Memory for the array will be allocated within the function. 2116 * @return 0 on success, -1 if no device special file was passed in, -2 if a device 2117 * special file was passed in but it has no partitions on it, or 1 on failure 2118 */ 2119 static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list) { 2120 int i = 0; 2121 int c = 0; 2122 int lastpos = 0; 2123 char *VG = NULL; 2124 char *tmp = NULL; 2125 char *command = NULL; 2126 char *partition_list = NULL; 2127 char partitions[64][MAX_STR_LEN]; 2128 char *mount_list = NULL; 2129 char *token = NULL; 2130 char token_chars[] =" \t\r\f\a\0"; 2131 MOUNTED_FS_STRUCT *DSFptr = NULL; 2132 2133 memset((char *)partitions, 0, sizeof(partitions)); 2134 2135 log_msg(5, "dsf: %s", dsf); 2136 2137 /******** 2138 * See if a device special file was passed in (i.e. it must start with /dev/ 2139 ********/ 2140 if (strncmp(dsf, "/dev/", 5)) { 2141 log_msg (5, "%s does not start with /dev/ and (probably) is not a device special file", dsf); 2142 return (-1); 2143 } 2144 log_msg(5, " %s looks like a device special file", dsf); 2145 /* Verify that the dsf exists */ 2146 mr_asprintf(command, "ls -al %s 2>/dev/null | wc -l", dsf); 2147 log_msg(5, "Executing: %s", command); 2148 tmp = call_program_and_get_last_line_of_output(command); 2149 mr_free(command); 2150 2151 log_msg(5, " Return value: %s", tmp); 2152 c = atoi(tmp); 2153 mr_free(tmp); 2154 2155 if (!c) { 2156 log_to_screen("Cannot find device special file %s", dsf); 2157 return (1); 2158 } 2159 log_msg(5, " %s device special file exists", dsf); 2160 2161 /* Get a list of the mounted file systems */ 2162 if (create_list_of_non_NETFS_mounted_file_systems()) { 2163 log_to_screen ("Could not get the list of mounted file systems"); 2164 return (1); 2165 } 2166 log_msg (5, "Processing dsf: %s", dsf); 2167 /******** 2168 * Get a list of the dsf's partitions. There could be no partitions on the disk 2169 * or a dsf of a partition was passed in (e.g. /dev/sda1 instead of /dev/sda). 2170 * Either way, it's an error. 2171 ********/ 2172 mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf); 2173 log_msg(4, "Executing: %s", command); 2174 partition_list = call_program_and_get_last_line_of_output(command); 2175 mr_free(command); 2176 log_msg(4, "Partition list for %s: %s", dsf, partition_list); 2177 if (!strlen(partition_list)) { 2178 /* There were no partitions on the disk */ 2179 log_msg(4, "Cannot find any partitions on device special file %s", dsf); 2180 return (-2); 2181 } 2182 2183 /* Fill the partition list */ 2184 i = 0; 2185 lastpos = 0; 2186 while ((token = mr_strtok(partition_list, token_chars, &lastpos)) != NULL) { 2187 log_msg (5, "Found partition: %s", token); 2188 strcpy(partitions[i++], token); 2189 mr_free(token); 2190 } 2191 paranoid_free(partition_list); 2192 2193 /******** 2194 * At this point, we have a list of all of the partitions on the dsf. Now try to 2195 * see which partitions have a file system on them. 2196 * 2197 * Loop through each partition on the disk and: 2198 * 2199 * - If the partition is swap, it ignores it. 2200 * 2201 * - If the partition is mounted (e.g. /dev/sda1 is mounted on /boot), it adds an entry 2202 * to the linked list, copies to it the device name and mount point, and sets check == 1. 2203 * 2204 * - If the partition is part of a Volume Group that has Logical Volumes mounted, it adds 2205 * an entry to the linked list for each mounted Logical Volume in that Volume Group, copying 2206 * to it the device name and mount point, and sets check == 1. Note that if the Volume Group 2207 * contains more than one disk, it will still add the entry even if the Logical Volume's 2208 * extents are not on the dsf that was passed in to the function. For example, Volume Group 2209 * VolGroup00 contains the disks /dev/sda1 and /dev/sdb1, and the Logical Volumes LogVol01, 2210 * which is mounted on /var and has all of its extents on /dev/sda1, and LogVol02, which is 2211 * mounted as /usr and has all of its extents on /dev/sdb1. If you pass /dev/sda into the 2212 * function, both /var and /usr will be archived even though /usr is actually on/dev/sdb. 2213 * 2214 * - If the partition is part of a Volume Group that has Logical Volumes used in a mounted 2215 * software raid device, it adds an entry to the linked list, copies to it the software raid 2216 * device name and mount point, and sets check == 1. 2217 * 2218 * - If the partition is part of a mounted software raid device, it adds an entry to the linked 2219 * list, copies to it the software raid device name and mount point, and sets check == 1. 2220 * 2221 ********/ 2222 for (i=0; strlen(partitions[i]); i++) { 2223 log_msg(4, "Processing partition: %s", partitions[i]); 2224 /* See if it's swap. If it is, ignore it. */ 2225 mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", dsf, partitions[i]); 2226 log_msg(4, " Running: %s", command); 2227 tmp = call_program_and_get_last_line_of_output(command); 2228 mr_free(command); 2229 2230 log_msg(4, " Return value: %s", tmp); 2231 c = strlen(tmp); 2232 mr_free(tmp); 2233 2234 if (c) { 2235 log_msg(4, "It's swap. Ignoring partition %s", partitions[i]); 2236 continue; 2237 } 2238 /* It's not swap. See if we can find the mount point from the mount command. */ 2239 mr_asprintf(command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]); 2240 tmp = call_program_and_get_last_line_of_output(command); 2241 mr_free(command); 2242 2243 c = strlen(tmp); 2244 mr_free(tmp); 2245 if (c) { 2246 log_msg(4, " %s is mounted: %s", partitions[i], tmp); 2247 if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) { 2248 log_msg (4, "Can't find mount point %s in mounted file systems list", tmp); 2249 return (1); 2250 } 2251 DSFptr->check = 1; 2252 continue; 2253 } 2254 2255 /* It's not swap and it's not mounted. See if it's LVM */ 2256 log_msg(4, " It's not mounted. Checking to see if it's LVM..."); 2257 2258 /* Get the partition ID; 8e for LVM */ 2259 mr_asprintf(command, "parted2fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]); 2260 log_msg(4, " Running: %s", command); 2261 tmp = call_program_and_get_last_line_of_output(command); 2262 mr_free(command); 2263 2264 c = strlen(tmp); 2265 mr_free(tmp); 2266 if (c) { 2267 log_msg(4, " Partition ID: %s", tmp); 2268 if (!strcasecmp(tmp, "8e")) { 2269 /* It's LVM: Find the VG it's in */ 2270 log_msg(4, " It's LVM: Find the VG it's in..."); 2271 mr_asprintf(command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]); 2272 log_msg(4, " Running: %s", command); 2273 VG = call_program_and_get_last_line_of_output(command); 2274 mr_free(command); 2275 2276 log_msg(4, " Volume Group: %s", VG); 2277 if (strlen(VG)) { 2278 /* Found the Volume Group. Now find all of the VG's mount points */ 2279 log_msg(4, " Found the Volume Group. Now find all of the VG's mount points"); 2280 mr_asprintf(command, "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", VG, VG); 2281 log_msg(4, " Running: %s", command); 2282 mount_list = call_program_and_get_last_line_of_output(command); 2283 mr_free(command); 2284 2285 log_msg(4, " VG %s mount_list: %s", VG, mount_list); 2286 lastpos = 0; 2287 while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) { 2288 log_msg (5, "mount point token: %s", token); 2289 if ((DSFptr = find_mount_point_in_list(token)) == NULL) { 2290 log_msg (4, "Can't find mount point %s in mounted file systems list", token); 2291 mr_free(token); 2292 mr_free(VG); 2293 return (1); 2294 } 2295 DSFptr->check = 1; 2296 mr_free(token); 2297 } 2298 /******** 2299 * Now we want to see if there are any software raid devices using 2300 * any of the Logical Volumes on the Volume Group. 2301 *******/ 2302 mr_free(mount_list); 2303 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); 2304 log_msg (5, "Running: %s", command); 2305 mount_list = call_program_and_get_last_line_of_output(command); 2306 mr_free(command); 2307 2308 log_msg(4, " Software raid device list: %s", mount_list); 2309 lastpos = 0; 2310 while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) { 2311 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG); 2312 log_msg (5, "Running: %s", command); 2313 2314 tmp = call_program_and_get_last_line_of_output(command); 2315 paranoid_free(command); 2316 log_msg(4, "Number of Software raid device: %s", tmp); 2317 c = atoi(tmp); 2318 mr_free(tmp); 2319 2320 if (c) { 2321 /* This device is on our disk */ 2322 if ((DSFptr = find_device_in_list(token)) == NULL) { 2323 log_msg (4, "Can't find device %s in mounted file systems list", token); 2324 mr_free(token); 2325 return (1); 2326 } 2327 DSFptr->check = 1; 2328 } 2329 mr_free(token); 2330 } 2331 mr_free(token); 2332 mr_free(mount_list); 2333 } else { 2334 log_msg (4, "Error finding Volume Group for partition %s", partitions[i]); 2335 return (1); 2336 } 2337 continue; 2338 } 2339 } else { 2340 log_msg (4, "Error finding partition type for the partition %s", partitions[i]); 2341 } 2342 paranoid_free(tmp); 2343 /******** 2344 * It's not swap, mounted, or LVM. See if it's used in a software raid device. 2345 ********/ 2346 log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device."); 2347 mr_asprintf(command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]); 2348 log_msg(4, " Running: %s", command); 2349 tmp = call_program_and_get_last_line_of_output(command); 2350 mr_free(command); 2351 2352 c = strlen(tmp); 2353 mr_free(tmp); 2354 if (!c) { 2355 log_msg(4, " Partition %s is not used in a non-LVM software raid device", partitions[i]); 2356 continue; 2357 } 2358 log_msg (5, " UUID: %s", tmp); 2359 /* Get the Software raid device list */ 2360 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); 2361 log_msg (5, " Running: %s", command); 2362 mount_list = call_program_and_get_last_line_of_output(command); 2363 mr_free(command); 2364 2365 log_msg(4, " Software raid device list: %s", mount_list); 2366 /* Loop through the software raid device list to see if we can find the partition */ 2367 lastpos = 0; 2368 while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) { 2369 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp); 2370 log_msg(4, " Running: %s", command); 2371 tmp = call_program_and_get_last_line_of_output(command); 2372 mr_free(command); 2373 c = atoi(tmp); 2374 mr_free(tmp); 2375 2376 if (!c) { 2377 log_msg (4," Didn't find partition %s in software raid device %s", partitions[i], token); 2378 } else { 2379 if ((DSFptr = find_device_in_list(token)) == NULL) { 2380 log_msg (4, "Can't find device %s in mounted file systems list", token); 2381 mr_free(token); 2382 return (1); 2383 } 2384 DSFptr->check = 1; 2385 break; 2386 } 2387 mr_free(token); 2388 } 2389 } 2390 mr_free(partition_list); 2391 mr_free(mount_list); 2392 2393 /* Determine how much memory to allocate for included_dsf_list and excluded_dsf_list */ 2394 i = 0; 2395 DSFptr= DSF_Head; 2396 while (DSFptr != NULL) { 2397 i += strlen(DSFptr->mount_point) + 1; 2398 DSFptr = DSFptr->next; 2399 } 2400 log_msg (5, "i: %d", i); 2401 if ((*included_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) { 2402 fatal_error ("Cannot allocate memory"); 2403 } 2404 if ((*excluded_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) { 2405 fatal_error ("Cannot allocate memory"); 2406 } 2407 DSFptr= DSF_Head; 2408 while (DSFptr != NULL) { 2409 if (DSFptr->check) { 2410 log_msg (5, "%s is mounted on %s and is on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf); 2411 strcat(*included_dsf_list, DSFptr->mount_point); 2412 strcat(*included_dsf_list, " "); 2413 } else { 2414 log_msg (4, "%s is mounted on %s and is NOT on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf); 2415 strcat(*excluded_dsf_list, DSFptr->mount_point); 2416 strcat(*excluded_dsf_list, " "); 2417 } 2418 DSFptr = DSFptr->next; 2419 } 2420 log_msg (5, "included_dsf_list: %s", *included_dsf_list); 2421 log_msg (5, "excluded_dsf_list: %s", *excluded_dsf_list); 2422 return (0); 2423 } 2424 2425 2426 /* Update the bkpinfo structure for exclude & include paths 2427 * in order to handle correctly paths corresponding to devices */ 2428 void mr_make_devlist_from_pathlist(char *pathlist, char mode) { 2429 2430 char *token = NULL; 2431 int lastpos = 0; 2432 char *mounted_on_dsf = NULL; 2433 char *not_mounted_on_dsf = NULL; 2434 char token_chars[] =" \t\r\f\a\0"; 2435 2436 while ((token = mr_strtok(pathlist, token_chars, &lastpos)) != NULL) { 2437 switch (get_dsf_mount_list(token, &mounted_on_dsf, ¬_mounted_on_dsf)) { 2438 case 1: 2439 if (mode == 'E') { 2440 log_msg(1, "WARNING ! %s doesn't exist in -E option", token); 2441 } else { 2442 fatal_error("Error processing -I option"); 2443 } 2444 break; 2445 /* Everything is OK; proceed to archive data */ 2446 case 0: 2447 if (mode == 'E') { 2448 if (strlen(mounted_on_dsf)) { 2449 log_to_screen("Excluding the following file systems on %s:\n", token); 2450 log_to_screen(" %s\n", mounted_on_dsf); 2451 log_msg (5, "Adding to bkpinfo->exclude_paths due to -E option: %s", mounted_on_dsf); 2452 mr_strcat(bkpinfo->exclude_paths, "%s ", mounted_on_dsf); 2453 mr_strcat(bkpinfo->exclude_devs, " %s ", token); 2454 } else { 2455 log_to_screen("Archiving only the following file systems on %s:\n", token); 2456 log_to_screen(" %s\n", mounted_on_dsf); 2457 mr_asprintf(bkpinfo->include_paths, "/"); 2458 if (strlen(not_mounted_on_dsf)) { 2459 log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf); 2460 log_to_screen("Not archiving the following file systems:\n"); 2461 log_to_screen(" %s\n", not_mounted_on_dsf); 2462 mr_strcat(bkpinfo->exclude_paths, "%s ", not_mounted_on_dsf); 2463 } 2464 } 2465 } 2466 break; 2467 /* It's a dsf but not a whole disk dsf */ 2468 case -2: 2469 log_to_screen("Could %s be a partition instead of a whole disk device special file?\nIgnored.", token); 2470 break; 2471 /* A device special file was not passed in. Process it as a path. */ 2472 case -1: 2473 if (mode == 'E') { 2474 mr_strcat(bkpinfo->exclude_paths, "%s ", token); 2475 } else { 2476 mr_strcat(bkpinfo->include_paths, "%s ", token); 2477 } 2478 break; 2479 } 2480 mr_free(token); 2481 2482 if (bkpinfo->include_paths != NULL) { 2483 mr_strip_spaces(bkpinfo->include_paths); 2484 log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths); 2485 } 2486 if (bkpinfo->exclude_paths != NULL) { 2487 mr_strip_spaces(bkpinfo->exclude_paths); 2488 log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths); 2489 } 2490 if (bkpinfo->exclude_devs != NULL) { 2491 mr_strip_spaces(bkpinfo->exclude_devs); 2492 log_msg(1, "exclude_devs is now '%s'", bkpinfo->exclude_devs); 2493 } 2494 } 2495 } 2496 2497 2498 2499 /** 2500 * Ask user for details of backup/restore information. 2501 * Called when @c mondoarchive doesn't get any parameters. 2502 * @param bkpinfo The backup information structure to fill out with the user's data. 2503 * @param archiving_to_media TRUE if archiving, FALSE if restoring. 2504 * @return 0, always. 2505 * @bug No point of `int' return value. 2506 * @ingroup archiveGroup 2507 */ 2508 int interactively_obtain_media_parameters_from_user(bool archiving_to_media) 2509 // archiving_to_media is TRUE if I'm being called by mondoarchive 2510 // archiving_to_media is FALSE if I'm being called by mondorestore 2511 { 2512 char *tmp = NULL; 2513 char *p = NULL; 2514 char *mds = NULL; 2515 char *sz_size = NULL; 2516 char *command = NULL; 2517 char *comment = NULL; 2518 int i; 2519 FILE *fin; 2520 2521 assert(bkpinfo != NULL); 2522 bkpinfo->nonbootable_backup = FALSE; 2523 2524 // Tape, CD, NETFS, ...? 2525 srandom(getpid()); 2526 bkpinfo->backup_media_type = 2527 (g_restoring_live_from_cd) ? cdr : 2528 which_backup_media_type(bkpinfo->restore_data); 2529 if (bkpinfo->backup_media_type == none) { 2530 log_to_screen("User has chosen not to backup the PC"); 2531 finish(1); 2532 } 2533 /* Why asking to remove the media with tape ? 2534 if (bkpinfo->backup_media_type == tape && bkpinfo->restore_data) { 2535 popup_and_OK("Please remove media from drive(s)"); 2536 } 2537 */ 2538 tmp = bkptype_to_string(bkpinfo->backup_media_type); 2539 log_msg(3, "media type = %s", tmp); 2540 mr_free(tmp); 2541 2542 bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4; 2543 bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1 : 5; 2544 bkpinfo->use_lzo = (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE; 2545 mvaddstr_and_log_it(2, 0, " "); 2546 2547 // Find device's /dev (or SCSI) entry 2548 switch (bkpinfo->backup_media_type) { 2549 case cdr: 2550 case cdrw: 2551 case dvd: 2552 case usb: 2553 /* Never try to eject a USB device */ 2554 if (bkpinfo->backup_media_type == usb) { 2555 bkpinfo->please_dont_eject = TRUE; 2556 } 2557 if (archiving_to_media) { 2558 if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) { 2559 if (ask_me_yes_or_no("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) { 2560 bkpinfo->manual_cd_tray = TRUE; 2561 } 2562 } 2563 if ((bkpinfo->compression_level = which_compression_level()) == -1) { 2564 log_to_screen("User has chosen not to backup the PC"); 2565 finish(1); 2566 } 2567 mds = media_descriptor_string(bkpinfo->backup_media_type); 2568 mr_asprintf(comment, "What speed is your %s (re)writer?", mds); 2569 mr_free(bkpinfo->media_device); 2570 if (bkpinfo->backup_media_type == dvd) { 2571 bkpinfo->media_device = find_dvd_device(); 2572 mr_asprintf(tmp, "1"); 2573 mr_asprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB 2574 log_msg(1, "Setting to DVD defaults"); 2575 } else { 2576 mr_asprintf(bkpinfo->media_device, "%s", VANILLA_SCSI_CDROM); 2577 mr_asprintf(tmp, "4"); 2578 mr_asprintf(sz_size, "%d", 650); 2579 log_msg(1, "Setting to CD defaults"); 2580 } 2581 if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) { 2582 p = popup_and_get_string("Speed", comment, tmp); 2583 mr_free(tmp); 2584 2585 if (p == NULL) { 2586 log_to_screen("User has chosen not to backup the PC"); 2587 mr_free(comment); 2588 finish(1); 2589 } 2590 /* tmp now has the new value given by the user */ 2591 tmp = p; 2592 } 2593 mr_free(comment); 2594 2595 bkpinfo->cdrw_speed = atoi(tmp); // if DVD then this shouldn't ever be used anyway :) 2596 mr_free(tmp); 2597 2598 mr_asprintf(comment, "How much data (in Megabytes) will each %s store?", mds); 2599 mr_free(mds); 2600 p = popup_and_get_string("Size", comment, sz_size); 2601 mr_free(sz_size); 2602 mr_free(comment); 2603 2604 if (p == NULL) { 2605 log_to_screen("User has chosen not to backup the PC"); 2606 finish(1); 2607 } 2608 sz_size = p; 2609 2610 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 2611 bkpinfo->media_size[i] = atoi(sz_size); 2612 } 2613 2614 if (bkpinfo->media_size[0] <= 0) { 2615 log_to_screen("User has chosen not to backup the PC"); 2616 finish(1); 2617 } 2618 } 2619 /* No break because we continue even for usb */ 2620 case cdstream: 2621 mds = media_descriptor_string(bkpinfo->backup_media_type); 2622 2623 mr_free(bkpinfo->media_device); 2624 if ((bkpinfo->disaster_recovery) && (bkpinfo->backup_media_type != usb)) { 2625 mr_asprintf(bkpinfo->media_device, "/dev/cdrom"); 2626 log_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device); 2627 } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb)) || bkpinfo->backup_media_type == dvd) { 2628 if ((bkpinfo->backup_media_type == dvd) || ((bkpinfo->media_device = find_cdrom_device(FALSE)) != NULL)) { 2629 mr_asprintf(comment, "Please specify your %s drive's /dev entry", mds); 2630 p = popup_and_get_string("Device?", comment, bkpinfo->media_device); 2631 mr_free(comment); 2632 2633 if (p == NULL) { 2634 log_to_screen("User has chosen not to backup the PC"); 2635 finish(1); 2636 } 2637 mr_free(bkpinfo->media_device); 2638 bkpinfo->media_device = p; 2639 } 2640 if (bkpinfo->media_device != NULL) { 2641 log_msg(2, "%s device found at %s", mds, bkpinfo->media_device); 2642 } else { 2643 log_msg(2, "%s device not found (bkpinfo->media_device is NULL)", mds); 2644 } 2645 } else { 2646 if (((bkpinfo->media_device = find_cdrw_device()) != NULL) && (bkpinfo->backup_media_type != usb)) { 2647 mr_free(bkpinfo->media_device); 2648 } 2649 if (bkpinfo->media_device != NULL) { 2650 if (bkpinfo->backup_media_type == usb) { 2651 mr_asprintf(tmp, "I think your %s media corresponds to %s. Is this correct?", mds, bkpinfo->media_device); 2652 } else { 2653 mr_asprintf(tmp, "I think I've found your %s burner at SCSI node %s. Is this correct? (Say no if you have an IDE burner and you are running a 2.6 kernel. You will then be prompted for further details.)", mds, bkpinfo->media_device); 2654 } 2655 if (!ask_me_yes_or_no(tmp)) { 2656 mr_free(bkpinfo->media_device); 2657 } 2658 mr_free(tmp); 2659 } 2660 if (!bkpinfo->media_device) { 2661 if (bkpinfo->backup_media_type == usb) { 2662 p = popup_and_get_string("/dev entry?", "What is the /dev entry of your USB Disk/Key, please?", NULL); 2663 } else { 2664 if (g_kernel_version < 2.6) { 2665 p = popup_and_get_string("Device node?", "What is the SCSI node of your CD (re)writer, please?", NULL); 2666 } else { 2667 p = popup_and_get_string("/dev entry?", "What is the /dev entry of your CD (re)writer, please?", NULL); 2668 } 2669 } 2670 if (p == NULL) { 2671 log_to_screen("User has chosen not to backup the PC"); 2672 finish(1); 2673 } 2674 bkpinfo->media_device = p; 2675 } 2676 } 2677 mr_free(mds); 2678 2679 if (bkpinfo->backup_media_type == cdstream) { 2680 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 2681 bkpinfo->media_size[i] = 650; 2682 } 2683 } 2684 break; 2685 case udev: 2686 if (!ask_me_yes_or_no 2687 ("This option is for advanced users only. Are you sure?")) { 2688 log_to_screen("User has chosen not to backup the PC"); 2689 finish(1); 2690 } 2691 case tape: 2692 2693 mr_free(bkpinfo->media_device); 2694 if ((!bkpinfo->restore_mode) && ((bkpinfo->media_device = mr_find_tape_device()) == NULL)) { 2695 log_msg(3, "Ok, using vanilla scsi tape."); 2696 mr_asprintf(bkpinfo->media_device, "%s", VANILLA_SCSI_TAPE); 2697 if ((fin = fopen(bkpinfo->media_device, "r"))) { 2698 paranoid_fclose(fin); 2699 } else { 2700 mr_free(bkpinfo->media_device); 2701 mr_asprintf(bkpinfo->media_device, "/dev/osst0"); 2702 } 2703 } 2704 if (bkpinfo->media_device != NULL) { 2705 if ((fin = fopen(bkpinfo->media_device, "r"))) { 2706 paranoid_fclose(fin); 2707 } else { 2708 if (does_file_exist("/tmp/mondo-restore.cfg")) { 2709 mr_free(bkpinfo->media_device); 2710 bkpinfo->media_device = read_cfg_var("/tmp/mondo-restore.cfg", "media-dev"); 2711 } 2712 } 2713 } 2714 if (bkpinfo->media_device != NULL) { 2715 mr_asprintf(tmp, "I think I've found your tape streamer at %s; am I right on the money?", bkpinfo->media_device); 2716 if (!ask_me_yes_or_no(tmp)) { 2717 mr_free(bkpinfo->media_device); 2718 } 2719 mr_free(tmp); 2720 } 2721 if (bkpinfo->media_device == NULL) { 2722 p = popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", bkpinfo->media_device); 2723 if (p == NULL) { 2724 log_to_screen("User has chosen not to backup the PC"); 2725 finish(1); 2726 } 2727 bkpinfo->media_device = p; 2728 } 2729 mr_asprintf(tmp, "ls -l %s", bkpinfo->media_device); 2730 if (run_program_and_log_output(tmp, FALSE)) { 2731 log_to_screen("User has not specified a valid /dev entry"); 2732 finish(1); 2733 } 2734 mr_free(tmp); 2735 2736 bkpinfo->use_obdr = ask_me_yes_or_no("Do you want to activate OBDR support for your tapes ?"); 2737 bkpinfo->media_size[0] = 0; 2738 log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]); 2739 if (bkpinfo->media_size[0] <= 0) { 2740 bkpinfo->media_size[0] = 0; 2741 } 2742 for (i = 1; i <= MAX_NOOF_MEDIA; i++) { 2743 bkpinfo->media_size[i] = bkpinfo->media_size[0]; 2744 } 2745 if (archiving_to_media) { 2746 if ((bkpinfo->compression_level = 2747 which_compression_level()) == -1) { 2748 log_to_screen("User has chosen not to backup the PC"); 2749 finish(1); 2750 } 2751 } 2752 break; 2753 2754 2755 2756 case netfs: 2757 /* Never try to eject a NETFS device */ 2758 bkpinfo->please_dont_eject = TRUE; 2759 2760 /* Initiate bkpinfo netfs_mount path from running environment if not already done */ 2761 if (bkpinfo->netfs_mount == NULL) { 2762 bkpinfo->netfs_mount = call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1"); 2763 } 2764 #ifdef __FreeBSD__ 2765 if (TRUE) 2766 #else 2767 if (!bkpinfo->disaster_recovery) 2768 #endif 2769 { 2770 p = popup_and_get_string("Network shared dir.", "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)", bkpinfo->netfs_mount); 2771 if (p == NULL) { 2772 log_to_screen("User has chosen not to backup the PC"); 2773 finish(1); 2774 } 2775 mr_free(bkpinfo->netfs_mount); 2776 bkpinfo->netfs_mount = p; 2777 if (!bkpinfo->restore_data) { 2778 if ((bkpinfo->compression_level = 2779 which_compression_level()) == -1) { 2780 log_to_screen("User has chosen not to backup the PC"); 2781 finish(1); 2782 } 2783 } 2784 // check whether already mounted - we better remove 2785 // surrounding spaces and trailing '/' for this 2786 mr_strip_spaces(bkpinfo->netfs_mount); 2787 if (bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] == '/') 2788 bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] = '\0'; 2789 mr_asprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", bkpinfo->netfs_mount); 2790 mr_free(bkpinfo->isodir); 2791 bkpinfo->isodir = call_program_and_get_last_line_of_output(command); 2792 mr_free(command); 2793 2794 if (!bkpinfo->restore_data) { 2795 mr_asprintf(comment, "How much data (in Megabytes) will each media store?"); 2796 // BERLIOS: 4480 shouldn't be hardcoded here 2797 sz_size = popup_and_get_string("Size", comment, "4480"); 2798 mr_free(comment); 2799 if (sz_size == NULL) { 2800 log_to_screen("User has chosen not to backup the PC"); 2801 finish(1); 2802 } 2803 } else { 2804 mr_asprintf(sz_size, "0"); 2805 } 2806 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 2807 bkpinfo->media_size[i] = atoi(sz_size); 2808 } 2809 mr_free(sz_size); 2810 if (bkpinfo->media_size[0] < 0) { 2811 log_to_screen("User has chosen not to backup the PC"); 2812 finish(1); 2813 } 2814 } 2815 if (bkpinfo->disaster_recovery) { 2816 mr_asprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir); 2817 (void)system(command); 2818 mr_free(command); 2819 2820 p = popup_and_get_string("Network protocol", "Which Network protocol should I use?", bkpinfo->netfs_proto); 2821 if (p == NULL) { 2822 log_to_screen("User has chosen not to backup the PC"); 2823 finish(1); 2824 } 2825 mr_free(bkpinfo->netfs_proto); 2826 bkpinfo->netfs_proto = p; 2827 2828 p = popup_and_get_string("Network share", "Which remote Network share should I mount?", bkpinfo->netfs_mount); 2829 if (p == NULL) { 2830 log_to_screen("User has chosen not to backup the PC"); 2831 finish(1); 2832 } 2833 mr_free(bkpinfo->netfs_mount); 2834 bkpinfo->netfs_mount = p; 2835 } 2836 /* Initiate bkpinfo isodir path from running environment if mount already done */ 2837 mr_free(bkpinfo->isodir); 2838 if (is_this_device_mounted(bkpinfo->netfs_mount)) { 2839 bkpinfo->isodir = call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1"); 2840 2841 } else { 2842 mr_asprintf(bkpinfo->isodir, "%s/netfsdir", bkpinfo->tmpdir); 2843 mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir); 2844 run_program_and_log_output(command, 5); 2845 mr_free(command); 2846 2847 if (bkpinfo->restore_data) { 2848 if (strstr(bkpinfo->netfs_proto, "sshfs")) { 2849 mr_asprintf(tmp, "sshfs -o ro %s %s", bkpinfo->netfs_mount, bkpinfo->isodir); 2850 } else { 2851 mr_asprintf(tmp, "mount -t %s -o nolock,ro %s %s", bkpinfo->netfs_proto, bkpinfo->netfs_mount, bkpinfo->isodir); 2852 } 2853 } else { 2854 if (strstr(bkpinfo->netfs_proto, "sshfs")) { 2855 mr_asprintf(tmp, "sshfs %s %s", bkpinfo->netfs_mount, bkpinfo->isodir); 2856 } else { 2857 mr_asprintf(tmp, "mount -t %s -o nolock %s %s", bkpinfo->netfs_proto, bkpinfo->netfs_mount, bkpinfo->isodir); 2858 } 2859 } 2860 run_program_and_log_output(tmp, 3); 2861 mr_free(tmp); 2862 2863 malloc_string(g_selfmounted_isodir); 2864 strcpy(g_selfmounted_isodir, bkpinfo->isodir); 2865 } 2866 if (!is_this_device_mounted(bkpinfo->netfs_mount)) { 2867 popup_and_OK("Please mount that partition before you try to backup to or restore from it."); 2868 finish(1); 2869 } 2870 p = popup_and_get_string("Directory", "Which directory within that mountpoint?", bkpinfo->netfs_remote_dir); 2871 if (p == NULL) { 2872 log_to_screen("User has chosen not to backup the PC"); 2873 finish(1); 2874 } 2875 mr_free(bkpinfo->netfs_remote_dir); 2876 bkpinfo->netfs_remote_dir = p; 2877 2878 // check whether writable - we better remove surrounding spaces for this 2879 mr_strip_spaces(bkpinfo->netfs_remote_dir); 2880 2881 p = popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix); 2882 if (p == NULL) { 2883 log_to_screen("User has chosen not to backup the PC"); 2884 finish(1); 2885 } 2886 mr_free(bkpinfo->prefix); 2887 bkpinfo->prefix = p; 2888 log_msg(3, "prefix set to %s", bkpinfo->prefix); 2889 2890 log_msg(3, "Just set netfs_remote_dir to %s", bkpinfo->netfs_remote_dir); 2891 log_msg(3, "isodir is still %s", bkpinfo->isodir); 2892 break; 2893 2894 case iso: 2895 if (!bkpinfo->disaster_recovery) { 2896 p = popup_and_get_string("Storage dir.", "Please enter the full path name to the directory for your ISO images. Example: /mnt/raid0_0", bkpinfo->isodir); 2897 if (p == NULL) { 2898 log_to_screen("User has chosen not to backup the PC"); 2899 finish(1); 2900 } 2901 bkpinfo->isodir = p; 2902 2903 if (archiving_to_media) { 2904 if ((bkpinfo->compression_level = 2905 which_compression_level()) == -1) { 2906 log_to_screen("User has chosen not to backup the PC"); 2907 finish(1); 2908 } 2909 p = popup_and_get_string("ISO size.", "Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s or DVD's you plan to backup to.", sz_size); 2910 if (p == NULL) { 2911 log_to_screen("User has chosen not to backup the PC"); 2912 finish(1); 2913 } 2914 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 2915 bkpinfo->media_size[i] = atoi(p); 2916 } 2917 mr_free(p); 2918 } else { 2919 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 2920 bkpinfo->media_size[i] = 650; 2921 } 2922 } 2923 } 2924 p = popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix); 2925 if (p == NULL) { 2926 log_to_screen("User has chosen not to backup the PC"); 2927 finish(1); 2928 } 2929 mr_free(bkpinfo->prefix); 2930 bkpinfo->prefix = p; 2931 log_msg(3, "prefix set to %s", bkpinfo->prefix); 2932 break; 2933 2934 default: 2935 fatal_error 2936 ("I, Mojo Jojo, shall defeat those pesky Powerpuff Girls!"); 2937 } 2938 2939 if (archiving_to_media) { 2940 2941 mr_free(bkpinfo->boot_device); 2942 #ifdef __FreeBSD__ 2943 #define EXAMPLEBD "/dev/ad0" 2944 bkpinfo->boot_device = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"); 2945 #else 2946 #define EXAMPLEBD "/dev/hda" 2947 bkpinfo->boot_device = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"); 2948 #endif 2949 i = which_boot_loader(bkpinfo->boot_device); 2950 if (i == 'U') // unknown 2951 { 2952 2953 p = popup_and_get_string("Boot device", "What is your boot device? (e.g. "EXAMPLEBD")", bkpinfo->boot_device); 2954 #undef EXAMPLEBD 2955 if (p == NULL) { 2956 log_to_screen("User has chosen not to backup the PC"); 2957 finish(1); 2958 } 2959 mr_free(bkpinfo->boot_device); 2960 bkpinfo->boot_device = p; 2961 #ifdef __FreeBSD__ 2962 i = which_boot_loader(bkpinfo->boot_device); 2963 #else 2964 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) { 2965 i = 'L'; 2966 } else 2967 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "ELILO")) { 2968 i = 'E'; 2969 } else 2970 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "GRUB")) { 2971 i = 'G'; 2972 } else { 2973 i = 'U'; 2974 } 2975 #endif 2976 if (i == 'U') { 2977 if (ask_me_yes_or_no("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?")) { 2978 i = 'R'; // raw 2979 } else { 2980 log_to_screen("I cannot find your boot loader. Please run mondoarchive with parameters."); 2981 finish(1); 2982 } 2983 } 2984 } 2985 bkpinfo->boot_loader = i; 2986 mr_free(bkpinfo->include_paths); 2987 mr_asprintf(p, "/"); 2988 bkpinfo->include_paths = p; 2989 2990 p = popup_and_get_string("Backup paths", "Please enter paths which you want me to backup. The default is '/' (i.e. everything).", bkpinfo->include_paths); 2991 if (p == NULL) { 2992 log_to_screen("User has chosen not to backup the PC"); 2993 finish(1); 2994 } 2995 mr_free(bkpinfo->include_paths); 2996 bkpinfo->include_paths = p; 2997 2998 mr_asprintf(tmp, "%s", list_of_NETFS_mounts_only()); 2999 if (strlen(tmp) > 2) { 3000 mr_strcat(bkpinfo->exclude_paths, " %s",tmp); 3001 } 3002 mr_free(tmp); 3003 // NTFS 3004 tmp = call_program_and_get_last_line_of_output("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"); 3005 if (strlen(tmp) > 2) { 3006 p = popup_and_get_string("NTFS partitions", "Please enter/confirm the NTFS partitions you wish to backup as well.", tmp); 3007 3008 if (p == NULL) { 3009 log_to_screen("User has chosen not to backup the PC"); 3010 finish(1); 3011 } 3012 mr_free(bkpinfo->image_devs); 3013 bkpinfo->image_devs = p; 3014 } 3015 3016 3017 p = popup_and_get_string("Exclude paths", "Please enter paths which you do NOT want to backup. Separate them with spaces. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup.", bkpinfo->exclude_paths); 3018 if (p == NULL) { 3019 log_to_screen("User has chosen not to backup the PC"); 3020 finish(1); 3021 } 3022 mr_free(bkpinfo->exclude_paths); 3023 bkpinfo->exclude_paths = p; 3024 3025 p = popup_and_get_string("Temporary directory", "Please enter your temporary directory.", bkpinfo->tmpdir); 3026 if (p == NULL) { 3027 log_to_screen("User has chosen not to backup the PC"); 3028 finish(1); 3029 } 3030 mr_free(bkpinfo->tmpdir); 3031 bkpinfo->tmpdir = p; 3032 3033 p = popup_and_get_string("Scratch directory", "Please enter your scratch directory.", bkpinfo->scratchdir); 3034 if (p == NULL) { 3035 log_to_screen("User has chosen not to backup the PC"); 3036 finish(1); 3037 } 3038 mr_free(bkpinfo->scratchdir); 3039 bkpinfo->scratchdir = p; 3040 3041 // Interactive mode: 3042 #ifdef __IA64__ 3043 bkpinfo->make_cd_use_lilo = TRUE; 3044 #else 3045 bkpinfo->make_cd_use_lilo = FALSE; 3046 #endif 3047 bkpinfo->backup_data = TRUE; 3048 bkpinfo->verify_data = 3049 ask_me_yes_or_no 3050 ("Will you want to verify your backups after Mondo has created them?"); 3051 3052 #ifndef __FreeBSD__ 3053 if (!ask_me_yes_or_no 3054 ("Are you confident that your kernel is a sane, sensible, standard Linux kernel? Say 'no' if you are using a Gentoo <1.4 or Debian <3.0, please.")) 3055 #endif 3056 { 3057 mr_free(bkpinfo->kernel_path); 3058 mr_asprintf(bkpinfo->kernel_path, "FAILSAFE"); 3059 } 3060 3061 if (!ask_me_yes_or_no 3062 ("Are you sure you want to proceed? Hit 'no' to abort.")) { 3063 log_to_screen("User has chosen not to backup the PC"); 3064 finish(1); 3065 } 3066 } else { 3067 bkpinfo->restore_data = TRUE; // probably... 3068 } 3069 3070 if (bkpinfo->backup_media_type == iso 3071 || bkpinfo->backup_media_type == netfs) { 3072 g_ISO_restore_mode = TRUE; 3073 } 3074 #ifdef __FreeSD__ 3075 // skip 3076 #else 3077 if (bkpinfo->backup_media_type == netfs) { 3078 log_msg(3, "I think the Remote mount is mounted at %s", bkpinfo->isodir); 3079 } 3080 log_it("isodir = %s", bkpinfo->isodir); 3081 if (bkpinfo->netfs_mount) { 3082 log_it("netfs_mount = '%s'", bkpinfo->netfs_mount); 3083 } 3084 if (bkpinfo->netfs_user) { 3085 log_it("netfs_user = '%s'", bkpinfo->netfs_user); 3086 } 3087 if (bkpinfo->netfs_proto) { 3088 log_it("netfs_proto = '%s'", bkpinfo->netfs_proto); 3089 } 3090 #endif 3091 3092 log_it("media device = %s", bkpinfo->media_device); 3093 log_it("media size = %ld", bkpinfo->media_size[1]); 3094 tmp = bkptype_to_string(bkpinfo->backup_media_type); 3095 log_it("media type = %s", tmp); 3096 mr_free(tmp); 3097 3098 if (bkpinfo->prefix) { 3099 log_it("prefix = %s", bkpinfo->prefix); 3100 } 3101 log_it("compression = %ld", bkpinfo->compression_level); 3102 3103 /* Handle devices passed in bkpinfo and print result */ 3104 mr_make_devlist_from_pathlist(bkpinfo->exclude_paths, 'E'); 3105 mr_make_devlist_from_pathlist(bkpinfo->include_paths, 'I'); 3106 3107 log_it("scratchdir = '%s'", bkpinfo->scratchdir); 3108 log_it("tmpdir = '%s'", bkpinfo->tmpdir); 3109 if (bkpinfo->image_devs) { 3110 log_it("image_devs = '%s'", bkpinfo->image_devs); 3111 } 3112 log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, bkpinfo->boot_loader); 3113 if (bkpinfo->media_size[0] < 0) { 3114 if (archiving_to_media) { 3115 fatal_error("Media size is less than zero."); 3116 } else { 3117 log_msg(2, "Warning - media size is less than zero."); 3118 bkpinfo->media_size[0] = 0; 3119 } 3120 } 3121 paranoid_free(sz_size); 3122 return (0); 3123 } 3124 3125 3126 3127 2575 3128 /* @} - end of deviceGroup */ -
branches/2.2.10/mondo/src/common/libmondo-tools.c
r2421 r2428 777 777 mr_free(bkpinfo->include_paths); 778 778 mr_free(bkpinfo->exclude_paths); 779 mr_free(bkpinfo->exclude_devs); 779 780 mr_free(bkpinfo->restore_path); 780 781 mr_free(bkpinfo->call_before_iso); … … 840 841 bkpinfo->include_paths = NULL; 841 842 bkpinfo->exclude_paths = NULL; 843 bkpinfo->exclude_devs = NULL; 842 844 bkpinfo->restore_path = NULL; 843 845 bkpinfo->call_before_iso = NULL; -
branches/2.2.10/mondo/src/common/mondostructures.h
r2382 r2428 521 521 */ 522 522 char *exclude_paths; 523 524 /** 525 * Devices to NOT back up. 526 * Multiple devices should be separated by spaces. 527 */ 528 char *exclude_devs; 523 529 524 530 /**
Note:
See TracChangeset
for help on using the changeset viewer.