Ignore:
Timestamp:
Sep 9, 2009, 8:30:47 PM (15 years ago)
Author:
Bruno Cornec
Message:
  • Change NFS support into a NetFS support to allow for multiple protocol in addition to NFS (NEEDS TESTING)
  • Better logging to detect a potential nuke issue
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mondo/src/common/libmondo-cli.c

    r2309 r2380  
    5555static void free_mounted_fs_list (void);
    5656static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list);
    57 static int create_list_of_non_NFS_mounted_file_systems (void);
     57static int create_list_of_non_NETFS_mounted_file_systems (void);
    5858static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point);
    5959static MOUNTED_FS_STRUCT *find_device_in_list (char *device);
     
    178178/**
    179179 * Frees the memory for all of the structures on the linked list of
    180  * all of the non-NFS mounted file systems.
     180 * all of the non-NETFS mounted file systems.
    181181 */
    182182static void free_mounted_fs_list (void) {
     
    195195
    196196/**
    197  * Creates a singly linked list of all of the non-NFS mounted file systems.
     197 * Creates a singly linked list of all of the non-NETFS mounted file systems.
    198198 * @param DSFptr A pointer  to the structure MOUNTED_FS_STRUCT used to hold
    199199 * the list of mounted file systems.
     
    213213
    214214/**
    215  * Find the structure, in the singly linked list of all of the non-NFS
     215 * Find the structure, in the singly linked list of all of the non-NETFS
    216216 * mounted file systems, that contains the specified device.
    217217 * @param device The device to find
     
    234234
    235235/**
    236  * Find the structure, in the singly linked list of all of the non-NFS
     236 * Find the structure, in the singly linked list of all of the non-NETFS
    237237 * mounted file systems, that contains the specified mount point.
    238238 * @param mount_point The mount point to find
     
    255255
    256256/**
    257  * Creates a linked list of all of the non-NFS mounted file systems.
     257 * Creates a linked list of all of the non-NETFS mounted file systems.
    258258 * We use a linked list because we don't know how many  mounted file
    259259 * there are (and there can be a lot).
    260260 * @return 0 on success and greated than 0 on failure.
    261261 */
    262 static int create_list_of_non_NFS_mounted_file_systems (void)
     262static int create_list_of_non_NETFS_mounted_file_systems (void)
    263263{
    264264    int i = 0;
     
    388388
    389389    /* Get a list of the mounted file systems */
    390     if (create_list_of_non_NFS_mounted_file_systems()) {
     390    if (create_list_of_non_NETFS_mounted_file_systems()) {
    391391        log_to_screen ("Could not get the list of mounted file systems");
    392392        return (1);
     
    992992
    993993    if (flag_set['n']) {
    994         strncpy(bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN);
     994        strncpy(bkpinfo->netfs_mount, flag_val['n'], MAX_STR_LEN);
    995995        if (!flag_set['d']) {
    996             strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN);
    997         }
    998         /* test if we specified a user for the NFS dialog */
    999         p = strchr(bkpinfo->nfs_mount, '@');
     996            strncpy(bkpinfo->netfs_remote_dir, "/", MAX_STR_LEN);
     997        }
     998        /* test for protocol */
     999        p = strchr(bkpinfo->netfs_mount, ':');
     1000        if (p == NULL) {
     1001            /* protocol not found abort */
     1002            fatal_error("No protocol specified for remote share mount. Please do man mondoarchive as syntax changed");
     1003        } else {
     1004            /* Proto found. Store the 2 values */
     1005            p++;
     1006            if (*p != '/') {
     1007                fatal_error("No protocol correctly specified for remote share mount. Use protocol://server:share");
     1008            }
     1009            p++;
     1010            if (*p != '/') {
     1011                fatal_error("No protocol correctly specified for remote share mount. Use protocol://server:share");
     1012            }
     1013            /* new netfs mount */
     1014            strcpy(tmp,p);
     1015            p--;
     1016            p--;
     1017            p--;
     1018            *p = '\0';
     1019            mr_asprintf(&q,"%s",bkpinfo->netfs_mount);
     1020            bkpinfo->netfs_proto = q;
     1021            strcpy(bkpinfo->netfs_mount,tmp);
     1022        }
     1023        /* test if we specified a user */
     1024        p = strchr(bkpinfo->netfs_mount, '@');
    10001025        if (p != NULL) {
    10011026            /* User found. Store the 2 values */
    10021027            p++;
    1003             /* new NFS mount */
     1028            /* new netfs mount */
    10041029            strcpy(tmp,p);
    10051030            p--;
    10061031            *p = '\0';
    1007             mr_asprintf(&q,"%s",bkpinfo->nfs_mount);
    1008             bkpinfo->nfs_user = q;
    1009             strcpy(bkpinfo->nfs_mount,tmp);
     1032            mr_asprintf(&q,"%s",bkpinfo->netfs_mount);
     1033            bkpinfo->netfs_user = q;
     1034            strcpy(bkpinfo->netfs_mount,tmp);
    10101035        }
    10111036        sprintf(tmp, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3",
    1012                 bkpinfo->nfs_mount);
     1037                bkpinfo->netfs_mount);
    10131038        strncpy(bkpinfo->isodir,
    10141039                call_program_and_get_last_line_of_output(tmp),
    10151040                MAX_STR_LEN / 4);
    10161041        if (strlen(bkpinfo->isodir) < 3) {
    1017             log_to_screen("NFS share is not mounted. Trying to mount it for you.\n");
    1018             sprintf(tmp, "mount %s", bkpinfo->nfs_mount);
     1042            log_to_screen("Network share is not mounted. Trying to mount it for you.\n");
     1043            if (strstr(bkpinfo->netfs_proto, "sshfs")) {
     1044                sprintf(tmp, "sshfs %s", bkpinfo->netfs_mount);
     1045            } else {
     1046                sprintf(tmp, "mount %s", bkpinfo->netfs_mount);
     1047            }
    10191048            if (system(tmp)) {
    1020                 log_to_screen("Unable to mount NFS share %s. Please mount manually.\n", bkpinfo->nfs_mount);
     1049                log_to_screen("Unable to mount Network share %s. Please mount manually.\n", bkpinfo->netfs_mount);
    10211050                retval++;
    10221051            } else {
    10231052                sprintf(tmp, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3",
    1024                     bkpinfo->nfs_mount);
     1053                    bkpinfo->netfs_mount);
    10251054                strncpy(bkpinfo->isodir,
    10261055                        call_program_and_get_last_line_of_output(tmp),
     
    10281057                if (strlen(bkpinfo->isodir) < 3) {
    10291058                    retval++;
    1030                     log_to_screen("NFS share %s is strangely not mounted. Please mount manually...\n", bkpinfo->nfs_mount);
     1059                    log_to_screen("Network share %s is strangely not mounted. Please mount manually...\n", bkpinfo->netfs_mount);
    10311060                }
    10321061            }
    10331062        }
    1034         log_msg(3, "mount = %s", bkpinfo->nfs_mount);
     1063        log_msg(3, "mount = %s", bkpinfo->netfs_mount);
    10351064        log_msg(3, "isodir= %s", bkpinfo->isodir);
    10361065    }
     
    10461075    }
    10471076    if (flag_set['n']) {
    1048         bkpinfo->backup_media_type = nfs;
    1049         /* Never try to eject a NFS device */
     1077        bkpinfo->backup_media_type = netfs;
     1078        /* Never try to eject a Network device */
    10501079        bkpinfo->please_dont_eject = TRUE;
    10511080    }
     
    11551184    }
    11561185
    1157     if ((flag_set['N']) && (! bkpinfo->restore_data))       // exclude NFS mounts & devices
     1186    if ((flag_set['N']) && (! bkpinfo->restore_data))       // exclude Network mounts & devices
    11581187    {
    1159 //      strncpy(psz, list_of_NFS_devices_and_mounts(), MAX_STR_LEN);
    1160         mr_asprintf(&psz, "%s", list_of_NFS_mounts_only());
     1188        mr_asprintf(&psz, "%s", list_of_NETFS_mounts_only());
    11611189        if (bkpinfo->exclude_paths[0]) {
    11621190            strncat(bkpinfo->exclude_paths, " ", 4*MAX_STR_LEN);
     
    12331261    }
    12341262
    1235     if (flag_set['d']) {        /* backup directory (if ISO/NFS) */
     1263    if (flag_set['d']) {        /* backup directory (if ISO/NETFS) */
    12361264        if (flag_set['i']) {
    12371265            strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4);
     
    12421270            }
    12431271        } else if (flag_set['n']) {
    1244             strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN);
     1272            strncpy(bkpinfo->netfs_remote_dir, flag_val['d'], MAX_STR_LEN);
    12451273        } else {                /* backup device (if tape/CD-R/CD-RW) */
    12461274            strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4);
     
    12491277
    12501278    if ((flag_set['n']) && (! bkpinfo->restore_data)) {
    1251         mr_asprintf(&tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->nfs_remote_dir);
    1252         if (bkpinfo->nfs_user) {
    1253             sprintf(tmp, "su - %s -c \"echo hi > %s\"", bkpinfo->nfs_user, tmp1);
     1279        mr_asprintf(&tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->netfs_remote_dir);
     1280        if ((bkpinfo->netfs_user) && (strstr(bkpinfo->netfs_proto,"nfs"))) {
     1281            sprintf(tmp, "su - %s -c \"echo hi > %s\"", bkpinfo->netfs_user, tmp1);
    12541282        } else {
    12551283            sprintf(tmp, "echo hi > %s", tmp1);
     
    12591287            sprintf(tmp,
    12601288                    "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n",
    1261                     bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount);
     1289                    bkpinfo->netfs_remote_dir, bkpinfo->netfs_mount);
    12621290            log_to_screen(tmp);
    12631291        }
Note: See TracChangeset for help on using the changeset viewer.