Ignore:
Timestamp:
Oct 22, 2008, 7:50:04 PM (15 years ago)
Author:
Bruno Cornec
Message:
  • Remove useless function extract_config_file_from_ramdisk()
  • Avoid erasing mountlist and I-want-my-lvm when already existing (based on ideas from Benoit Donnette bdonnette_at_linagora.com)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.8/mondo/src/mondorestore/mondo-rstr-tools.c

    r2030 r2049  
    202202* @ingroup restoreUtilityGroup
    203203*/
    204 int
    205 extract_config_file_from_ramdisk(char *ramdisk_fname,
    206                          char *output_cfg_file,
    207                          char *output_mountlist_file)
    208 {
    209 char *mountpt;
    210 char *command;
    211 char *orig_fname;
    212 int retval = 0;
    213 
    214 assert(bkpinfo != NULL);
    215 malloc_string(mountpt);
    216 malloc_string(command);
    217 malloc_string(orig_fname);
    218 assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname);
    219 assert_string_is_neither_NULL_nor_zerolength(output_cfg_file);
    220 assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file);
    221 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
    222 sprintf(command, "mkdir -p %s", mountpt);
    223 run_program_and_log_output(command, FALSE);
    224 sprintf(command, "gzip -dc %s > %s/mindi.rd 2> /dev/null",
    225     ramdisk_fname, bkpinfo->tmpdir);
    226 
    227 run_program_and_log_output(command, FALSE);
    228 sprintf(command, "umount %s", mountpt);
    229 
    230 run_program_and_log_output(command, FALSE);
    231 
    232 sprintf(command, "mount -o loop %s/mindi.rd -t ext2 %s",
    233     bkpinfo->tmpdir, mountpt);
    234 
    235 run_program_and_log_output(command, FALSE);
    236 
    237 sprintf(command, "mkdir -p %s/tmp", bkpinfo->tmpdir);
    238 
    239 run_program_and_log_output(command, FALSE);
    240 
    241 sprintf(command, "cp -f %s/%s %s",  // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg
    242     mountpt, g_mondo_cfg_file, output_cfg_file);
    243 run_program_and_log_output(command, FALSE);
    244 
    245 sprintf(orig_fname, "%s/%s", mountpt, g_mountlist_fname);
    246 if (does_file_exist(orig_fname)) {
    247 sprintf(command, "cp -f %s %s", orig_fname, output_mountlist_file);
    248 run_program_and_log_output(command, FALSE);
    249 }
    250 sprintf(command, "umount %s", mountpt);
    251 run_program_and_log_output(command, FALSE);
    252 if (!does_file_exist(output_cfg_file)
    253 || (!does_file_exist(output_mountlist_file)
    254     && does_file_exist(orig_fname))) {
    255 log_msg(2, "Failed to extract %s and/or %s from ramdisk",
    256         output_cfg_file, output_mountlist_file);
    257 retval = 1;
    258 } else {
    259 retval = 0;
    260 }
    261 paranoid_free(mountpt);
    262 paranoid_free(command);
    263 paranoid_free(orig_fname);
    264 return (retval);
    265 
    266 }
    267 
    268 
    269 
    270204
    271205/**
     
    11861120int res = 0;
    11871121pid_t pid;
     1122bool extract_mountlist_stub = FALSE;
    11881123
    11891124assert(bkpinfo != NULL);
    11901125malloc_string(command);
    11911126malloc_string(tmp);
     1127
     1128/* If those files already exist, do not overwrite them later on */
     1129if (does_file_exist("/"MOUNTLIST_FNAME_STUB)) {
     1130    extract_mountlist_stub = FALSE;
     1131} else {
     1132    extract_mountlist_stub = TRUE;
     1133}
    11921134
    11931135if (does_file_exist(g_filelist_full)
     
    12041146    unlink("/tmp/filelist.full");
    12051147    unlink(FILELIST_FULL_STUB);
    1206     unlink("/" IWANTMYLVM_STUB);
    12071148    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    12081149        sprintf(command,
     
    12131154            BIGGIELIST_TXT_STUB,
    12141155            FILELIST_FULL_STUB,
    1215             IWANTMYLVM_STUB, 
     1156            IWANTMYLVM_STUB,
    12161157            MONDO_CFG_FILE_STUB);
    12171158        log_msg(1, "tarcommand = %s", command);
     
    12281169                FILELIST_FULL_STUB,
    12291170                IWANTMYLVM_STUB,
    1230                 MONDO_CFG_FILE_STUB);
     1171                MONDO_CFG_FILE_STUB);
    12311172            log_msg(1, "tarcommand = %s", command);
    12321173            run_program_and_log_output(command, 1);
     
    12451186            BIGGIELIST_TXT_STUB,
    12461187            FILELIST_FULL_STUB,
    1247             IWANTMYLVM_STUB, 
     1188            IWANTMYLVM_STUB,
    12481189            MONDO_CFG_FILE_STUB);
    12491190
     
    12591200                BIGGIELIST_TXT_STUB,
    12601201                FILELIST_FULL_STUB,
    1261                 IWANTMYLVM_STUB, 
     1202                IWANTMYLVM_STUB,
    12621203                MONDO_CFG_FILE_STUB);
    12631204
     
    12901231    if (am_I_in_disaster_recovery_mode()
    12911232    &&
     1233    /* If it was there, do not overwrite it */
     1234    (extract_mountlist_stub)
     1235    &&
    12921236    ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
    12931237    {
     
    12981242
    12991243    chdir(tmp);
    1300    
     1244
    13011245    if (!does_file_exist(g_biggielist_txt)) {
    13021246        log_msg(1, "Warning - %s not found", g_biggielist_txt);
     
    22312175    char *ramdisk_fname;
    22322176    char *mountlist_file;
     2177    bool extract_mountlist_stub;
     2178    bool extract_i_want_my_lvm;
    22332179
    22342180    bool try_plan_B;
     
    22522198    unlink(FILELIST_FULL_STUB);
    22532199    unlink(BIGGIELIST_TXT_STUB);
    2254     unlink(IWANTMYLVM_STUB);
    22552200    sprintf(command, "mkdir -p %s", mountpt);
    22562201    run_program_and_log_output(command, FALSE);
    22572202
    2258 //   unlink( "tmp/mondo-restore.cfg" ); // superfluous, surely?
    2259 
    22602203    sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
    2261     sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir,
    2262             MOUNTLIST_FNAME_STUB);
     2204    sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
    22632205    //   make_hole_for_file( cfg_file );
    22642206    //   make_hole_for_file( mountlist_file);
     
    23162258            }
    23172259        } else {
     2260                if (does_file_exist("/"MOUNTLIST_FNAME_STUB)) {
     2261                    extract_mountlist_stub = FALSE;
     2262                } else {
     2263                    extract_mountlist_stub = TRUE;
     2264                }
     2265                if (does_file_exist("/"IWANTMYLVM_STUB)) {
     2266                    extract_i_want_my_lvm = FALSE;
     2267                } else {
     2268                    extract_i_want_my_lvm = TRUE;
     2269                }
     2270
    23182271                log_msg(2,
    23192272                        "gcffa --- Plan B, a.k.a. untarring some file from all.tar.gz");
     
    23482301        }
    23492302        sprintf(command, "cp -f %s/%s %s",
    2350                 call_program_and_get_last_line_of_output("pwd"),
    2351                 MOUNTLIST_FNAME_STUB, mountlist_file);
     2303            call_program_and_get_last_line_of_output("pwd"),
     2304            MOUNTLIST_FNAME_STUB, mountlist_file);
    23522305        iamhere(command);
    2353         if (strcmp(tmp, cfg_file)
    2354             && run_program_and_log_output(command, 1)) {
    2355             log_msg(1, "Failed to get mountlist");
    2356         } else {
    2357             log_msg(1, "Got mountlist too");
    2358             sprintf(command, "cp -f %s %s", mountlist_file,
    2359                     g_mountlist_fname);
    2360             if (run_program_and_log_output(command, 1)) {
    2361                 log_msg(1, "Failed to copy mountlist to /tmp");
     2306        if (extract_mountlist_stub) {
     2307            if (strcmp(tmp, cfg_file)
     2308                && run_program_and_log_output(command, 1)) {
     2309                log_msg(1, "Failed to get mountlist");
    23622310            } else {
    2363                 log_msg(1, "Copied mountlist to /tmp as well OK");
    2364                 sprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
    2365                 run_program_and_log_output(command, 1);
     2311                log_msg(1, "Got mountlist too");
     2312                sprintf(command, "cp -f %s %s", mountlist_file,
     2313                        g_mountlist_fname);
     2314                if (run_program_and_log_output(command, 1)) {
     2315                    log_msg(1, "Failed to copy mountlist to /tmp");
     2316                } else {
     2317                    log_msg(1, "Copied mountlist to /tmp as well OK");
     2318                    sprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
     2319                    run_program_and_log_output(command, 1);
     2320                }
    23662321            }
    23672322        }
     
    23802335        log_to_screen("...but not mountlist.txt - a pity, really...");
    23812336    }
    2382 /* start SAH */
    23832337    else {
    2384         sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,
    2385                 bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
    2386         run_program_and_log_output(command, FALSE);
    2387     }
    2388 /*--commented out by SAH
    2389   sprintf( command, "cp -f %s %s/%s", cfg_file, bkpinfo->tmpdir, MONDO_CFG_FILE_STUB );
    2390   run_program_and_log_output( command, FALSE );
    2391   sprintf( command, "cp -f %s %s/%s", mountlist_file, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB );
    2392   run_program_and_log_output( command, FALSE );
    2393 */
    2394 /* end SAH */
     2338            /* Is this code really useful ??? */
     2339        if (extract_mountlist_stub) {
     2340            sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,
     2341                    bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
     2342            run_program_and_log_output(command, FALSE);
     2343        }
     2344    }
    23952345
    23962346    sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
    23972347    run_program_and_log_output(command, FALSE);
    2398     sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
    2399     run_program_and_log_output(command, FALSE);
     2348    if (extract_mountlist_stub) {
     2349        sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
     2350        run_program_and_log_output(command, FALSE);
     2351    }
    24002352    sprintf(command, "cp -f etc/raidtab /etc/");
    24012353    run_program_and_log_output(command, FALSE);
    2402     sprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
    2403     run_program_and_log_output(command, FALSE);
     2354    if (extract_i_want_my_lvm) {
     2355        sprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
     2356        run_program_and_log_output(command, FALSE);
     2357    }
    24042358    g_backup_media_type = bkpinfo->backup_media_type;
    24052359    paranoid_free(device);
Note: See TracChangeset for help on using the changeset viewer.