Changeset 2366 in MondoRescue for branches/2.2.9/mondo/src/common
- Timestamp:
- Sep 5, 2009, 1:28:18 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mondo/src/common/libmondo-filelist.c
r2290 r2366 34 34 /* Reference to global bkpinfo */ 35 35 extern struct s_bkpinfo *bkpinfo; 36 37 38 int mondo_makefilelist(char *logfile, char *tmpdir, char *scratchdir,39 char *include_paths, char *excp, int differential,40 char *userdef_filelist);41 36 42 37 … … 1269 1264 } 1270 1265 } 1266 } 1267 1268 1269 1270 /** 1271 * Create the filelist for the backup. It will be stored in [scratchdir]/archives/filelist.full. 1272 * @param logfile Unused. 1273 * @param tmpdir The tmpdir of the backup. 1274 * @param scratchdir The scratchdir of the backup. 1275 * @param include_paths The paths to back up, or NULL if you're using a user-defined filelist. 1276 * @param excp The paths to NOT back up. 1277 * @param differential The differential level (currently only 0 and 1 are supported). 1278 * @param userdef_filelist The user-defined filelist, or NULL if you're using @p include_paths. 1279 * @return 0, always. 1280 * @bug @p logfile is unused. 1281 * @bug Return value is meaningless. 1282 */ 1283 int mondo_makefilelist(char *logfile, char *tmpdir, char *scratchdir, 1284 char *include_paths, char *excp, int differential, 1285 char *userdef_filelist) 1286 { 1287 char *p, *q; 1288 char *sz_datefile; 1289 char *sz_filelist, *exclude_paths, *tmp; 1290 int i; 1291 FILE *fout; 1292 char *command; 1293 time_t time_of_last_full_backup = 0; 1294 struct stat statbuf; 1295 char *tmp1 = NULL; 1296 char *tmp2 = NULL; 1297 1298 malloc_string(command); 1299 malloc_string(tmp); 1300 malloc_string(g_skeleton_filelist); 1301 if (!(exclude_paths = malloc(8*MAX_STR_LEN))) { 1302 fatal_error("Cannot malloc exclude_paths"); 1303 } 1304 mr_asprintf(&sz_datefile,MONDO_CACHE"/difflevel.%d" , 0); 1305 if (!include_paths && !userdef_filelist) { 1306 fatal_error 1307 ("Please supply either include_paths or userdef_filelist"); 1308 } 1309 // make hole for filelist 1310 sprintf(command, "mkdir -p %s/archives", scratchdir); 1311 paranoid_system(command); 1312 mr_asprintf(&sz_filelist, "%s/tmpfs/filelist.full", tmpdir); 1313 make_hole_for_file(sz_filelist); 1314 1315 if (differential == 0) { 1316 // restore last good datefile if it exists 1317 sprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile); 1318 run_program_and_log_output(command, 3); 1319 // backup last known good datefile just in case :) 1320 if (does_file_exist(sz_datefile)) { 1321 sprintf(command, "mv -f %s %s.aborted", sz_datefile, 1322 sz_datefile); 1323 paranoid_system(command); 1324 } 1325 make_hole_for_file(sz_datefile); 1326 write_one_liner_data_file(sz_datefile, 1327 call_program_and_get_last_line_of_output 1328 ("date +%s")); 1329 } else if (lstat(sz_datefile, &statbuf)) { 1330 log_msg(2, 1331 "Warning - unable to find date of previous backup. Full backup instead."); 1332 differential = 0; 1333 time_of_last_full_backup = 0; 1334 } else { 1335 time_of_last_full_backup = statbuf.st_mtime; 1336 log_msg(2, "Differential backup. Yay."); 1337 } 1338 paranoid_free(sz_datefile); 1339 1340 // use user-specified filelist (if specified) 1341 if (userdef_filelist) { 1342 log_msg(1, 1343 "Using the user-specified filelist - %s - instead of calculating one", 1344 userdef_filelist); 1345 sprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist); 1346 if (run_program_and_log_output(command, 3)) { 1347 fatal_error("Failed to copy user-specified filelist"); 1348 } 1349 } else { 1350 log_msg(2, "include_paths = '%s'", include_paths); 1351 log_msg(1, "Calculating filelist"); 1352 mr_asprintf(&tmp2, "%s", call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|ntfs-3g|fat|vfat|dos' | awk '{print $3}'")); 1353 if (strlen(tmp2) < 1) { 1354 mr_asprintf(&tmp1," "); 1355 } else { 1356 log_msg(2, "Found windows FS: %s",tmp2); 1357 mr_asprintf(&tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2); 1358 paranoid_free(tmp2); 1359 mr_asprintf(&tmp2, "%s", call_program_and_get_last_line_of_output(tmp1)); 1360 log_msg(2, "Found windows files: %s",tmp2); 1361 } 1362 paranoid_free(tmp1); 1363 1364 snprintf(exclude_paths, (size_t)8*MAX_STR_LEN," %s %s %s %s %s . .. \ 1365 " MNT_CDROM " " MNT_FLOPPY " /media /tmp \ 1366 /proc /sys " MINDI_CACHE, MONDO_CACHE, excp, tmp2, (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir); 1367 paranoid_free(tmp2); 1368 1369 log_msg(2, "Excluding paths = '%s'", exclude_paths); 1370 log_msg(2, 1371 "Generating skeleton filelist so that we can track our progress"); 1372 sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir); 1373 make_hole_for_file(g_skeleton_filelist); 1374 log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries); 1375 log_msg(2, "Opening out filelist to %s", sz_filelist); 1376 if (!(fout = fopen(sz_filelist, "w"))) { 1377 fatal_error("Cannot openout to sz_filelist"); 1378 } 1379 i = 0; 1380 if (strlen(include_paths) == 0) { 1381 log_msg(1, "Including only '/' in %s", sz_filelist); 1382 open_and_list_dir("/", exclude_paths, fout, 1383 time_of_last_full_backup); 1384 } else { 1385 p = include_paths; 1386 while (*p) { 1387 q = next_entry(p); 1388 log_msg(1, "Including %s in filelist %s", q, sz_filelist); 1389 open_and_list_dir(q, exclude_paths, fout, 1390 time_of_last_full_backup); 1391 p += strlen(q); 1392 paranoid_free(q); 1393 while (*p == ' ') { 1394 p++; 1395 } 1396 } 1397 } 1398 paranoid_fclose(fout); 1399 } 1400 log_msg(2, "Copying new filelist to scratchdir"); 1401 sprintf(command, "mkdir -p %s/archives", scratchdir); 1402 paranoid_system(command); 1403 sprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir); 1404 paranoid_system(command); 1405 sprintf(command, "mv -f %s %s", sz_filelist, tmpdir); 1406 paranoid_system(command); 1407 paranoid_free(sz_filelist); 1408 log_msg(2, "Freeing variables"); 1409 paranoid_free(command); 1410 paranoid_free(exclude_paths); 1411 paranoid_free(tmp); 1412 paranoid_free(g_skeleton_filelist); 1413 log_msg(2, "Exiting"); 1414 return (0); 1271 1415 } 1272 1416 … … 1562 1706 1563 1707 /** 1564 * Create the filelist for the backup. It will be stored in [scratchdir]/archives/filelist.full.1565 * @param logfile Unused.1566 * @param tmpdir The tmpdir of the backup.1567 * @param scratchdir The scratchdir of the backup.1568 * @param include_paths The paths to back up, or NULL if you're using a user-defined filelist.1569 * @param excp The paths to NOT back up.1570 * @param differential The differential level (currently only 0 and 1 are supported).1571 * @param userdef_filelist The user-defined filelist, or NULL if you're using @p include_paths.1572 * @return 0, always.1573 * @bug @p logfile is unused.1574 * @bug Return value is meaningless.1575 */1576 int mondo_makefilelist(char *logfile, char *tmpdir, char *scratchdir,1577 char *include_paths, char *excp, int differential,1578 char *userdef_filelist)1579 {1580 char *p, *q;1581 char *sz_datefile;1582 char *sz_filelist, *exclude_paths, *tmp;1583 int i;1584 FILE *fout;1585 char *command;1586 time_t time_of_last_full_backup = 0;1587 struct stat statbuf;1588 char *tmp1 = NULL;1589 char *tmp2 = NULL;1590 1591 malloc_string(command);1592 malloc_string(tmp);1593 malloc_string(g_skeleton_filelist);1594 if (!(exclude_paths = malloc(8*MAX_STR_LEN))) {1595 fatal_error("Cannot malloc exclude_paths");1596 }1597 mr_asprintf(&sz_datefile,MONDO_CACHE"/difflevel.%d" , 0);1598 if (!include_paths && !userdef_filelist) {1599 fatal_error1600 ("Please supply either include_paths or userdef_filelist");1601 }1602 // make hole for filelist1603 sprintf(command, "mkdir -p %s/archives", scratchdir);1604 paranoid_system(command);1605 mr_asprintf(&sz_filelist, "%s/tmpfs/filelist.full", tmpdir);1606 make_hole_for_file(sz_filelist);1607 1608 if (differential == 0) {1609 // restore last good datefile if it exists1610 sprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);1611 run_program_and_log_output(command, 3);1612 // backup last known good datefile just in case :)1613 if (does_file_exist(sz_datefile)) {1614 sprintf(command, "mv -f %s %s.aborted", sz_datefile,1615 sz_datefile);1616 paranoid_system(command);1617 }1618 make_hole_for_file(sz_datefile);1619 write_one_liner_data_file(sz_datefile,1620 call_program_and_get_last_line_of_output1621 ("date +%s"));1622 } else if (lstat(sz_datefile, &statbuf)) {1623 log_msg(2,1624 "Warning - unable to find date of previous backup. Full backup instead.");1625 differential = 0;1626 time_of_last_full_backup = 0;1627 } else {1628 time_of_last_full_backup = statbuf.st_mtime;1629 log_msg(2, "Differential backup. Yay.");1630 }1631 paranoid_free(sz_datefile);1632 1633 // use user-specified filelist (if specified)1634 if (userdef_filelist) {1635 log_msg(1,1636 "Using the user-specified filelist - %s - instead of calculating one",1637 userdef_filelist);1638 sprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);1639 if (run_program_and_log_output(command, 3)) {1640 fatal_error("Failed to copy user-specified filelist");1641 }1642 } else {1643 log_msg(2, "include_paths = '%s'", include_paths);1644 log_msg(1, "Calculating filelist");1645 mr_asprintf(&tmp2, "%s", call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|ntfs-3g|fat|vfat|dos' | awk '{print $3}'"));1646 if (strlen(tmp2) < 1) {1647 mr_asprintf(&tmp1," ");1648 } else {1649 log_msg(2, "Found windows FS: %s",tmp2);1650 mr_asprintf(&tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2);1651 paranoid_free(tmp2);1652 mr_asprintf(&tmp2, "%s", call_program_and_get_last_line_of_output(tmp1));1653 log_msg(2, "Found windows files: %s",tmp2);1654 }1655 paranoid_free(tmp1);1656 1657 snprintf(exclude_paths, (size_t)8*MAX_STR_LEN," %s %s %s %s %s . .. \1658 " MNT_CDROM " " MNT_FLOPPY " /media /tmp \1659 /proc /sys " MINDI_CACHE, MONDO_CACHE, excp, tmp2, (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir);1660 paranoid_free(tmp2);1661 1662 log_msg(2, "Excluding paths = '%s'", exclude_paths);1663 log_msg(2,1664 "Generating skeleton filelist so that we can track our progress");1665 sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir);1666 make_hole_for_file(g_skeleton_filelist);1667 log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries);1668 log_msg(2, "Opening out filelist to %s", sz_filelist);1669 if (!(fout = fopen(sz_filelist, "w"))) {1670 fatal_error("Cannot openout to sz_filelist");1671 }1672 i = 0;1673 if (strlen(include_paths) == 0) {1674 log_msg(1, "Including only '/' in %s", sz_filelist);1675 open_and_list_dir("/", exclude_paths, fout,1676 time_of_last_full_backup);1677 } else {1678 p = include_paths;1679 while (*p) {1680 q = next_entry(p);1681 log_msg(1, "Including %s in filelist %s", q, sz_filelist);1682 open_and_list_dir(q, exclude_paths, fout,1683 time_of_last_full_backup);1684 p += strlen(q);1685 paranoid_free(q);1686 while (*p == ' ') {1687 p++;1688 }1689 }1690 }1691 paranoid_fclose(fout);1692 }1693 log_msg(2, "Copying new filelist to scratchdir");1694 sprintf(command, "mkdir -p %s/archives", scratchdir);1695 paranoid_system(command);1696 sprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir);1697 paranoid_system(command);1698 sprintf(command, "mv -f %s %s", sz_filelist, tmpdir);1699 paranoid_system(command);1700 paranoid_free(sz_filelist);1701 log_msg(2, "Freeing variables");1702 paranoid_free(command);1703 paranoid_free(exclude_paths);1704 paranoid_free(tmp);1705 paranoid_free(g_skeleton_filelist);1706 log_msg(2, "Exiting");1707 return (0);1708 }1709 1710 1711 1712 1713 /**1714 1708 * Locate the string @p string_to_find in the tree rooted at @p startnode. 1715 1709 * @param startnode The node containing the root of the directory tree.
Note:
See TracChangeset
for help on using the changeset viewer.