Changeset 2382 in MondoRescue for branches/2.2.10/mondo/src/common/libmondo-filelist.c
- Timestamp:
- Sep 10, 2009, 2:07:16 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/common/libmondo-filelist.c
r2370 r2382 1299 1299 *p = '\0'; 1300 1300 return (sz_res); 1301 }1302 1303 1304 1305 /**1306 * Create the filelist for the backup. It will be stored in [scratchdir]/archives/filelist.full.1307 * @param logfile Unused.1308 * @param include_paths The paths to back up, or NULL if you're using a user-defined filelist.1309 * @param excp The paths to NOT back up.1310 * @param differential The differential level (currently only 0 and 1 are supported).1311 * @param userdef_filelist The user-defined filelist, or NULL if you're using @p include_paths.1312 * @return 0, always.1313 * @bug @p logfile is unused.1314 * @bug Return value is meaningless.1315 */1316 int mondo_makefilelist(char *logfile, char *include_paths, char *excp, int differential, char *userdef_filelist)1317 {1318 char *p, *q;1319 char *sz_datefile;1320 char *sz_filelist;1321 char *exclude_paths = NULL;1322 char *tmp;1323 int i;1324 FILE *fout;1325 char *command = NULL;1326 time_t time_of_last_full_backup = 0;1327 struct stat statbuf;1328 char *tmp1 = NULL;1329 char *tmp2 = NULL;1330 1331 malloc_string(tmp);1332 malloc_string(g_skeleton_filelist);1333 mr_asprintf(sz_datefile,MONDO_CACHE"/difflevel.%d" , 0);1334 if (!include_paths && !userdef_filelist) {1335 fatal_error("Please supply either include_paths or userdef_filelist");1336 }1337 // make hole for filelist1338 mr_asprintf(command, "mkdir -p %s/archives", bkpinfo->scratchdir);1339 paranoid_system(command);1340 mr_free(command);1341 1342 mr_asprintf(sz_filelist, "%s/tmpfs/filelist.full", bkpinfo->tmpdir);1343 make_hole_for_file(sz_filelist);1344 1345 if (differential == 0) {1346 // restore last good datefile if it exists1347 mr_asprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);1348 run_program_and_log_output(command, 3);1349 mr_free(command);1350 1351 // backup last known good datefile just in case :)1352 if (does_file_exist(sz_datefile)) {1353 mr_asprintf(command, "mv -f %s %s.aborted", sz_datefile, sz_datefile);1354 paranoid_system(command);1355 mr_free(command);1356 }1357 make_hole_for_file(sz_datefile);1358 write_one_liner_data_file(sz_datefile,1359 call_program_and_get_last_line_of_output1360 ("date +%s"));1361 } else if (lstat(sz_datefile, &statbuf)) {1362 log_msg(2, "Warning - unable to find date of previous backup. Full backup instead.");1363 differential = 0;1364 time_of_last_full_backup = 0;1365 } else {1366 time_of_last_full_backup = statbuf.st_mtime;1367 log_msg(2, "Differential backup. Yay.");1368 }1369 paranoid_free(sz_datefile);1370 1371 // use user-specified filelist (if specified)1372 if (userdef_filelist) {1373 log_msg(1, "Using the user-specified filelist - %s - instead of calculating one", userdef_filelist);1374 mr_asprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);1375 if (run_program_and_log_output(command, 3)) {1376 mr_free(command);1377 fatal_error("Failed to copy user-specified filelist");1378 }1379 mr_free(command);1380 } else {1381 if (include_paths) {1382 log_msg(2, "include_paths = '%s'", include_paths);1383 }1384 log_msg(1, "Calculating filelist");1385 mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|ntfs-3g|fat|vfat|dos' | awk '{print $3}'"));1386 if (strlen(tmp2) < 1) {1387 mr_asprintf(tmp1," ");1388 } else {1389 log_msg(2, "Found windows FS: %s",tmp2);1390 mr_asprintf(tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2);1391 mr_free(tmp2);1392 mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output(tmp1));1393 log_msg(2, "Found windows files: %s",tmp2);1394 }1395 mr_free(tmp1);1396 1397 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);1398 mr_free(tmp2);1399 1400 log_msg(2, "Excluding paths = '%s'", exclude_paths);1401 log_msg(2, "Generating skeleton filelist so that we can track our progress");1402 sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", bkpinfo->tmpdir);1403 make_hole_for_file(g_skeleton_filelist);1404 log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries);1405 log_msg(2, "Opening out filelist to %s", sz_filelist);1406 if (!(fout = fopen(sz_filelist, "w"))) {1407 fatal_error("Cannot openout to sz_filelist");1408 }1409 i = 0;1410 if ((!include_paths) || (strlen(include_paths) == 0)) {1411 log_msg(1, "Including only '/' in %s", sz_filelist);1412 open_and_list_dir("/", exclude_paths, fout,1413 time_of_last_full_backup);1414 } else {1415 p = include_paths;1416 while (*p) {1417 q = next_entry(p);1418 log_msg(1, "Including %s in filelist %s", q, sz_filelist);1419 open_and_list_dir(q, exclude_paths, fout,1420 time_of_last_full_backup);1421 p += strlen(q);1422 paranoid_free(q);1423 while (*p == ' ') {1424 p++;1425 }1426 }1427 }1428 mr_free(exclude_paths);1429 paranoid_fclose(fout);1430 }1431 log_msg(2, "Copying new filelist to scratchdir");1432 mr_asprintf(command, "mkdir -p %s/archives", bkpinfo->scratchdir);1433 paranoid_system(command);1434 mr_free(command);1435 1436 mr_asprintf(command, "cp -f %s %s/archives/", sz_filelist, bkpinfo->scratchdir);1437 paranoid_system(command);1438 mr_free(command);1439 1440 mr_asprintf(command, "mv -f %s %s", sz_filelist, bkpinfo->tmpdir);1441 paranoid_system(command);1442 mr_free(command);1443 1444 paranoid_free(sz_filelist);1445 log_msg(2, "Freeing variables");1446 paranoid_free(tmp);1447 paranoid_free(g_skeleton_filelist);1448 log_msg(2, "Exiting");1449 return (0);1450 }1451 1452 1453 1454 /**1455 * Wrapper around mondo_makefilelist().1456 * @param bkpinfo The backup information structure. Fields used:1457 * - @c bkpinfo->differential1458 * - @c bkpinfo->exclude_paths1459 * - @c bkpinfo->include_paths1460 * - @c bkpinfo->make_filelist1461 * - @c bkpinfo->scratchdir1462 * - @c bkpinfo->tmpdir1463 * @return 0 for success, nonzero for failure.1464 * @see mondo_makefilelist1465 */1466 int prepare_filelist()1467 {1468 1469 /*@ int **************************************************** */1470 int res = 0;1471 1472 assert(bkpinfo != NULL);1473 log_it("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir, bkpinfo->scratchdir);1474 if (bkpinfo->make_filelist) {1475 mvaddstr_and_log_it(g_currentY, 0,1476 "Making catalog of files to be backed up");1477 } else {1478 mvaddstr_and_log_it(g_currentY, 0,1479 "Using supplied catalog of files to be backed up");1480 }1481 1482 if (bkpinfo->make_filelist) {1483 res =1484 mondo_makefilelist(MONDO_LOGFILE, bkpinfo->include_paths, bkpinfo->exclude_paths, bkpinfo->differential, NULL);1485 } else {1486 res =1487 mondo_makefilelist(MONDO_LOGFILE, NULL, bkpinfo->exclude_paths, bkpinfo->differential, bkpinfo->include_paths);1488 }1489 1490 if (res) {1491 log_OS_error("Call to mondo_makefilelist failed");1492 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");1493 } else {1494 mvaddstr_and_log_it(g_currentY++, 74, "Done.");1495 }1496 return (res);1497 1301 } 1498 1302 … … 1675 1479 1676 1480 1481 1482 /** 1483 * Create the filelist for the backup. It will be stored in [scratchdir]/archives/filelist.full. 1484 * @param logfile Unused. 1485 * @param include_paths The paths to back up, or NULL if you're using a user-defined filelist. 1486 * @param excp The paths to NOT back up. 1487 * @param differential The differential level (currently only 0 and 1 are supported). 1488 * @param userdef_filelist The user-defined filelist, or NULL if you're using @p include_paths. 1489 * @return 0, always. 1490 * @bug @p logfile is unused. 1491 * @bug Return value is meaningless. 1492 */ 1493 int mondo_makefilelist(char *logfile, char *include_paths, char *excp, int differential, char *userdef_filelist) 1494 { 1495 char *p, *q; 1496 char *sz_datefile; 1497 char *sz_filelist; 1498 char *exclude_paths = NULL; 1499 char *tmp; 1500 int i; 1501 FILE *fout; 1502 char *command = NULL; 1503 time_t time_of_last_full_backup = 0; 1504 struct stat statbuf; 1505 char *tmp1 = NULL; 1506 char *tmp2 = NULL; 1507 1508 malloc_string(tmp); 1509 malloc_string(g_skeleton_filelist); 1510 mr_asprintf(sz_datefile,MONDO_CACHE"/difflevel.%d" , 0); 1511 if (!include_paths && !userdef_filelist) { 1512 fatal_error("Please supply either include_paths or userdef_filelist"); 1513 } 1514 // make hole for filelist 1515 mr_asprintf(command, "mkdir -p %s/archives", bkpinfo->scratchdir); 1516 paranoid_system(command); 1517 mr_free(command); 1518 1519 mr_asprintf(sz_filelist, "%s/tmpfs/filelist.full", bkpinfo->tmpdir); 1520 make_hole_for_file(sz_filelist); 1521 1522 if (differential == 0) { 1523 // restore last good datefile if it exists 1524 mr_asprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile); 1525 run_program_and_log_output(command, 3); 1526 mr_free(command); 1527 1528 // backup last known good datefile just in case :) 1529 if (does_file_exist(sz_datefile)) { 1530 mr_asprintf(command, "mv -f %s %s.aborted", sz_datefile, sz_datefile); 1531 paranoid_system(command); 1532 mr_free(command); 1533 } 1534 make_hole_for_file(sz_datefile); 1535 write_one_liner_data_file(sz_datefile, 1536 call_program_and_get_last_line_of_output 1537 ("date +%s")); 1538 } else if (lstat(sz_datefile, &statbuf)) { 1539 log_msg(2, "Warning - unable to find date of previous backup. Full backup instead."); 1540 differential = 0; 1541 time_of_last_full_backup = 0; 1542 } else { 1543 time_of_last_full_backup = statbuf.st_mtime; 1544 log_msg(2, "Differential backup. Yay."); 1545 } 1546 paranoid_free(sz_datefile); 1547 1548 // use user-specified filelist (if specified) 1549 if (userdef_filelist) { 1550 log_msg(1, "Using the user-specified filelist - %s - instead of calculating one", userdef_filelist); 1551 mr_asprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist); 1552 if (run_program_and_log_output(command, 3)) { 1553 mr_free(command); 1554 fatal_error("Failed to copy user-specified filelist"); 1555 } 1556 mr_free(command); 1557 } else { 1558 if (include_paths) { 1559 log_msg(2, "include_paths = '%s'", include_paths); 1560 } 1561 log_msg(1, "Calculating filelist"); 1562 mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|ntfs-3g|fat|vfat|dos' | awk '{print $3}'")); 1563 if (strlen(tmp2) < 1) { 1564 mr_asprintf(tmp1," "); 1565 } else { 1566 log_msg(2, "Found windows FS: %s",tmp2); 1567 mr_asprintf(tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2); 1568 mr_free(tmp2); 1569 mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output(tmp1)); 1570 log_msg(2, "Found windows files: %s",tmp2); 1571 } 1572 mr_free(tmp1); 1573 1574 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); 1575 mr_free(tmp2); 1576 1577 log_msg(2, "Excluding paths = '%s'", exclude_paths); 1578 log_msg(2, "Generating skeleton filelist so that we can track our progress"); 1579 sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", bkpinfo->tmpdir); 1580 make_hole_for_file(g_skeleton_filelist); 1581 log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries); 1582 log_msg(2, "Opening out filelist to %s", sz_filelist); 1583 if (!(fout = fopen(sz_filelist, "w"))) { 1584 fatal_error("Cannot openout to sz_filelist"); 1585 } 1586 i = 0; 1587 if ((!include_paths) || (strlen(include_paths) == 0)) { 1588 log_msg(1, "Including only '/' in %s", sz_filelist); 1589 open_and_list_dir("/", exclude_paths, fout, 1590 time_of_last_full_backup); 1591 } else { 1592 p = include_paths; 1593 while (*p) { 1594 q = next_entry(p); 1595 log_msg(1, "Including %s in filelist %s", q, sz_filelist); 1596 open_and_list_dir(q, exclude_paths, fout, 1597 time_of_last_full_backup); 1598 p += strlen(q); 1599 paranoid_free(q); 1600 while (*p == ' ') { 1601 p++; 1602 } 1603 } 1604 } 1605 mr_free(exclude_paths); 1606 paranoid_fclose(fout); 1607 } 1608 log_msg(2, "Copying new filelist to scratchdir"); 1609 mr_asprintf(command, "mkdir -p %s/archives", bkpinfo->scratchdir); 1610 paranoid_system(command); 1611 mr_free(command); 1612 1613 mr_asprintf(command, "cp -f %s %s/archives/", sz_filelist, bkpinfo->scratchdir); 1614 paranoid_system(command); 1615 mr_free(command); 1616 1617 mr_asprintf(command, "mv -f %s %s", sz_filelist, bkpinfo->tmpdir); 1618 paranoid_system(command); 1619 mr_free(command); 1620 1621 paranoid_free(sz_filelist); 1622 log_msg(2, "Freeing variables"); 1623 paranoid_free(tmp); 1624 paranoid_free(g_skeleton_filelist); 1625 log_msg(2, "Exiting"); 1626 return (0); 1627 } 1628 1629 1630 1631 /** 1632 * Wrapper around mondo_makefilelist(). 1633 * @param bkpinfo The backup information structure. Fields used: 1634 * - @c bkpinfo->differential 1635 * - @c bkpinfo->exclude_paths 1636 * - @c bkpinfo->include_paths 1637 * - @c bkpinfo->make_filelist 1638 * - @c bkpinfo->scratchdir 1639 * - @c bkpinfo->tmpdir 1640 * @return 0 for success, nonzero for failure. 1641 * @see mondo_makefilelist 1642 */ 1643 int prepare_filelist() 1644 { 1645 1646 /*@ int **************************************************** */ 1647 int res = 0; 1648 1649 assert(bkpinfo != NULL); 1650 log_it("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir, bkpinfo->scratchdir); 1651 if (bkpinfo->make_filelist) { 1652 mvaddstr_and_log_it(g_currentY, 0, 1653 "Making catalog of files to be backed up"); 1654 } else { 1655 mvaddstr_and_log_it(g_currentY, 0, 1656 "Using supplied catalog of files to be backed up"); 1657 } 1658 1659 if (bkpinfo->make_filelist) { 1660 res = 1661 mondo_makefilelist(MONDO_LOGFILE, bkpinfo->include_paths, bkpinfo->exclude_paths, bkpinfo->differential, NULL); 1662 } else { 1663 res = 1664 mondo_makefilelist(MONDO_LOGFILE, NULL, bkpinfo->exclude_paths, bkpinfo->differential, bkpinfo->include_paths); 1665 } 1666 1667 if (res) { 1668 log_OS_error("Call to mondo_makefilelist failed"); 1669 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1670 } else { 1671 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1672 } 1673 return (res); 1674 } 1675 1676 1677 1677 /** 1678 1678 * Locate the string @p string_to_find in the tree rooted at @p startnode.
Note:
See TracChangeset
for help on using the changeset viewer.