Ignore:
Timestamp:
Sep 5, 2009, 1:28:18 AM (15 years ago)
Author:
Bruno Cornec
Message:

place the code of mondo_makefilelist before its call

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.10/mondo/src/common/libmondo-filelist.c

    r2357 r2366  
    3434/* Reference to global bkpinfo */
    3535extern struct s_bkpinfo *bkpinfo;
    36 
    37 
    38 int mondo_makefilelist(char *logfile, char *include_paths, char *excp, int differential, char *userdef_filelist);
    3936
    4037
     
    12761273 */
    12771274long g_skeleton_entries = 0;
     1275
     1276
     1277/**
     1278 * Create the filelist for the backup. It will be stored in [scratchdir]/archives/filelist.full.
     1279 * @param logfile Unused.
     1280 * @param include_paths The paths to back up, or NULL if you're using a user-defined filelist.
     1281 * @param excp The paths to NOT back up.
     1282 * @param differential The differential level (currently only 0 and 1 are supported).
     1283 * @param userdef_filelist The user-defined filelist, or NULL if you're using @p include_paths.
     1284 * @return 0, always.
     1285 * @bug @p logfile is unused.
     1286 * @bug Return value is meaningless.
     1287 */
     1288int mondo_makefilelist(char *logfile, char *include_paths, char *excp, int differential, char *userdef_filelist)
     1289{
     1290    char *p, *q;
     1291    char *sz_datefile;
     1292    char *sz_filelist;
     1293    char *exclude_paths = NULL;
     1294    char *tmp;
     1295    int i;
     1296    FILE *fout;
     1297    char *command = NULL;
     1298    time_t time_of_last_full_backup = 0;
     1299    struct stat statbuf;
     1300    char *tmp1 = NULL;
     1301    char *tmp2 = NULL;
     1302
     1303    malloc_string(tmp);
     1304    malloc_string(g_skeleton_filelist);
     1305    mr_asprintf(sz_datefile,MONDO_CACHE"/difflevel.%d" , 0);
     1306    if (!include_paths && !userdef_filelist) {
     1307        fatal_error("Please supply either include_paths or userdef_filelist");
     1308    }
     1309    // make hole for filelist
     1310    mr_asprintf(command, "mkdir -p %s/archives", bkpinfo->scratchdir);
     1311    paranoid_system(command);
     1312    mr_free(command);
     1313
     1314    mr_asprintf(sz_filelist, "%s/tmpfs/filelist.full", bkpinfo->tmpdir);
     1315    make_hole_for_file(sz_filelist);
     1316
     1317    if (differential == 0) {
     1318        // restore last good datefile if it exists
     1319        mr_asprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);
     1320        run_program_and_log_output(command, 3);
     1321        mr_free(command);
     1322
     1323        // backup last known good datefile just in case :)
     1324        if (does_file_exist(sz_datefile)) {
     1325            mr_asprintf(command, "mv -f %s %s.aborted", sz_datefile, sz_datefile);
     1326            paranoid_system(command);
     1327            mr_free(command);
     1328        }
     1329        make_hole_for_file(sz_datefile);
     1330        write_one_liner_data_file(sz_datefile,
     1331                                  call_program_and_get_last_line_of_output
     1332                                  ("date +%s"));
     1333    } else if (lstat(sz_datefile, &statbuf)) {
     1334        log_msg(2, "Warning - unable to find date of previous backup. Full backup instead.");
     1335        differential = 0;
     1336        time_of_last_full_backup = 0;
     1337    } else {
     1338        time_of_last_full_backup = statbuf.st_mtime;
     1339        log_msg(2, "Differential backup. Yay.");
     1340    }
     1341    paranoid_free(sz_datefile);
     1342
     1343// use user-specified filelist (if specified)
     1344    if (userdef_filelist) {
     1345        log_msg(1, "Using the user-specified filelist - %s - instead of calculating one", userdef_filelist);
     1346        mr_asprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);
     1347        if (run_program_and_log_output(command, 3)) {
     1348            mr_free(command);
     1349            fatal_error("Failed to copy user-specified filelist");
     1350        }
     1351        mr_free(command);
     1352    } else {
     1353        if (include_paths) {
     1354            log_msg(2, "include_paths = '%s'", include_paths);
     1355        }
     1356        log_msg(1, "Calculating filelist");
     1357        mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|ntfs-3g|fat|vfat|dos' | awk '{print $3}'"));
     1358        if (strlen(tmp2) < 1) {
     1359            mr_asprintf(tmp1," ");
     1360        } else {
     1361            log_msg(2, "Found windows FS: %s",tmp2);
     1362            mr_asprintf(tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2);
     1363            mr_free(tmp2);
     1364            mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output(tmp1));
     1365            log_msg(2, "Found windows files: %s",tmp2);
     1366        }
     1367        mr_free(tmp1);
     1368
     1369        mr_asprintf(exclude_paths, " %s %s %s %s %s . ..  " MNT_CDROM " " MNT_FLOPPY " /media /tmp  /proc /sys " MINDI_CACHE, MONDO_CACHE, (excp == NULL) ? "" : excp, tmp2, (bkpinfo->tmpdir[0] == '/' && bkpinfo->tmpdir[1] == '/') ? (bkpinfo->tmpdir + 1) : bkpinfo->tmpdir, (bkpinfo->scratchdir[0] == '/' && bkpinfo->scratchdir[1] == '/') ? (bkpinfo->scratchdir + 1) : bkpinfo->scratchdir);
     1370        mr_free(tmp2);
     1371
     1372        log_msg(2, "Excluding paths = '%s'", exclude_paths);
     1373        log_msg(2, "Generating skeleton filelist so that we can track our progress");
     1374        sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", bkpinfo->tmpdir);
     1375        make_hole_for_file(g_skeleton_filelist);
     1376        log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries);
     1377        log_msg(2, "Opening out filelist to %s", sz_filelist);
     1378        if (!(fout = fopen(sz_filelist, "w"))) {
     1379            fatal_error("Cannot openout to sz_filelist");
     1380        }
     1381        i = 0;
     1382        if ((!include_paths) || (strlen(include_paths) == 0)) {
     1383            log_msg(1, "Including only '/' in %s", sz_filelist);
     1384            open_and_list_dir("/", exclude_paths, fout,
     1385                              time_of_last_full_backup);
     1386        } else {
     1387            p = include_paths;
     1388            while (*p) {
     1389                q = next_entry(p);
     1390                log_msg(1, "Including %s in filelist %s", q, sz_filelist);
     1391                open_and_list_dir(q, exclude_paths, fout,
     1392                                  time_of_last_full_backup);
     1393                p += strlen(q);
     1394                paranoid_free(q);
     1395                while (*p == ' ') {
     1396                    p++;
     1397                }
     1398            }
     1399        }
     1400        mr_free(exclude_paths);
     1401        paranoid_fclose(fout);
     1402    }
     1403    log_msg(2, "Copying new filelist to scratchdir");
     1404    mr_asprintf(command, "mkdir -p %s/archives", bkpinfo->scratchdir);
     1405    paranoid_system(command);
     1406    mr_free(command);
     1407
     1408    mr_asprintf(command, "cp -f %s %s/archives/", sz_filelist, bkpinfo->scratchdir);
     1409    paranoid_system(command);
     1410    mr_free(command);
     1411
     1412    mr_asprintf(command, "mv -f %s %s", sz_filelist, bkpinfo->tmpdir);
     1413    paranoid_system(command);
     1414    mr_free(command);
     1415
     1416    paranoid_free(sz_filelist);
     1417    log_msg(2, "Freeing variables");
     1418    paranoid_free(tmp);
     1419    paranoid_free(g_skeleton_filelist);
     1420    log_msg(2, "Exiting");
     1421    return (0);
     1422}
     1423
     1424
    12781425
    12791426/**
     
    15291676
    15301677/**
    1531  * Create the filelist for the backup. It will be stored in [scratchdir]/archives/filelist.full.
    1532  * @param logfile Unused.
    1533  * @param include_paths The paths to back up, or NULL if you're using a user-defined filelist.
    1534  * @param excp The paths to NOT back up.
    1535  * @param differential The differential level (currently only 0 and 1 are supported).
    1536  * @param userdef_filelist The user-defined filelist, or NULL if you're using @p include_paths.
    1537  * @return 0, always.
    1538  * @bug @p logfile is unused.
    1539  * @bug Return value is meaningless.
    1540  */
    1541 int mondo_makefilelist(char *logfile, char *include_paths, char *excp, int differential, char *userdef_filelist)
    1542 {
    1543     char *p, *q;
    1544     char *sz_datefile;
    1545     char *sz_filelist;
    1546     char *exclude_paths = NULL;
    1547     char *tmp;
    1548     int i;
    1549     FILE *fout;
    1550     char *command = NULL;
    1551     time_t time_of_last_full_backup = 0;
    1552     struct stat statbuf;
    1553     char *tmp1 = NULL;
    1554     char *tmp2 = NULL;
    1555 
    1556     malloc_string(tmp);
    1557     malloc_string(g_skeleton_filelist);
    1558     mr_asprintf(sz_datefile,MONDO_CACHE"/difflevel.%d" , 0);
    1559     if (!include_paths && !userdef_filelist) {
    1560         fatal_error("Please supply either include_paths or userdef_filelist");
    1561     }
    1562     // make hole for filelist
    1563     mr_asprintf(command, "mkdir -p %s/archives", bkpinfo->scratchdir);
    1564     paranoid_system(command);
    1565     mr_free(command);
    1566 
    1567     mr_asprintf(sz_filelist, "%s/tmpfs/filelist.full", bkpinfo->tmpdir);
    1568     make_hole_for_file(sz_filelist);
    1569 
    1570     if (differential == 0) {
    1571         // restore last good datefile if it exists
    1572         mr_asprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);
    1573         run_program_and_log_output(command, 3);
    1574         mr_free(command);
    1575 
    1576         // backup last known good datefile just in case :)
    1577         if (does_file_exist(sz_datefile)) {
    1578             mr_asprintf(command, "mv -f %s %s.aborted", sz_datefile, sz_datefile);
    1579             paranoid_system(command);
    1580             mr_free(command);
    1581         }
    1582         make_hole_for_file(sz_datefile);
    1583         write_one_liner_data_file(sz_datefile,
    1584                                   call_program_and_get_last_line_of_output
    1585                                   ("date +%s"));
    1586     } else if (lstat(sz_datefile, &statbuf)) {
    1587         log_msg(2, "Warning - unable to find date of previous backup. Full backup instead.");
    1588         differential = 0;
    1589         time_of_last_full_backup = 0;
    1590     } else {
    1591         time_of_last_full_backup = statbuf.st_mtime;
    1592         log_msg(2, "Differential backup. Yay.");
    1593     }
    1594     paranoid_free(sz_datefile);
    1595 
    1596 // use user-specified filelist (if specified)
    1597     if (userdef_filelist) {
    1598         log_msg(1, "Using the user-specified filelist - %s - instead of calculating one", userdef_filelist);
    1599         mr_asprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);
    1600         if (run_program_and_log_output(command, 3)) {
    1601             mr_free(command);
    1602             fatal_error("Failed to copy user-specified filelist");
    1603         }
    1604         mr_free(command);
    1605     } else {
    1606         if (include_paths) {
    1607             log_msg(2, "include_paths = '%s'", include_paths);
    1608         }
    1609         log_msg(1, "Calculating filelist");
    1610         mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|ntfs-3g|fat|vfat|dos' | awk '{print $3}'"));
    1611         if (strlen(tmp2) < 1) {
    1612             mr_asprintf(tmp1," ");
    1613         } else {
    1614             log_msg(2, "Found windows FS: %s",tmp2);
    1615             mr_asprintf(tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2);
    1616             mr_free(tmp2);
    1617             mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output(tmp1));
    1618             log_msg(2, "Found windows files: %s",tmp2);
    1619         }
    1620         mr_free(tmp1);
    1621 
    1622         mr_asprintf(exclude_paths, " %s %s %s %s %s . ..  " MNT_CDROM " " MNT_FLOPPY " /media /tmp  /proc /sys " MINDI_CACHE, MONDO_CACHE, (excp == NULL) ? "" : excp, tmp2, (bkpinfo->tmpdir[0] == '/' && bkpinfo->tmpdir[1] == '/') ? (bkpinfo->tmpdir + 1) : bkpinfo->tmpdir, (bkpinfo->scratchdir[0] == '/' && bkpinfo->scratchdir[1] == '/') ? (bkpinfo->scratchdir + 1) : bkpinfo->scratchdir);
    1623         mr_free(tmp2);
    1624 
    1625         log_msg(2, "Excluding paths = '%s'", exclude_paths);
    1626         log_msg(2, "Generating skeleton filelist so that we can track our progress");
    1627         sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", bkpinfo->tmpdir);
    1628         make_hole_for_file(g_skeleton_filelist);
    1629         log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries);
    1630         log_msg(2, "Opening out filelist to %s", sz_filelist);
    1631         if (!(fout = fopen(sz_filelist, "w"))) {
    1632             fatal_error("Cannot openout to sz_filelist");
    1633         }
    1634         i = 0;
    1635         if ((!include_paths) || (strlen(include_paths) == 0)) {
    1636             log_msg(1, "Including only '/' in %s", sz_filelist);
    1637             open_and_list_dir("/", exclude_paths, fout,
    1638                               time_of_last_full_backup);
    1639         } else {
    1640             p = include_paths;
    1641             while (*p) {
    1642                 q = next_entry(p);
    1643                 log_msg(1, "Including %s in filelist %s", q, sz_filelist);
    1644                 open_and_list_dir(q, exclude_paths, fout,
    1645                                   time_of_last_full_backup);
    1646                 p += strlen(q);
    1647                 paranoid_free(q);
    1648                 while (*p == ' ') {
    1649                     p++;
    1650                 }
    1651             }
    1652         }
    1653         mr_free(exclude_paths);
    1654         paranoid_fclose(fout);
    1655     }
    1656     log_msg(2, "Copying new filelist to scratchdir");
    1657     mr_asprintf(command, "mkdir -p %s/archives", bkpinfo->scratchdir);
    1658     paranoid_system(command);
    1659     mr_free(command);
    1660 
    1661     mr_asprintf(command, "cp -f %s %s/archives/", sz_filelist, bkpinfo->scratchdir);
    1662     paranoid_system(command);
    1663     mr_free(command);
    1664 
    1665     mr_asprintf(command, "mv -f %s %s", sz_filelist, bkpinfo->tmpdir);
    1666     paranoid_system(command);
    1667     mr_free(command);
    1668 
    1669     paranoid_free(sz_filelist);
    1670     log_msg(2, "Freeing variables");
    1671     paranoid_free(tmp);
    1672     paranoid_free(g_skeleton_filelist);
    1673     log_msg(2, "Exiting");
    1674     return (0);
    1675 }
    1676 
    1677 
    1678 
    1679 
    1680 /**
    16811678 * Locate the string @p string_to_find in the tree rooted at @p startnode.
    16821679 * @param startnode The node containing the root of the directory tree.
Note: See TracChangeset for help on using the changeset viewer.