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

Last change on this file since 1087 was 1087, checked in by Bruno Cornec, 17 years ago

WARNING: Not tested yet ! Will be stabilized in next hours.
this patch changes the interface between mindi and mondo.
Everything is now managed through either MONDO_CACHE/mondo-restore.cfg
and MONDO_CACHE/mindi.conf (an additional configuration file)
This removes all the one line files NFS-*, ... that where used
in an anarchic way. Now everything computed by mondo is
under mondo-restore.cfg and everything related to mindi in mindi.conf

Still needed are the removal of the 2 parameters to mindi,
but that will be done after when a clear line is drawn between
where files are put by each tool.

MONDO_TMP and MINDI_TMP should be reserved for temporary files
MONDO_CACHE and MINDI_CACHE for end results and communication
between tools.
These changes were made in order to prepare the USB support in mondo

A first step in the right direction, but still some work to do
before it's working again.
Testers please be warned.

  • Property svn:keywords set to Id
File size: 12.8 KB
Line 
1/***************************************************************************
2* $Id: main.c 1087 2007-02-02 22:31:00Z bruno $
3*/
4
5
6/**
7 * @file
8 * The main file for mondoarchive.
9 */
10
11/************************* #include statements *************************/
12#include <pthread.h>
13//#include <config.h>
14//#include "../../config.h"
15#include <stdio.h>
16#include <stdlib.h>
17#include "my-stuff.h"
18#include "../common/mondostructures.h"
19#include "../common/libmondo.h"
20#include "mondo-cli-EXT.h"
21
22#include "mr_str.h"
23
24// for CVS
25//static char cvsid[] = "$Id: main.c 1087 2007-02-02 22:31:00Z bruno $";
26
27/************************* external variables *************************/
28extern void set_signals(int);
29extern int g_current_media_number;
30extern void register_pid(pid_t, char *);
31extern int g_currentY;
32extern bool g_text_mode;
33extern char *g_boot_mountpt;
34extern bool g_remount_cdrom_at_end, g_remount_floppy_at_end;
35extern char *g_mondo_home;
36extern char *g_tmpfs_mountpt;
37extern char *g_erase_tmpdir_and_scratchdir;
38extern char *g_cdrw_drive_is_here;
39static char *g_cdrom_drive_is_here = NULL;
40static char *g_dvd_drive_is_here = NULL;
41extern double g_kernel_version;
42
43/***************** global vars, used only by main.c ******************/
44bool g_skip_floppies;
45long diffs;
46char *ps_options = "auxww";
47char *ps_proc_id = "$2";
48
49extern t_bkptype g_backup_media_type;
50extern int g_loglevel;
51
52/****************** subroutines used only by main.c ******************/
53
54
55/**
56 * Print a "don't panic" message to the log and a message about the logfile to the screen.
57 */
58void welcome_to_mondoarchive()
59{
60 log_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org",
61 PACKAGE_VERSION);
62 log_msg(0, "running on %s architecture", get_architecture());
63 log_msg(0,
64 "-----------------------------------------------------------");
65 log_msg(0,
66 "NB: Mondo logs almost everything, so don't panic if you see");
67 log_msg(0,
68 "some error messages. Please read them carefully before you");
69 log_msg(0,
70 "decide to break out in a cold sweat. Despite (or perhaps");
71 log_msg(0,
72 "because of) the wealth of messages. some users are inclined");
73 log_msg(0,
74 "to stop reading this log. If Mondo stopped for some reason,");
75 log_msg(0,
76 "chances are it's detailed here. More than likely there's a");
77 log_msg(0,
78 "message at the very end of this log that will tell you what");
79 log_msg(0,
80 "is wrong. Please read it! -Devteam");
81 log_msg(0,
82 "-----------------------------------------------------------");
83
84 log_msg(0, "Zero...");
85 log_msg(1, "One...");
86 log_msg(2, "Two...");
87 log_msg(3, "Three...");
88 log_msg(4, "Four...");
89 log_msg(5, "Five...");
90 log_msg(6, "Six...");
91 log_msg(7, "Seven...");
92 log_msg(8, "Eight...");
93 printf("See %s for details of backup run.\n", MONDO_LOGFILE);
94}
95
96
97extern char *g_magicdev_command;
98
99/**
100 * Do whatever is necessary to insure a successful backup on the Linux distribution
101 * of the day.
102 */
103void distro_specific_kludges_at_start_of_mondoarchive()
104{
105 log_msg(2, "Unmounting old ramdisks if necessary");
106 stop_magicdev_if_necessary(); // for RH+Gnome users
107 run_program_and_log_output
108 ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2);
109 unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted
110 // stop_autofs_if_necessary(); // for Xandros users
111 mount_boot_if_necessary(); // for Gentoo users with non-mounted /boot partitions
112 clean_up_KDE_desktop_if_necessary(); // delete various misc ~/.* files that get in the way
113}
114
115
116
117/**
118 * Undo whatever was done by distro_specific_kludges_at_start_of_mondoarchive().
119 */
120void distro_specific_kludges_at_end_of_mondoarchive()
121{
122// char tmp[500];
123 log_msg(2, "Restarting magicdev if necessary");
124 sync();
125 restart_magicdev_if_necessary(); // for RH+Gnome users
126
127 log_msg(2, "Restarting autofs if necessary");
128 sync();
129 // restart_autofs_if_necessary(); // for Xandros users
130
131 log_msg(2, "Restarting supermounts if necessary");
132 sync();
133 remount_supermounts_if_necessary(); // for Mandrake users
134
135 log_msg(2, "Unmounting /boot if necessary");
136 sync();
137 unmount_boot_if_necessary(); // for Gentoo users
138
139// log_msg( 2, "Cleaning up KDE desktop");
140// clean_up_KDE_desktop_if_necessary();
141}
142
143/*-----------------------------------------------------------*/
144
145
146
147/**
148 * Backup/verify the user's data.
149 * What did you think it did, anyway? :-)
150 */
151int main(int argc, char *argv[])
152{
153 struct s_bkpinfo *bkpinfo;
154 char *tmp;
155 int res, retval;
156 char *say_at_end;
157
158/* Make sure I'm root; abort if not */
159 if (getuid() != 0) {
160 fprintf(stderr, "Please run as root.\r\n");
161 exit(127);
162 }
163
164/* If -V, -v or --version then echo version no. and quit */
165 if (argc == 2
166 && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
167 || !strcmp(argv[argc - 1], "--version"))) {
168 printf("mondoarchive v%s\nSee man page for help\n", PACKAGE_VERSION);
169 exit(0);
170 }
171
172/* Initialize variables */
173
174 malloc_libmondo_global_strings();
175 malloc_string(tmp);
176 malloc_string(say_at_end);
177
178 res = 0;
179 retval = 0;
180 diffs = 0;
181 say_at_end[0] = '\0';
182 printf("Initializing...\n");
183 bkpinfo = mr_malloc(sizeof(struct s_bkpinfo));
184
185 /* initialize log file with time stamp */
186 unlink(MONDO_LOGFILE);
187 log_msg(0, "Time started: %s", mr_date());
188
189 /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */
190 strncpy(tmp, getenv("PATH"), MAX_STR_LEN - 1);
191 tmp[MAX_STR_LEN - 1] = '\0';
192 if (strlen(tmp) >= MAX_STR_LEN - 33) {
193 fatal_error
194 ("Your PATH environmental variable is too long. Please shorten it.");
195 }
196 strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin");
197 setenv("PATH", tmp, 1);
198
199 /* Add the ARCH environment variable for ia64 purposes */
200 strncpy(tmp, get_architecture(), MAX_STR_LEN - 1);
201 tmp[MAX_STR_LEN - 1] = '\0';
202 setenv("ARCH", tmp, 1);
203
204 /* Add MONDO_SHARE environment variable for mindi */
205 setenv_mondo_share();
206
207 /* Configure the bkpinfo structure, global file paths, etc. */
208 g_main_pid = getpid();
209 log_msg(9, "This");
210
211 register_pid(g_main_pid, "mondo");
212 set_signals(TRUE); // catch SIGTERM, etc.
213 run_program_and_log_output("dmesg -n1", TRUE);
214
215 log_msg(9, "Next");
216 welcome_to_mondoarchive();
217 distro_specific_kludges_at_start_of_mondoarchive();
218 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
219 bkpinfo->scratchdir);
220 g_kernel_version = get_kernel_version();
221
222 if (argc == 4 && !strcmp(argv[1], "getfattr")) {
223 g_loglevel = 10;
224 g_text_mode = TRUE;
225 setup_newt_stuff();
226 if (!strstr(argv[2], "filelist")) {
227 printf("Sorry - filelist goes first\n");
228 finish(1);
229 } else {
230 finish(get_fattr_list(argv[2], argv[3]));
231 }
232 finish(0);
233 }
234 if (argc == 4 && !strcmp(argv[1], "setfattr")) {
235 g_loglevel = 10;
236// chdir("/tmp");
237 g_text_mode = TRUE;
238 setup_newt_stuff();
239 finish(set_fattr_list(argv[2], argv[3]));
240 }
241
242 if (argc == 3 && !strcmp(argv[1], "wildcards")) {
243 g_loglevel = 10;
244 g_text_mode = TRUE;
245 setup_newt_stuff();
246 turn_wildcard_chars_into_literal_chars(tmp, argv[2]);
247 printf("in=%s; out=%s\n", argv[2], tmp);
248 finish(1);
249 }
250
251 if (argc == 4 && !strcmp(argv[1], "getfacl")) {
252 g_loglevel = 10;
253 g_text_mode = TRUE;
254 setup_newt_stuff();
255 if (!strstr(argv[2], "filelist")) {
256 printf("Sorry - filelist goes first\n");
257 finish(1);
258 } else {
259 finish(get_acl_list(argv[2], argv[3]));
260 }
261 finish(0);
262 }
263 if (argc == 4 && !strcmp(argv[1], "setfacl")) {
264 g_loglevel = 10;
265// chdir("/tmp");
266 g_text_mode = TRUE;
267 setup_newt_stuff();
268 finish(set_acl_list(argv[2], argv[3]));
269 }
270
271 if (argc > 2 && !strcmp(argv[1], "find-cd")) {
272 g_loglevel = 10;
273 g_text_mode = TRUE;
274 setup_newt_stuff();
275 if (find_cdrw_device(tmp)) {
276 printf("Failed to find CDR-RW drive\n");
277 } else {
278 printf("CD-RW is at %s\n", tmp);
279 }
280 tmp[0] = '\0';
281 if (find_cdrom_device(tmp, atoi(argv[2]))) {
282 printf("Failed to find CD-ROM drive\n");
283 } else {
284 printf("CD-ROM is at %s\n", tmp);
285 }
286 finish(0);
287 }
288
289 if (argc > 2 && !strcmp(argv[1], "find-dvd")) {
290 g_loglevel = 10;
291 g_text_mode = TRUE;
292 setup_newt_stuff();
293 if (find_dvd_device(tmp, atoi(argv[2]))) {
294 printf("Failed to find DVD drive\n");
295 } else {
296 printf("DVD is at %s\n", tmp);
297 }
298 finish(0);
299 }
300
301 if (argc > 2 && !strcmp(argv[1], "disksize")) {
302 printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2]));
303 finish(0);
304 }
305 if (argc > 2 && !strcmp(argv[1], "test-dev")) {
306 if (is_dev_an_NTFS_dev(argv[2])) {
307 printf("%s is indeed an NTFS dev\n", argv[2]);
308 } else {
309 printf("%s is _not_ an NTFS dev\n", argv[2]);
310 }
311 finish(0);
312 }
313
314 if (pre_param_configuration(bkpinfo)) {
315 fatal_error
316 ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting...");
317 }
318
319/* Process command line, if there is one. If not, ask user for info. */
320 if (argc == 1) {
321 g_text_mode = FALSE;
322 setup_newt_stuff();
323 res = interactively_obtain_media_parameters_from_user(bkpinfo, TRUE); /* yes, archiving */
324 if (res) {
325 fatal_error
326 ("Syntax error. Please review the parameters you have supplied and try again.");
327 }
328 } else {
329 res = handle_incoming_parameters(argc, argv, bkpinfo);
330 if (res) {
331 printf
332 ("Errors were detected in the command line you supplied.\n");
333 printf("Please review the log file - " MONDO_LOGFILE "\n");
334 log_msg(1, "Mondoarchive will now exit.");
335 finish(1);
336 }
337 setup_newt_stuff();
338 }
339
340/* Finish configuring global structures */
341 if (post_param_configuration(bkpinfo)) {
342 fatal_error
343 ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting...");
344 }
345
346 log_to_screen
347 ("BusyBox's sources are available from http://www.busybox.net");
348 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
349 bkpinfo->scratchdir);
350
351 /* If we're meant to backup then backup */
352 if (bkpinfo->backup_data) {
353 res = backup_data(bkpinfo);
354 retval += res;
355 if (res) {
356 strcat(say_at_end,
357 "Data archived. Please check the logs, just as a precaution. ");
358 } else {
359 strcat(say_at_end, "Data archived OK. ");
360 }
361 }
362
363/* If we're meant to verify then verify */
364 if (bkpinfo->verify_data) {
365 res = verify_data(bkpinfo);
366 if (res < 0) {
367 sprintf(tmp, "%d difference%c found.", -res,
368 (-res != 1) ? 's' : ' ');
369 strcat(say_at_end, tmp);
370 log_to_screen(tmp);
371 res = 0;
372 }
373 retval += res;
374 }
375
376/* Offer to write floppy disk images to physical disks */
377 if (bkpinfo->backup_data && !g_skip_floppies) {
378 res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo);
379 retval += res;
380// res = offer_to_write_boot_ISO_to_physical_CD(bkpinfo);
381// retval += res;
382 }
383
384/* Report result of entire operation (success? errors?) */
385 if (!retval) {
386 mvaddstr_and_log_it(g_currentY++, 0,
387 "Backup and/or verify ran to completion. Everything appears to be fine.");
388 } else {
389 mvaddstr_and_log_it(g_currentY++, 0,
390 "Backup and/or verify ran to completion. However, errors did occur.");
391 }
392
393 if (does_file_exist("/var/cache/mindi/mondorescue.iso")) {
394 log_to_screen
395 ("/var/cache/mindi/mondorescue.iso, a boot/utility CD, is available if you want it.");
396 }
397
398
399 if (length_of_file("/tmp/changed.files") > 2) {
400 if (g_text_mode) {
401 log_to_screen
402 ("Type 'less /tmp/changed.files' to see which files don't match the archives");
403 } else {
404 log_msg(1,
405 "Type 'less /tmp/changed.files' to see which files don't match the archives");
406 log_msg(2, "Calling popup_changelist_from_file()");
407 popup_changelist_from_file("/tmp/changed.files");
408 log_msg(2, "Returned from popup_changelist_from_file()");
409 }
410 } else {
411 unlink("/tmp/changed.files");
412 }
413 log_to_screen(say_at_end);
414 sprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
415 run_program_and_log_output(tmp, TRUE);
416 run_program_and_log_output(g_erase_tmpdir_and_scratchdir, TRUE);
417
418 run_program_and_log_output("mount", 2);
419
420 system("rm -f /var/cache/mondo-archive/last-backup.aborted");
421 system("rm -Rf /tmp.mondo.* /mondo.scratch.*");
422 if (!retval) {
423 printf("Mondoarchive ran OK.\n");
424 } else {
425 printf("Errors occurred during backup. Please check logfile.\n");
426 }
427 distro_specific_kludges_at_end_of_mondoarchive();
428 register_pid(0, "mondo");
429 set_signals(FALSE);
430 chdir("/tmp"); // just in case there's something wrong with g_erase_tmpdir_and_scratchdir
431 system(g_erase_tmpdir_and_scratchdir);
432 free_libmondo_global_strings();
433 mr_free(say_at_end);
434 mr_free(tmp);
435 mr_free(bkpinfo);
436
437 unlink("/tmp/filelist.full");
438 unlink("/tmp/filelist.full.gz");
439
440 if (!g_cdrom_drive_is_here) {
441 log_msg(10, "FYI, g_cdrom_drive_is_here was never used");
442 }
443 if (!g_dvd_drive_is_here) {
444 log_msg(10, "FYI, g_dvd_drive_is_here was never used");
445 }
446
447 /* finalize log file with time stamp */
448 log_msg(0, "Time finished: %s", mr_date());
449
450 if (!g_text_mode) {
451 popup_and_OK
452 ("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt.");
453 log_to_screen("See %s for details of backup run.", MONDO_LOGFILE);
454 finish(retval);
455 } else {
456 printf("See %s for details of backup run.\n", MONDO_LOGFILE);
457 exit(retval);
458 }
459
460 return EXIT_SUCCESS;
461}
Note: See TracBrowser for help on using the repository browser.