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-devices.c

    r2368 r2380  
    5454 */
    5555bool g_restoring_live_from_cd = FALSE;
    56 bool g_restoring_live_from_nfs = FALSE;
     56bool g_restoring_live_from_netfs = FALSE;
    5757
    5858extern t_bkptype g_backup_media_type;   // set by main()
     
    179179        strcpy(output, "cdstream");
    180180        break;
    181     case nfs:
    182         strcpy(output, "nfs");
     181    case netfs:
     182        strcpy(output, "netfs");
    183183        break;
    184184    case tape:
     
    13761376    run_program_and_log_output(tmp, 5);
    13771377    if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso
    1378         || bkpinfo->backup_media_type == nfs) {
     1378        || bkpinfo->backup_media_type == netfs) {
    13791379        log_msg(3, "Remounting CD");
    13801380        g_ISO_restore_mode = TRUE;
     
    13871387        (void)system(tmp);
    13881388        sprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir,
    1389                 bkpinfo->nfs_remote_dir, bkpinfo->prefix,
     1389                bkpinfo->netfs_remote_dir, bkpinfo->prefix,
    13901390                cd_number_i_want);
    13911391        if (!does_file_exist(tmp)) {
    13921392            sprintf(tmp, "%s/isodir/%s/%s-%d.iso", bkpinfo->tmpdir,
    1393                     bkpinfo->nfs_remote_dir, bkpinfo->prefix,
     1393                    bkpinfo->netfs_remote_dir, bkpinfo->prefix,
    13941394                    cd_number_i_want);
    13951395            if (does_file_exist(tmp)) {
     
    14861486    bkpinfo->nonbootable_backup = FALSE;
    14871487
    1488     // Tape, CD, NFS, ...?
     1488    // Tape, CD, NETFS, ...?
    14891489    srandom(getpid());
    14901490    bkpinfo->backup_media_type =
     
    17261726
    17271727
    1728     case nfs:
    1729         /* Never try to eject a NFS device */
     1728    case netfs:
     1729        /* Never try to eject a NETFS device */
    17301730        bkpinfo->please_dont_eject = TRUE;
    17311731
    1732         /* Initiate bkpinfo nfs_mount path from running environment if not already done */
    1733         if (!bkpinfo->nfs_mount[0]) {
    1734             strcpy(bkpinfo->nfs_mount,
     1732        /* Initiate bkpinfo netfs_mount path from running environment if not already done */
     1733        if (!bkpinfo->netfs_mount[0]) {
     1734            strcpy(bkpinfo->netfs_mount,
    17351735                   call_program_and_get_last_line_of_output
    17361736                   ("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
     
    17431743        {
    17441744            if (!popup_and_get_string
    1745                 ("NFS dir.",
     1745                ("Network shared dir.",
    17461746                 "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.)",
    1747                  bkpinfo->nfs_mount, MAX_STR_LEN / 4)) {
     1747                 bkpinfo->netfs_mount, MAX_STR_LEN / 4)) {
    17481748                log_to_screen("User has chosen not to backup the PC");
    17491749                finish(1);
     
    17581758            // check whether already mounted - we better remove
    17591759            // surrounding spaces and trailing '/' for this
    1760             strip_spaces(bkpinfo->nfs_mount);
    1761             if (bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] == '/')
    1762                 bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] = '\0';
     1760            strip_spaces(bkpinfo->netfs_mount);
     1761            if (bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] == '/')
     1762                bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] = '\0';
    17631763            sprintf(command, "mount | grep \"%s \" | cut -d' ' -f3",
    1764                     bkpinfo->nfs_mount);
     1764                    bkpinfo->netfs_mount);
    17651765            strcpy(bkpinfo->isodir,
    17661766                   call_program_and_get_last_line_of_output(command));
     
    17881788            (void)system(command);
    17891789            if (!popup_and_get_string
    1790                 ("NFS share", "Which remote NFS share should I mount?",
    1791                  bkpinfo->nfs_mount, MAX_STR_LEN)) {
     1790                ("Network share", "Which remote share should I mount?",
     1791                 bkpinfo->netfs_mount, MAX_STR_LEN)) {
    17921792                log_to_screen("User has chosen not to backup the PC");
    17931793                finish(1);
     
    17951795        }
    17961796        /* Initiate bkpinfo isodir path from running environment if mount already done */
    1797         if (is_this_device_mounted(bkpinfo->nfs_mount)) {
     1797        if (is_this_device_mounted(bkpinfo->netfs_mount)) {
    17981798            strcpy(bkpinfo->isodir,
    17991799                   call_program_and_get_last_line_of_output
    18001800                   ("mount | grep \":\" | cut -d' ' -f3 | head -n1"));
    18011801        } else {
    1802             sprintf(bkpinfo->isodir, "%s/nfsdir", bkpinfo->tmpdir);
     1802            sprintf(bkpinfo->isodir, "%s/netfsdir", bkpinfo->tmpdir);
    18031803            sprintf(command, "mkdir -p %s", bkpinfo->isodir);
    18041804            run_program_and_log_output(command, 5);
    18051805            if (bkpinfo->restore_data) {
    1806                 mr_asprintf(&tmp, "mount -t nfs -o nolock,ro %s %s", bkpinfo->nfs_mount, bkpinfo->isodir);
     1806                if (strstr(bkpinfo->netfs_proto, "sshfs")) {
     1807                    mr_asprintf(&tmp, "sshfs -o ro %s %s", bkpinfo->netfs_mount, bkpinfo->isodir);
     1808                } else {
     1809                    mr_asprintf(&tmp, "mount -t %s -o nolock,ro %s %s", bkpinfo->netfs_proto, bkpinfo->netfs_mount, bkpinfo->isodir);
     1810                }
    18071811            } else {
    1808                 mr_asprintf(&tmp, "mount -t nfs -o nolock %s %s", bkpinfo->nfs_mount, bkpinfo->isodir);
     1812                if (strstr(bkpinfo->netfs_proto, "sshfs")) {
     1813                    mr_asprintf(&tmp, "sshfs %s %s", bkpinfo->netfs_mount, bkpinfo->isodir);
     1814                } else {
     1815                    mr_asprintf(&tmp, "mount -t %s -o nolock %s %s", bkpinfo->netfs_proto, bkpinfo->netfs_mount, bkpinfo->isodir);
     1816                }
    18091817            }
    18101818            run_program_and_log_output(tmp, 3);
     
    18141822            strcpy(g_selfmounted_isodir, bkpinfo->isodir);
    18151823        }
    1816         if (!is_this_device_mounted(bkpinfo->nfs_mount)) {
     1824        if (!is_this_device_mounted(bkpinfo->netfs_mount)) {
    18171825            popup_and_OK
    18181826                ("Please mount that partition before you try to backup to or restore from it.");
    18191827            finish(1);
    18201828        }
    1821         strcpy(tmp1, bkpinfo->nfs_remote_dir);
     1829        strcpy(tmp1, bkpinfo->netfs_remote_dir);
    18221830        if (!popup_and_get_string
    18231831            ("Directory", "Which directory within that mountpoint?", tmp1,
     
    18261834            finish(1);
    18271835        }
    1828         strcpy(bkpinfo->nfs_remote_dir, tmp1);
     1836        strcpy(bkpinfo->netfs_remote_dir, tmp1);
    18291837
    18301838        // check whether writable - we better remove surrounding spaces for this
    1831         strip_spaces(bkpinfo->nfs_remote_dir);
     1839        strip_spaces(bkpinfo->netfs_remote_dir);
    18321840
    18331841        if (!popup_and_get_string
     
    18431851            bkpinfo->media_size[i] = 650;
    18441852        }
    1845         log_msg(3, "Just set nfs_remote_dir to %s",
    1846                 bkpinfo->nfs_remote_dir);
     1853        log_msg(3, "Just set netfs_remote_dir to %s",
     1854                bkpinfo->netfs_remote_dir);
    18471855        log_msg(3, "isodir is still %s", bkpinfo->isodir);
    18481856        break;
     
    19611969            finish(1);
    19621970        }
    1963         mr_asprintf(&tmp, "%s", list_of_NFS_mounts_only());
     1971        mr_asprintf(&tmp, "%s", list_of_NETFS_mounts_only());
    19641972        if (strlen(tmp) > 2) {
    19651973            if (bkpinfo->exclude_paths[0]) {
     
    20332041
    20342042    if (bkpinfo->backup_media_type == iso
    2035         || bkpinfo->backup_media_type == nfs) {
     2043        || bkpinfo->backup_media_type == netfs) {
    20362044        g_ISO_restore_mode = TRUE;
    20372045    }
     
    20392047// skip
    20402048#else
    2041     if (bkpinfo->backup_media_type == nfs) {
    2042         log_msg(3, "I think the NFS mount is mounted at %s",
     2049    if (bkpinfo->backup_media_type == netfs) {
     2050        log_msg(3, "I think the Remote mount is mounted at %s",
    20432051                bkpinfo->isodir);
    20442052    }
    20452053    log_it("isodir = %s", bkpinfo->isodir);
    2046     log_it("nfs_mount = '%s'", bkpinfo->nfs_mount);
    2047     if (bkpinfo->nfs_user) {
    2048         log_it("nfs_user = '%s'", bkpinfo->nfs_user);
     2054    log_it("netfs_mount = '%s'", bkpinfo->netfs_mount);
     2055    log_it("netfs_proto = '%s'", bkpinfo->netfs_proto);
     2056    if (bkpinfo->netfs_user) {
     2057        log_it("netfs_user = '%s'", bkpinfo->netfs_user);
    20492058    }
    20502059#endif
     
    20872096 */
    20882097/**
    2089  * Get a space-separated list of NFS devices and mounts.
     2098 * Get a space-separated list of NETFS devices and mounts.
    20902099 * @return The list created.
    20912100 * @note The return value points to static data that will be overwritten with each call.
    20922101 */
    2093 char *list_of_NFS_devices_and_mounts(void)
     2102char *list_of_NETFS_devices_and_mounts(void)
    20942103{
    20952104    char *exclude_these_devices = NULL;
     
    20972106    static char result_sz[1024];
    20982107
    2099     mr_asprintf(&exclude_these_directories,"%s",list_of_NFS_mounts_only());
    2100     mr_asprintf(&exclude_these_devices,"%s", call_program_and_get_last_line_of_output("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|nfs|nfs4|smbfs|cifs|afs|gfs|ocfs|ocfs2|mvfs|nsspool|nsvol) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2108    mr_asprintf(&exclude_these_directories,"%s",list_of_NETFS_mounts_only());
     2109    mr_asprintf(&exclude_these_devices,"%s", call_program_and_get_last_line_of_output("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|sshfs|nfs|nfs4|smbfs|cifs|afs|gfs|ocfs|ocfs2|mvfs|nsspool|nsvol) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
    21012110    snprintf(result_sz, 1023, "%s %s", exclude_these_directories, exclude_these_devices);
    21022111    mr_free(exclude_these_devices);
     
    21092118
    21102119/**
    2111  * Get a space-separated list of NFS mounts.
     2120 * Get a space-separated list of NETFS mounts.
    21122121 * @return The list created.
    21132122 * @note The return value points to static data that will be overwritten with each call.
    21142123 * @bug Even though we only want the mounts, the devices are still checked.
    21152124 */
    2116 char *list_of_NFS_mounts_only(void)
     2125char *list_of_NETFS_mounts_only(void)
    21172126{
    21182127    char *exclude_these_directories = NULL;
    21192128    static char result_sz[512];
    21202129
    2121     mr_asprintf(&exclude_these_directories,"%s", call_program_and_get_last_line_of_output("mount -t coda,ncpfs,nfs,nfs4,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2130    mr_asprintf(&exclude_these_directories,"%s", call_program_and_get_last_line_of_output("mount -t coda,ncpfs,fuse.sshfs,nfs,nfs4,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
    21222131    snprintf(result_sz, 511, "%s", exclude_these_directories);
    21232132    mr_free(exclude_these_directories);
     
    21762185    mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -t nonfs,msdosfs,ntfs,ntfs-3g,smbfs,smb,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
    21772186#else
    2178     mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -x nfs -x nfs4 -x vfat -x ntfs -x ntfs-3g -x smbfs -x smb -x cifs -x afs -x gfs -x ocfs -x ocfs2 -x mvfs -x nsspool -x nssvol -x iso9660 | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
     2187    mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -x nfs -x nfs4 -x fuse.sshfs -x vfat -x ntfs -x ntfs-3g -x smbfs -x smb -x cifs -x afs -x gfs -x ocfs -x ocfs2 -x mvfs -x nsspool -x nssvol -x iso9660 | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
    21792188#endif
    21802189
     
    26062615    malloc_string(command);
    26072616    malloc_string(fdisk);
    2608     log_msg(0, "Looking for partition table format type");
    26092617    sprintf(fdisk, "/sbin/parted2fdisk");
    2610     log_msg(1, "Using %s", fdisk);
    26112618    sprintf(command, "%s -l %s | grep 'EFI GPT'", fdisk, drive);
    26122619    mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
Note: See TracChangeset for help on using the changeset viewer.