source: MondoRescue/branches/stable/mondo/src/mondoarchive/mondoarchive.c@ 1842

Last change on this file since 1842 was 1842, checked in by Bruno Cornec, 16 years ago
  • Fix lack of /etc/raidtab at restore rime in the right place
  • Adds support for nls_utf8 and pata_serverworks Patches from Dirk Husung (husung_at_tu-harburg.de)
  • Add efibootmgr to deplist.txt in order to be able to modify EFI menu at restore time on ia64
  • Usage of the new testver param of pb 0.8.12 to deliver 2.2.5 packages in a test dir.
  • Update pbcl files for upcoming delivery of 2.2.5
  • Fix an issue on parted output (K instead of KB) in parted2fdisk at restore time
  • Adds support for alb/aft types of bonding on Intel cards (Mark Pinkerton <Mark.Pinkerton_at_emageon.com>)
  • Escape variables in a perl script like mindi-bkphw
  • Better Proliant support at restore time now.
  • Fix a label bug where the variable label should also be re-initialized at each loop
  • start-nfs should NOT do exit => kernel panix as init exits
  • some other fixes for init on denymods
  • Adds boot options denymods (for udev) and forcemods (if not udev)
  • kqemu is denied. Probably should also be done for kvm stuff
  • Fix again the bug on modules link at root of the initrd. Hopefully for good.
  • Wait more around the USB CD emulated by iLO as it takes up to 5 seconds to come up
  • Attempt to fix udev support for RHEL 5.1
  • Better support for automatic iLO Virtual Media with udev
  • Some VMWare support improvements (however, it seems that VMWare support won't be possible anytime soon)
  • during init at restore time, copy all static evices availble for udev, as some distro implementation are no

t yet supported correctly for udev. Not very elegant, but should solve our current issues

  • Fedora 8 now supported as a build target for pb
  • svn.log removed.
  • dependencies reviewd for rhel_3
  • Attempt to fix the lack of modules loaded at restore time - especially fs device drivers
  • removes bkphw dir before potential creation
  • render mount command more vebose at restore time
  • Should fix #217
  • Increase BOOT_SIZE and EXTRA_SIZE to support features such as HW recovery
  • Handles udev.files files which could be symlinks
  • Improve udev support for distro with compressed modules (mdv e.g.)
  • Fix modules.dep copy
  • /sbin/pam_console_apply is needed by mdv udev conf
  • Adds support for nohw boot option to avoid re-setuping the HW conf
  • Improved support for Proliant on cpqacuxe
  • RstHW should be called after driver initialization
  • For debian/ubuntu mindi dpends on mindi-busybox
  • Update mindi-busybox pbcl for correct debian changelog generation, and up2date infos
  • Should fix #215
  • Fix #214 (Thanks to xdelaruelle)
  • Fix again svn.log not used anymore with new pb version
  • Adaptation of build process to upcoming 0.8.12 version of pb
  • Remove MONOTONIC clock to continue to support 2.4 kernels (RHEL 3 e.g. or ESX)
  • Attempt to solve ia64 BMC access through the serial port
  • parted2fdisk binary no more generated
  • do not require perl modules (strict.pm) at restore time
  • try to avoid modprobe messages at restore time
  • on ia64 now use the perl script parted2fdisk at retore time also
  • Also modprobe modules for udev after decompressing the additional ones
  • replace gzip -v9 by gzip -c9. Fix a bug at least on ia64
  • For all modules supported, create symlinks under the mountpoint and extract dev files as some are not automat ically created at the moment
  • Support /vmfs/volumes for ESX
  • Finally do not use vdf for ESX. Only creates issues.
  • Avoids continuing hw support if no product name found
  • Improves ia64 support for bootable image build
  • Fix a potential problem with ramdisk_blocksize param
  • MAKEDEV should also be included in deplist.txt
  • More fixes for udev support for Debian
  • Do not mount /boot if it's already mounted - avoids ESX hang
  • Fix NICs renumbering on Debian at least
  • Udev startup improvement to support iLO + NFS so modprobing all modules seems required as of now
  • Update to version 1.7.3 of busybox for pb
  • Load USB earlier in order to support KBD such as with iLO
  • Do busybox ldd first in order to create a potential /lib64 link correctly and then use it later in the image
  • Use variable DF in mindi to be able to support the ESX vdf
  • Fix mindi for Debian x86_64 where /lib64 is a link
  • Fix issue at restore time for ext2fs params not reused (Fix from Klaus Ade Johnstad <klaus_at_skolelinux.no>)
  • Do not copy udev files if they do not exist In udev case do not insert modules at all (udev should do it alone) May avoid the issue with rhel4.5 kernel ? To be tested
  • Update dependencies for rpm base build as well
  • And also perl is a debian/ubuntu dep
  • Better debian/ubuntu dependecies requirements (mtools)
  • Fix modes on mindi-bkphw (Thanks Phil Walker phil.walker_at_hp.com)
  • Complete rev [1771] for upper case RESTORE cli with syslinux as well
  • Update mindi-busybox to 1.7.3
  • Use RESTORE consistently across mondo to restore without interaction (report from Takeshi Shoji t.shoji_at_tripodw.jp)

(merge -r1769:1841 $SVN_M/branches/2.2.5)

  • Property svn:keywords set to Id
File size: 19.1 KB
RevLine 
[1]1/***************************************************************************
[1080]2* $Id: mondoarchive.c 1842 2007-12-15 01:24:34Z bruno $
3*/
[1]4
5
6/**
7 * @file
8 * The main file for mondoarchive.
9 */
10
11/************************* #include statements *************************/
12#include <pthread.h>
13#include <stdio.h>
14#include <stdlib.h>
[1100]15#include <sys/types.h>
16#include <sys/stat.h>
17#include <unistd.h>
[1549]18#include <locale.h>
[1100]19
[1458]20#include "mr_gettext.h"
[1256]21#include "mondoarchive.h"
[1187]22#include "mr_mem.h"
[1087]23#include "mr_str.h"
[1112]24#include "mr_msg.h"
[1102]25#include "mr_file.h"
[1264]26#include "mr_err.h"
[1256]27#include "mr_conf.h"
[1087]28
[1458]29#include "my-stuff.h"
30#include "mondostructures.h"
31#include "libmondo.h"
32#include "mondo-cli-EXT.h"
33
[1]34// for CVS
[128]35//static char cvsid[] = "$Id: mondoarchive.c 1842 2007-12-15 01:24:34Z bruno $";
[1]36
37/************************* external variables *************************/
38extern void set_signals(int);
39extern int g_current_media_number;
[128]40extern void register_pid(pid_t, char *);
[1]41extern int g_currentY;
42extern bool g_text_mode;
43extern char *g_boot_mountpt;
44extern bool g_remount_cdrom_at_end, g_remount_floppy_at_end;
45extern char *g_cdrw_drive_is_here;
[1256]46extern double g_kernel_version;
47extern char *g_magicdev_command;
48extern t_bkptype g_backup_media_type;
49
[1549]50extern char *get_uname_m(void);
[1384]51
[128]52static char *g_cdrom_drive_is_here = NULL;
53static char *g_dvd_drive_is_here = NULL;
[1]54
[1543]55struct mr_ar_conf *mr_conf = NULL;
[1256]56
57/***************** global vars ******************/
[1]58long diffs;
59
[1256]60/****************** subroutines used only here ******************/
[1]61
[1663]62/* Reference to global bkpinfo */
63struct s_bkpinfo *bkpinfo;
[1]64
[1663]65/****************** subroutines used only by main.c ******************/
66
[1]67/**
68 * Print a "don't panic" message to the log and a message about the logfile to the screen.
69 */
[1256]70static void welcome_to_mondoarchive(void)
[1]71{
[1377]72 char *tmp = NULL;
73
[1256]74 mr_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org", PACKAGE_VERSION);
[1378]75 mr_msg(0, "running %s binaries", get_architecture());
[1377]76 tmp = get_uname_m();
[1378]77 mr_msg(0, "running on %s architecture", tmp);
[1377]78 mr_free(tmp);
[1256]79 mr_msg(0, "-----------------------------------------------------------");
80 mr_msg(0, "NB: Mondo logs almost everything, so don't panic if you see");
81 mr_msg(0, "some error messages. Please read them carefully before you");
82 mr_msg(0, "decide to break out in a cold sweat. Despite (or perhaps");
83 mr_msg(0, "because of) the wealth of messages. some users are inclined");
84 mr_msg(0, "to stop reading this log. If Mondo stopped for some reason,");
85 mr_msg(0, "chances are it's detailed here. More than likely there's a");
86 mr_msg(0, "message at the very end of this log that will tell you what");
87 mr_msg(0, "is wrong. Please read it! -Devteam");
88 mr_msg(0, "-----------------------------------------------------------");
[1]89
[1108]90 mr_msg(0, "Zero...");
91 mr_msg(1, "One...");
92 mr_msg(2, "Two...");
93 mr_msg(3, "Three...");
94 mr_msg(4, "Four...");
95 mr_msg(5, "Five...");
96 mr_msg(6, "Six...");
97 mr_msg(7, "Seven...");
98 mr_msg(8, "Eight...");
[1594]99 printf(_("See %s for details of backup run.\n"), MONDO_LOGFILE);
[1]100}
101
102/**
103 * Do whatever is necessary to insure a successful backup on the Linux distribution
104 * of the day.
105 */
[1256]106static void distro_specific_kludges_at_start_of_mondoarchive(void)
[1]107{
[1108]108 mr_msg(2, "Unmounting old ramdisks if necessary");
[128]109 stop_magicdev_if_necessary(); // for RH+Gnome users
110 run_program_and_log_output
111 ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2);
112 unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted
113 mount_boot_if_necessary(); // for Gentoo users with non-mounted /boot partitions
114 clean_up_KDE_desktop_if_necessary(); // delete various misc ~/.* files that get in the way
[1]115}
116
117
118/**
119 * Undo whatever was done by distro_specific_kludges_at_start_of_mondoarchive().
120 */
[1256]121static void distro_specific_kludges_at_end_of_mondoarchive(void)
[1]122{
[1108]123 mr_msg(2, "Restarting magicdev if necessary");
[128]124 sync();
125 restart_magicdev_if_necessary(); // for RH+Gnome users
[1]126
[1108]127 mr_msg(2, "Restarting supermounts if necessary");
[128]128 sync();
129 remount_supermounts_if_necessary(); // for Mandrake users
[1]130
[1108]131 mr_msg(2, "Unmounting /boot if necessary");
[128]132 sync();
133 unmount_boot_if_necessary(); // for Gentoo users
[1]134}
135
[1594]136/* reset/empty the mr_ar_conf structure from mondo's conf file */
137static void mr_ar_reset_conf(struct mr_ar_conf *mr_cnf) {
138
139 /* This should correspond to the default conf file */
140 /* Especially for boolean values */
141 mr_cnf->iso_creation_cmd = NULL;
142 mr_cnf->iso_creation_opt = NULL;
143 mr_cnf->iso_burning_cmd = NULL;
144 mr_cnf->iso_burning_opt = NULL;
145 mr_cnf->iso_burning_dev = NULL;
146 mr_cnf->iso_burning_speed = 0;
147 mr_cnf->media_size = 0;
148 mr_cnf->media_device = NULL;
149 mr_cnf->iso_burning_dev = NULL;
150 mr_cnf->manual_tray = FALSE;
151 mr_cnf->log_level = 0;
152 mr_cnf->prefix = NULL;
153 mr_cnf->external_tape_blocksize = 0;
154 mr_cnf->internal_tape_blocksize = 0;
155 mr_cnf->kernel = NULL;
156 mr_cnf->additional_modules = NULL;
157 mr_cnf->boot_loader = NULL;
158 mr_cnf->differential = FALSE;
159 mr_cnf->compression_tool = NULL;
160 mr_cnf->compression_level = 0;
161 mr_cnf->exclude_paths = NULL;
162 mr_cnf->include_paths = NULL;
163 mr_cnf->ui_mode = NULL;
164 mr_cnf->automatic_restore = FALSE;
165 mr_cnf->scratch_dir = NULL;
166 mr_cnf->tmp_dir = NULL;
167 mr_cnf->images_dir = NULL;
168}
169
[1535]170/* fill the mr_ar_conf structure from mindi's conf file */
171static void mr_ar_store_conf_mindi(struct mr_ar_conf *mr_cnf) {
172
173 char *p = NULL;
174
175 p = mr_conf_sread("mr_iso_creation_cmd");
176 if (p != NULL) {
177 mr_cnf->iso_creation_cmd = p;
178 }
179 p = mr_conf_sread("mr_iso_creation_opt");
180 if (p != NULL) {
181 mr_cnf->iso_creation_opt = p;
182 }
183}
184
[1256]185/* create the mr_ar_conf structure from mondo's conf file */
[1264]186static void mr_ar_store_conf(struct mr_ar_conf *mr_cnf) {
[1256]187
[1415]188 char *p = NULL;
189
[1594]190 p = mr_conf_sread("mondo_iso_burning_cmd");
191 if (p != NULL) {
192 mr_cnf->iso_burning_cmd = p;
193 }
[1422]194
[1594]195 p = mr_conf_sread("mondo_iso_burning_opt");
196 if (p != NULL) {
197 mr_cnf->iso_burning_opt = p;
198 }
[1422]199
[1594]200 p = mr_conf_sread("mondo_iso_burning_dev");
201 if (p != NULL) {
202 mr_cnf->iso_burning_dev = p;
203 }
[1422]204
[1594]205 p = mr_conf_iread("mondo_iso_burning_speed");
206 if (p != NULL ) {
207 mr_cnf->iso_burning_speed = atoi(p);
208 mr_free(p);
209 }
[1422]210
[1594]211 p = mr_conf_iread("mondo_media_size");
212 if (p != NULL ) {
213 mr_cnf->media_size = atoi(p);
214 mr_free(p);
215 }
[1422]216
[1594]217 p = mr_conf_sread("mondo_media_device");
218 if (p != NULL) {
219 mr_cnf->media_device = p;
220 }
221 /* If no specific device name for the burning command (a la ATAPI:0,0,0),
222 * then use the normal device name (a la /dev/hda) */
223 if ((mr_cnf->iso_burning_dev == NULL) && (mr_cnf->media_device != NULL)) {
224 mr_asprintf(&p, mr_cnf->media_device);
225 mr_cnf->iso_burning_dev = p;
226 }
[1422]227
[1594]228 p = mr_conf_bread("mondo_manual_tray");
229 if (p != NULL) {
230 mr_cnf->manual_tray = mr_atob(p);
231 mr_free(p);
232 }
[1422]233
[1594]234 p = mr_conf_iread("mondo_log_level");
235 if (p != NULL) {
236 mr_cnf->log_level = atoi(p);
237 mr_free(p);
238 }
[1422]239
[1594]240 p = mr_conf_sread("mondo_prefix");
241 if (p != NULL) {
242 mr_cnf->prefix = p;
243 }
[1422]244
[1594]245 p = mr_conf_iread("mondo_external_tape_blocksize");
246 if (p != NULL) {
247 mr_cnf->external_tape_blocksize = atoi(p);
248 mr_free(p);
249 }
[1422]250
[1594]251 p = mr_conf_iread("mondo_internal_tape_blocksize");
252 if (p != NULL) {
253 mr_cnf->internal_tape_blocksize = atoi(p);
254 mr_free(p);
255 }
[1422]256
[1594]257 p = mr_conf_sread("mondo_kernel");
258 if (p != NULL) {
259 mr_cnf->kernel = p;
260 }
[1422]261
[1594]262 p = mr_conf_sread("mondo_additional_modules");
263 if (p != NULL) {
264 mr_cnf->additional_modules = p;
265 }
[1422]266
[1594]267 p = mr_conf_sread("mondo_boot_loader");
268 if (p != NULL) {
269 mr_cnf->boot_loader = p;
270 }
[1422]271
[1594]272 p = mr_conf_bread("mondo_differential");
273 if (p != NULL) {
274 mr_cnf->differential = mr_atob(p);
275 mr_free(p);
276 }
[1422]277
[1594]278 p = mr_conf_sread("mondo_compression_tool");
279 if (p != NULL) {
280 mr_cnf->compression_tool = p;
281 }
[1422]282
[1769]283 p = mr_conf_sread("mondo_compression_suffix");
284 if (p != NULL) {
285 mr_cnf->compression_suffix = p;
286 }
287
[1594]288 p = mr_conf_iread("mondo_compression_level");
289 if (p != NULL) {
290 mr_cnf->compression_level = atoi(p);
291 mr_free(p);
292 }
[1422]293
[1594]294 p = mr_conf_sread("mondo_exclude_paths");
295 if (p != NULL) {
296 mr_cnf->exclude_paths = p;
297 }
[1422]298
[1594]299 p = mr_conf_sread("mondo_include_paths");
300 if (p != NULL) {
301 mr_cnf->include_paths = p;
302 }
303
304 p = mr_conf_sread("mondo_ui_mode");
305 if (p != NULL) {
306 mr_cnf->ui_mode = p;
307 }
308
309 p = mr_conf_bread("mondo_automatic_restore");
310 if (p != NULL) {
311 mr_cnf->automatic_restore = mr_atob(p);
312 mr_free(p);
313 }
314
315 p = mr_conf_sread("mondo_scratch_dir");
316 if (p != NULL) {
317 mr_cnf->scratch_dir = p;
318 }
319
320 p = mr_conf_sread("mondo_tmp_dir");
321 if (p != NULL) {
322 mr_cnf->tmp_dir = p;
323 }
324
325 p = mr_conf_sread("mondo_images_dir");
326 if (p != NULL) {
327 mr_cnf->images_dir = p;
328 }
[1264]329 mr_msg(5, "Directory for images is %s", mr_cnf->images_dir);
[1256]330}
331
[1264]332/* destroy the mr_ar_conf structure's content */
333static void mr_ar_clean_conf(struct mr_ar_conf *mr_cnf) {
334
335 if (mr_cnf == NULL) {
336 return;
337 }
338 mr_free(mr_cnf->iso_creation_cmd);
[1535]339 mr_free(mr_cnf->iso_creation_opt);
[1264]340 mr_free(mr_cnf->iso_burning_cmd);
[1594]341 mr_free(mr_cnf->iso_burning_dev);
[1592]342 mr_free(mr_cnf->iso_burning_opt);
[1264]343 mr_free(mr_cnf->media_device);
344 mr_free(mr_cnf->prefix);
345 mr_free(mr_cnf->kernel);
346 mr_free(mr_cnf->additional_modules);
347 mr_free(mr_cnf->boot_loader);
348 mr_free(mr_cnf->compression_tool);
349 mr_free(mr_cnf->exclude_paths);
350 mr_free(mr_cnf->include_paths);
351 mr_free(mr_cnf->ui_mode);
352 mr_free(mr_cnf->scratch_dir);
353 mr_free(mr_cnf->tmp_dir);
354 mr_free(mr_cnf->images_dir);
[1543]355 mr_free(mr_cnf);
[1264]356}
357
358/* Create the pointer to the function called in mr_exit */
359void (*mr_cleanup)(void) = NULL;
360
[1390]361/* Just for init */
362void mr_ar_cleanup_empty(void) {
363}
364
[1264]365/* Cleanup all memory allocated in various structures */
366void mr_ar_cleanup(void) {
367 /* Highly incomplete function for the moment */
368 /* We have to free all allocated memory */
[1543]369 mr_ar_clean_conf(mr_conf);
[1264]370 /* We have to remove all temporary files */
371 /* We have to unmount what has been mounted */
372 /* We have to properly end newt */
373 /* We have to remind people of log files */
374
375 mr_msg_close();
376}
377
[1]378/*-----------------------------------------------------------*/
379
380
381
382/**
383 * Backup/verify the user's data.
384 * What did you think it did, anyway? :-)
385 */
[128]386int main(int argc, char *argv[])
[1]387{
[1100]388 struct stat stbuf;
[1152]389 char *tmp = NULL;
[1187]390 int res = 0;
391 int retval = 0;
392 char *say_at_end = NULL;
[1190]393 char *say_at_end2 = NULL;
[1]394
[1187]395#ifdef ENABLE_NLS
396 setlocale(LC_ALL, "");
397 (void) textdomain("mondo");
398#endif
[1594]399 printf(_("Initializing...\n"));
[1256]400
[1663]401 bkpinfo = mr_malloc(sizeof(struct s_bkpinfo));
402 reset_bkpinfo();
403
[1390]404 /* Reference a dummy cleanup function for mr_exit temporarily */
405 mr_cleanup = &mr_ar_cleanup_empty;
[1264]406
[1256]407 /* initialize log file with time stamp */
408 /* We start with a loglevel of 4 - Adapted later on */
409 /* It's mandatory to set this up first as all mr_ functions rely on it */
410 unlink(MONDO_LOGFILE);
411 mr_msg_init(MONDO_LOGFILE,4);
412 mr_msg(0, _("Time started: %s"), mr_date());
413
414 /* Make sure I'm root; abort if not */
[128]415 if (getuid() != 0) {
[1256]416 mr_log_exit(127, _("Please run as root."));
[128]417 }
[1]418
[1187]419 /* If -V, -v or --version then echo version no. and quit */
[128]420 if (argc == 2
421 && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
422 || !strcmp(argv[argc - 1], "--version"))) {
[1187]423 printf(_("mondoarchive v%s\nSee man page for help\n"), PACKAGE_VERSION);
[1256]424 mr_exit(0, NULL);
[128]425 }
[1]426
[1256]427 /* Conf file management */
[1594]428 mr_conf = mr_malloc(sizeof(struct mr_ar_conf));
429 mr_ar_reset_conf(mr_conf);
[1256]430 /* Check md5 sum before */
431 /* Get content */
432 if (mr_conf_open(MONDO_CONF_DIR"/mondo.conf.dist") != 0) {
433 mr_log_exit(-1, "Unable to open "MONDO_CONF_DIR"/mondo.conf.dist");
434 }
[1543]435 mr_ar_store_conf(mr_conf);
[1390]436 /* Reference the right cleanup function for mr_exit now it's allocated */
437 mr_cleanup = &mr_ar_cleanup;
[1256]438 mr_conf_close();
439
[1594]440 if (mr_conf_open(MONDO_CONF_DIR"/mondo.conf") == 0) {
441 mr_ar_store_conf(mr_conf);
442 mr_conf_close();
443 }
444
[1535]445 /* Check md5 sum before */
446 /* Get content of mindi conf file now to finish structure initialization */
447/* Tempo Hack */
[1571]448#define MINDI_CONF_DIR MONDO_CONF_DIR"/../mindi"
[1535]449 if (mr_conf_open(MINDI_CONF_DIR"/mindi.conf.dist") != 0) {
450 mr_log_exit(-1, "Unable to open "MINDI_CONF_DIR"/mindi.conf.dist");
451 }
[1543]452 mr_ar_store_conf_mindi(mr_conf);
[1535]453 mr_conf_close();
454
455 if (mr_conf_open(MINDI_CONF_DIR"/mindi.conf") == 0) {
[1543]456 mr_ar_store_conf_mindi(mr_conf);
[1535]457 mr_conf_close();
458 }
[1554]459 mr_msg(5, "Command for ISO images is %s", mr_conf->iso_creation_cmd);
[1535]460
[1256]461 /* Add MONDO_SHARE + other environment variables for mindi */
462 setenv_mondo_var();
463
[1187]464 /* Initialize variables */
[128]465 malloc_libmondo_global_strings();
466 diffs = 0;
[1100]467 if (stat(MONDO_CACHE, &stbuf) != 0) {
468 mr_mkdir(MONDO_CACHE,0x755);
469 }
470
[1140]471 /* BERLIOS: Hardcoded to be improved */
472 unlink(MONDO_CACHE"/mindi.conf");
[1143]473 unlink(MONDORESTORECFG);
[1140]474
[807]475 /* Configure the bkpinfo structure, global file paths, etc. */
[128]476 g_main_pid = getpid();
[1108]477 mr_msg(9, "This");
[1]478
[128]479 register_pid(g_main_pid, "mondo");
480 set_signals(TRUE); // catch SIGTERM, etc.
481 run_program_and_log_output("dmesg -n1", TRUE);
[1]482
[1108]483 mr_msg(9, "Next");
[1770]484 make_hole_for_dir(MONDO_CACHE);
485
[128]486 welcome_to_mondoarchive();
487 distro_specific_kludges_at_start_of_mondoarchive();
488 g_kernel_version = get_kernel_version();
[1]489
[128]490 if (argc == 4 && !strcmp(argv[1], "getfattr")) {
[1625]491 mr_conf->log_level = 10;
[128]492 g_text_mode = TRUE;
493 setup_newt_stuff();
494 if (!strstr(argv[2], "filelist")) {
[1187]495 mr_msg(1,_("Sorry - filelist goes first\n"));
[128]496 finish(1);
497 } else {
498 finish(get_fattr_list(argv[2], argv[3]));
499 }
500 finish(0);
[1]501 }
[128]502 if (argc == 4 && !strcmp(argv[1], "setfattr")) {
[1625]503 mr_conf->log_level = 10;
[128]504 g_text_mode = TRUE;
505 setup_newt_stuff();
506 finish(set_fattr_list(argv[2], argv[3]));
[1]507 }
[128]508
509 if (argc == 3 && !strcmp(argv[1], "wildcards")) {
[1625]510 mr_conf->log_level = 10;
[128]511 g_text_mode = TRUE;
512 setup_newt_stuff();
[1241]513 tmp = mr_stresc(argv[2], WILDCHARS, BACKSLASH);
[128]514 printf("in=%s; out=%s\n", argv[2], tmp);
[1152]515 mr_free(tmp);
[128]516 finish(1);
[1]517 }
[128]518
519 if (argc == 4 && !strcmp(argv[1], "getfacl")) {
[1625]520 mr_conf->log_level = 10;
[128]521 g_text_mode = TRUE;
522 setup_newt_stuff();
523 if (!strstr(argv[2], "filelist")) {
[1187]524 mr_msg(1,_("Sorry - filelist goes first\n"));
[128]525 finish(1);
526 } else {
527 finish(get_acl_list(argv[2], argv[3]));
528 }
529 finish(0);
530 }
531 if (argc == 4 && !strcmp(argv[1], "setfacl")) {
[1625]532 mr_conf->log_level = 10;
[128]533 g_text_mode = TRUE;
534 setup_newt_stuff();
535 finish(set_acl_list(argv[2], argv[3]));
536 }
[1]537
[128]538 if (argc > 2 && !strcmp(argv[1], "find-cd")) {
[1625]539 mr_conf->log_level = 10;
[128]540 g_text_mode = TRUE;
541 setup_newt_stuff();
[1152]542 malloc_string(tmp);
[128]543 if (find_cdrw_device(tmp)) {
[1187]544 mr_msg(1,_("Failed to find CDR-RW drive\n"));
[128]545 } else {
[1187]546 mr_msg(1,_("CD-RW is at %s\n"), tmp);
[128]547 }
548 tmp[0] = '\0';
549 if (find_cdrom_device(tmp, atoi(argv[2]))) {
[1187]550 mr_msg(1,_("Failed to find CD-ROM drive\n"));
[128]551 } else {
[1187]552 mr_msg(1,_("CD-ROM is at %s\n"), tmp);
[128]553 }
[1152]554 mr_free(tmp);
[128]555 finish(0);
556 }
[1]557
[128]558 if (argc > 2 && !strcmp(argv[1], "find-dvd")) {
[1625]559 mr_conf->log_level = 10;
[128]560 g_text_mode = TRUE;
561 setup_newt_stuff();
[1152]562 malloc_string(tmp);
[128]563 if (find_dvd_device(tmp, atoi(argv[2]))) {
[1187]564 mr_msg(1,_("Failed to find DVD drive\n"));
[128]565 } else {
[1187]566 mr_msg(1,_("DVD is at %s\n"), tmp);
[128]567 }
[1152]568 mr_free(tmp);
[128]569 finish(0);
570 }
[1]571
[128]572 if (argc > 2 && !strcmp(argv[1], "disksize")) {
573 printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2]));
574 finish(0);
575 }
576 if (argc > 2 && !strcmp(argv[1], "test-dev")) {
577 if (is_dev_an_NTFS_dev(argv[2])) {
[1187]578 mr_msg(1,_("%s is indeed an NTFS dev\n"), argv[2]);
[128]579 } else {
[1187]580 mr_msg(1,_("%s is _not_ an NTFS dev\n"), argv[2]);
[128]581 }
582 finish(0);
583 }
584
[1663]585 if (pre_param_configuration()) {
[128]586 fatal_error
587 ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting...");
588 }
[1140]589 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
590 bkpinfo->scratchdir);
[128]591
[1140]592 /* Process command line, if there is one. If not, ask user for info. */
[128]593 if (argc == 1) {
594 g_text_mode = FALSE;
595 setup_newt_stuff();
[1663]596 res = interactively_obtain_media_parameters_from_user(TRUE); /* yes, archiving */
[128]597 if (res) {
598 fatal_error
599 ("Syntax error. Please review the parameters you have supplied and try again.");
600 }
601 } else {
[1663]602 res = handle_incoming_parameters(argc, argv);
[128]603 if (res) {
[1187]604 mr_msg(1,
605 _("Errors were detected in the command line you supplied.\n"));
606 mr_msg(1,_("Please review the log file - %s \n"),MONDO_LOGFILE);
[1108]607 mr_msg(1, "Mondoarchive will now exit.");
[128]608 finish(1);
609 }
610 setup_newt_stuff();
[1]611 }
612
613/* Finish configuring global structures */
[1663]614 if (post_param_configuration()) {
[128]615 fatal_error
616 ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting...");
617 }
[1]618
[128]619 log_to_screen
[1187]620 (_("BusyBox's sources are available from http://www.busybox.net"));
621
[1]622
[128]623 /* If we're meant to backup then backup */
624 if (bkpinfo->backup_data) {
[1663]625 res = backup_data();
[128]626 retval += res;
627 if (res) {
[1187]628 mr_strcat(say_at_end,
629 _("Data archived. Please check the logs, just as a precaution. "));
[128]630 } else {
[1187]631 mr_strcat(say_at_end, _("Data archived OK. "));
[128]632 }
633 }
[1]634
[1187]635 /* If we're meant to verify then verify */
[128]636 if (bkpinfo->verify_data) {
[1663]637 res = verify_data();
[128]638 if (res < 0) {
[1190]639 mr_asprintf(&say_at_end2, _("%d difference%c found."), -res,
[128]640 (-res != 1) ? 's' : ' ');
641 res = 0;
642 }
643 retval += res;
644 }
[1]645
[1187]646 /* Report result of entire operation (success? errors?) */
[128]647 if (!retval) {
648 mvaddstr_and_log_it(g_currentY++, 0,
[1187]649 _("Backup and/or verify ran to completion. Everything appears to be fine."));
[128]650 } else {
651 mvaddstr_and_log_it(g_currentY++, 0,
[1187]652 _("Backup and/or verify ran to completion. However, errors did occur."));
[128]653 }
[1]654
[1438]655 if (does_file_exist(MINDI_CACHE"/mondorescue.iso")) {
[128]656 log_to_screen
[1438]657 (_(MINDI_CACHE"/mondorescue.iso, a boot/utility CD, is available if you want it."));
[128]658 }
[1]659
[1770]660 if (length_of_file(MONDO_CACHE"/changed.files") > 2) {
[128]661 if (g_text_mode) {
662 log_to_screen
[1770]663 (_("Type 'less "MONDO_CACHE"/changed.files' to see which files don't match the archives"));
[128]664 } else {
[1108]665 mr_msg(1,
[1770]666 _("Type 'less "MONDO_CACHE"/changed.files' to see which files don't match the archives"));
[1108]667 mr_msg(2, "Calling popup_changelist_from_file()");
[1770]668 popup_changelist_from_file(MONDO_CACHE"/changed.files");
[1108]669 mr_msg(2, "Returned from popup_changelist_from_file()");
[128]670 }
671 } else {
[1770]672 unlink(MONDO_CACHE"/changed.files");
[128]673 }
674 log_to_screen(say_at_end);
[1187]675 mr_free(say_at_end);
[1190]676 if (say_at_end2 != NULL) {
677 log_to_screen(say_at_end2);
678 mr_free(say_at_end2);
679 }
[1187]680
[1152]681 mr_asprintf(&tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
[128]682 run_program_and_log_output(tmp, TRUE);
[1152]683 mr_free(tmp);
[1770]684 if (bkpinfo->backup_media_type == usb) {
685 log_msg(1, "Unmounting USB device.");
686 mr_asprintf(&tmp, "umount %s1", bkpinfo->media_device);
687 run_program_and_log_output(tmp, TRUE);
688 mr_free(tmp);
689 }
[1]690
[128]691 run_program_and_log_output("mount", 2);
[1]692
[1770]693 system("rm -f "MONDO_CACHE"/last-backup.aborted");
[128]694 if (!retval) {
[1187]695 printf(_("Mondoarchive ran OK.\n"));
[128]696 } else {
[1187]697 printf(_("Errors occurred during backup. Please check logfile.\n"));
[128]698 }
699 distro_specific_kludges_at_end_of_mondoarchive();
700 register_pid(0, "mondo");
701 set_signals(FALSE);
[1663]702
[128]703 free_libmondo_global_strings();
[1080]704 mr_free(bkpinfo);
[1]705
[128]706 if (!g_cdrom_drive_is_here) {
[1108]707 mr_msg(10, "FYI, g_cdrom_drive_is_here was never used");
[128]708 }
709 if (!g_dvd_drive_is_here) {
[1108]710 mr_msg(10, "FYI, g_dvd_drive_is_here was never used");
[128]711 }
[1]712
[810]713 /* finalize log file with time stamp */
[1187]714 mr_msg(1, "Time finished: %s", mr_date());
[1132]715 mr_msg_close();
[810]716
[1770]717 chdir("/tmp");
[1663]718
[128]719 if (!g_text_mode) {
720 popup_and_OK
[1187]721 (_("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt."));
722 log_to_screen(_("See %s for details of backup run."), MONDO_LOGFILE);
[128]723 } else {
[1187]724 printf(_("See %s for details of backup run.\n"), MONDO_LOGFILE);
[1264]725 mr_exit(retval, NULL);
[128]726 }
[1770]727 finish(retval);
[128]728
729 return EXIT_SUCCESS;
[1]730}
Note: See TracBrowser for help on using the repository browser.