[1] | 1 | /***************************************************************************
|
---|
[1080] | 2 | * $Id: mondoarchive.c 1377 2007-04-30 09:25:39Z 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>
|
---|
| 18 |
|
---|
[1067] | 19 | #include "my-stuff.h"
|
---|
[1190] | 20 | #include "mondostructures.h"
|
---|
| 21 | #include "libmondo.h"
|
---|
[1] | 22 | #include "mondo-cli-EXT.h"
|
---|
| 23 |
|
---|
[1256] | 24 | #include "mondoarchive.h"
|
---|
[1187] | 25 | #include "mr_mem.h"
|
---|
[1087] | 26 | #include "mr_str.h"
|
---|
[1112] | 27 | #include "mr_msg.h"
|
---|
[1102] | 28 | #include "mr_file.h"
|
---|
[1264] | 29 | #include "mr_err.h"
|
---|
[1256] | 30 | #include "mr_conf.h"
|
---|
[1087] | 31 |
|
---|
[1] | 32 | // for CVS
|
---|
[128] | 33 | //static char cvsid[] = "$Id: mondoarchive.c 1377 2007-04-30 09:25:39Z bruno $";
|
---|
[1] | 34 |
|
---|
| 35 | /************************* external variables *************************/
|
---|
| 36 | extern void set_signals(int);
|
---|
| 37 | extern int g_current_media_number;
|
---|
[128] | 38 | extern void register_pid(pid_t, char *);
|
---|
[1] | 39 | extern int g_currentY;
|
---|
| 40 | extern bool g_text_mode;
|
---|
| 41 | extern char *g_boot_mountpt;
|
---|
| 42 | extern bool g_remount_cdrom_at_end, g_remount_floppy_at_end;
|
---|
| 43 | extern char *g_tmpfs_mountpt;
|
---|
| 44 | extern char *g_erase_tmpdir_and_scratchdir;
|
---|
| 45 | extern char *g_cdrw_drive_is_here;
|
---|
[1256] | 46 | extern double g_kernel_version;
|
---|
| 47 | extern char *g_magicdev_command;
|
---|
| 48 | extern t_bkptype g_backup_media_type;
|
---|
| 49 | extern int g_loglevel;
|
---|
| 50 |
|
---|
[128] | 51 | static char *g_cdrom_drive_is_here = NULL;
|
---|
| 52 | static char *g_dvd_drive_is_here = NULL;
|
---|
[1] | 53 |
|
---|
[1256] | 54 | struct mr_ar_conf mr_conf;
|
---|
| 55 |
|
---|
| 56 | /***************** global vars ******************/
|
---|
[1] | 57 | bool g_skip_floppies;
|
---|
| 58 | long diffs;
|
---|
| 59 |
|
---|
[1256] | 60 | /****************** subroutines used only here ******************/
|
---|
[1] | 61 |
|
---|
| 62 |
|
---|
| 63 | /**
|
---|
| 64 | * Print a "don't panic" message to the log and a message about the logfile to the screen.
|
---|
| 65 | */
|
---|
[1256] | 66 | static void welcome_to_mondoarchive(void)
|
---|
[1] | 67 | {
|
---|
[1377] | 68 | char *tmp = NULL;
|
---|
| 69 |
|
---|
[1256] | 70 | mr_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org", PACKAGE_VERSION);
|
---|
[1377] | 71 | log_msg(0, "running %s binaries", get_architecture());
|
---|
| 72 | tmp = get_uname_m();
|
---|
| 73 | log_msg(0, "running on %s architecture", tmp);
|
---|
| 74 | mr_free(tmp);
|
---|
[1256] | 75 | mr_msg(0, "-----------------------------------------------------------");
|
---|
| 76 | mr_msg(0, "NB: Mondo logs almost everything, so don't panic if you see");
|
---|
| 77 | mr_msg(0, "some error messages. Please read them carefully before you");
|
---|
| 78 | mr_msg(0, "decide to break out in a cold sweat. Despite (or perhaps");
|
---|
| 79 | mr_msg(0, "because of) the wealth of messages. some users are inclined");
|
---|
| 80 | mr_msg(0, "to stop reading this log. If Mondo stopped for some reason,");
|
---|
| 81 | mr_msg(0, "chances are it's detailed here. More than likely there's a");
|
---|
| 82 | mr_msg(0, "message at the very end of this log that will tell you what");
|
---|
| 83 | mr_msg(0, "is wrong. Please read it! -Devteam");
|
---|
| 84 | mr_msg(0, "-----------------------------------------------------------");
|
---|
[1] | 85 |
|
---|
[1108] | 86 | mr_msg(0, "Zero...");
|
---|
| 87 | mr_msg(1, "One...");
|
---|
| 88 | mr_msg(2, "Two...");
|
---|
| 89 | mr_msg(3, "Three...");
|
---|
| 90 | mr_msg(4, "Four...");
|
---|
| 91 | mr_msg(5, "Five...");
|
---|
| 92 | mr_msg(6, "Six...");
|
---|
| 93 | mr_msg(7, "Seven...");
|
---|
| 94 | mr_msg(8, "Eight...");
|
---|
[128] | 95 | printf("See %s for details of backup run.\n", MONDO_LOGFILE);
|
---|
[1] | 96 | }
|
---|
| 97 |
|
---|
| 98 | /**
|
---|
| 99 | * Do whatever is necessary to insure a successful backup on the Linux distribution
|
---|
| 100 | * of the day.
|
---|
| 101 | */
|
---|
[1256] | 102 | static void distro_specific_kludges_at_start_of_mondoarchive(void)
|
---|
[1] | 103 | {
|
---|
[1108] | 104 | mr_msg(2, "Unmounting old ramdisks if necessary");
|
---|
[128] | 105 | stop_magicdev_if_necessary(); // for RH+Gnome users
|
---|
| 106 | run_program_and_log_output
|
---|
| 107 | ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2);
|
---|
| 108 | unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted
|
---|
| 109 | mount_boot_if_necessary(); // for Gentoo users with non-mounted /boot partitions
|
---|
| 110 | clean_up_KDE_desktop_if_necessary(); // delete various misc ~/.* files that get in the way
|
---|
[1] | 111 | }
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | /**
|
---|
| 115 | * Undo whatever was done by distro_specific_kludges_at_start_of_mondoarchive().
|
---|
| 116 | */
|
---|
[1256] | 117 | static void distro_specific_kludges_at_end_of_mondoarchive(void)
|
---|
[1] | 118 | {
|
---|
[1108] | 119 | mr_msg(2, "Restarting magicdev if necessary");
|
---|
[128] | 120 | sync();
|
---|
| 121 | restart_magicdev_if_necessary(); // for RH+Gnome users
|
---|
[1] | 122 |
|
---|
[1108] | 123 | mr_msg(2, "Restarting supermounts if necessary");
|
---|
[128] | 124 | sync();
|
---|
| 125 | remount_supermounts_if_necessary(); // for Mandrake users
|
---|
[1] | 126 |
|
---|
[1108] | 127 | mr_msg(2, "Unmounting /boot if necessary");
|
---|
[128] | 128 | sync();
|
---|
| 129 | unmount_boot_if_necessary(); // for Gentoo users
|
---|
[1] | 130 | }
|
---|
| 131 |
|
---|
[1256] | 132 | /* create the mr_ar_conf structure from mondo's conf file */
|
---|
[1264] | 133 | static void mr_ar_store_conf(struct mr_ar_conf *mr_cnf) {
|
---|
[1256] | 134 |
|
---|
[1264] | 135 | mr_asprintf(&mr_cnf->iso_creation_cmd, mr_conf_sread("mondo_iso_creation_cmd"));
|
---|
| 136 | mr_asprintf(&mr_cnf->iso_creation_options, mr_conf_sread("mondo_iso_creation_options"));
|
---|
| 137 | mr_asprintf(&mr_cnf->iso_burning_cmd, mr_conf_sread("mondo_iso_burning_cmd"));
|
---|
| 138 | mr_asprintf(&mr_cnf->iso_burning_options, mr_conf_sread("mondo_iso_burning_options"));
|
---|
| 139 | mr_cnf->iso_burning_speed = mr_conf_iread("mondo_iso_burning_speed");
|
---|
| 140 | mr_cnf->media_size = mr_conf_iread("mondo_media_size");
|
---|
| 141 | mr_asprintf(&mr_cnf->media_device, mr_conf_sread("mondo_media_device"));
|
---|
| 142 | mr_cnf->manual_tray = mr_conf_bread("mondo_manual_tray");
|
---|
| 143 | mr_cnf->log_level = mr_conf_iread("mondo_log_level");
|
---|
| 144 | mr_asprintf(&mr_cnf->prefix, mr_conf_sread("mondo_prefix"));
|
---|
| 145 | mr_cnf->external_tape_blocksize = mr_conf_iread("mondo_external_tape_blocksize");
|
---|
| 146 | mr_cnf->internal_tape_blocksize = mr_conf_iread("mondo_internal_tape_blocksize");
|
---|
| 147 | mr_cnf->slice_size = mr_conf_iread("mondo_slice_size");
|
---|
| 148 | mr_asprintf(&mr_cnf->deplist_file, mr_conf_sread("mondo_deplist_file"));
|
---|
| 149 | mr_cnf->write_boot_floppy = mr_conf_bread("mondo_write_boot_floppy");
|
---|
| 150 | mr_cnf->create_mindi_cd = mr_conf_bread("mondo_create_mindi_cd");
|
---|
| 151 | mr_asprintf(&mr_cnf->kernel, mr_conf_sread("mondo_kernel"));
|
---|
| 152 | mr_asprintf(&mr_cnf->additional_modules, mr_conf_sread("mondo_additional_modules"));
|
---|
| 153 | mr_asprintf(&mr_cnf->boot_loader, mr_conf_sread("mondo_boot_loader"));
|
---|
| 154 | mr_cnf->differential = mr_conf_bread("mondo_differential");
|
---|
| 155 | mr_asprintf(&mr_cnf->compression_tool, mr_conf_sread("mondo_compression_tool"));
|
---|
| 156 | mr_cnf->compression_level = mr_conf_iread("mondo_compression_level");
|
---|
| 157 | mr_asprintf(&mr_cnf->exclude_paths, mr_conf_sread("mondo_exclude_paths"));
|
---|
| 158 | mr_asprintf(&mr_cnf->include_paths, mr_conf_sread("mondo_include_paths"));
|
---|
| 159 | mr_asprintf(&mr_cnf->ui_mode, mr_conf_sread("mondo_ui_mode"));
|
---|
| 160 | mr_cnf->automatic_restore = mr_conf_bread("mondo_automatic_restore");
|
---|
| 161 | mr_asprintf(&mr_cnf->scratch_dir, mr_conf_sread("mondo_scratch_dir"));
|
---|
| 162 | mr_asprintf(&mr_cnf->tmp_dir, mr_conf_sread("mondo_tmp_dir"));
|
---|
| 163 | mr_asprintf(&mr_cnf->images_dir, mr_conf_sread("mondo_images_dir"));
|
---|
| 164 | mr_msg(5, "Directory for images is %s", mr_cnf->images_dir);
|
---|
[1256] | 165 | }
|
---|
| 166 |
|
---|
[1264] | 167 | /* destroy the mr_ar_conf structure's content */
|
---|
| 168 | static void mr_ar_clean_conf(struct mr_ar_conf *mr_cnf) {
|
---|
| 169 |
|
---|
| 170 | if (mr_cnf == NULL) {
|
---|
| 171 | return;
|
---|
| 172 | }
|
---|
| 173 | mr_free(mr_cnf->iso_creation_cmd);
|
---|
| 174 | mr_free(mr_cnf->iso_creation_options);
|
---|
| 175 | mr_free(mr_cnf->iso_burning_cmd);
|
---|
| 176 | mr_free(mr_cnf->iso_burning_options);
|
---|
| 177 | mr_free(mr_cnf->media_device);
|
---|
| 178 | mr_free(mr_cnf->prefix);
|
---|
| 179 | mr_free(mr_cnf->deplist_file);
|
---|
| 180 | mr_free(mr_cnf->kernel);
|
---|
| 181 | mr_free(mr_cnf->additional_modules);
|
---|
| 182 | mr_free(mr_cnf->boot_loader);
|
---|
| 183 | mr_free(mr_cnf->compression_tool);
|
---|
| 184 | mr_free(mr_cnf->exclude_paths);
|
---|
| 185 | mr_free(mr_cnf->include_paths);
|
---|
| 186 | mr_free(mr_cnf->ui_mode);
|
---|
| 187 | mr_free(mr_cnf->scratch_dir);
|
---|
| 188 | mr_free(mr_cnf->tmp_dir);
|
---|
| 189 | mr_free(mr_cnf->images_dir);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | /* Create the pointer to the function called in mr_exit */
|
---|
| 193 | void (*mr_cleanup)(void) = NULL;
|
---|
| 194 |
|
---|
| 195 | /* Cleanup all memory allocated in various structures */
|
---|
| 196 | void mr_ar_cleanup(void) {
|
---|
| 197 | /* Highly incomplete function for the moment */
|
---|
| 198 | /* We have to free all allocated memory */
|
---|
| 199 | mr_ar_clean_conf(&mr_conf);
|
---|
| 200 | /* We have to remove all temporary files */
|
---|
| 201 | /* We have to unmount what has been mounted */
|
---|
| 202 | /* We have to properly end newt */
|
---|
| 203 | /* We have to remind people of log files */
|
---|
| 204 |
|
---|
| 205 | mr_msg_close();
|
---|
| 206 | }
|
---|
| 207 |
|
---|
[1] | 208 | /*-----------------------------------------------------------*/
|
---|
| 209 |
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | /**
|
---|
| 213 | * Backup/verify the user's data.
|
---|
| 214 | * What did you think it did, anyway? :-)
|
---|
| 215 | */
|
---|
[128] | 216 | int main(int argc, char *argv[])
|
---|
[1] | 217 | {
|
---|
[1256] | 218 | struct s_bkpinfo *bkpinfo = NULL;
|
---|
[1100] | 219 | struct stat stbuf;
|
---|
[1152] | 220 | char *tmp = NULL;
|
---|
[1187] | 221 | int res = 0;
|
---|
| 222 | int retval = 0;
|
---|
| 223 | char *say_at_end = NULL;
|
---|
[1190] | 224 | char *say_at_end2 = NULL;
|
---|
[1] | 225 |
|
---|
[1187] | 226 | #ifdef ENABLE_NLS
|
---|
| 227 | setlocale(LC_ALL, "");
|
---|
| 228 | (void) textdomain("mondo");
|
---|
| 229 | #endif
|
---|
[1256] | 230 | printf(_("Initializing..."));
|
---|
| 231 |
|
---|
[1264] | 232 | /* Reference the right cleanup function for mr_exit */
|
---|
[1269] | 233 | mr_cleanup = &mr_ar_cleanup;
|
---|
[1264] | 234 |
|
---|
[1256] | 235 | /* initialize log file with time stamp */
|
---|
| 236 | /* We start with a loglevel of 4 - Adapted later on */
|
---|
| 237 | /* It's mandatory to set this up first as all mr_ functions rely on it */
|
---|
| 238 | unlink(MONDO_LOGFILE);
|
---|
| 239 | mr_msg_init(MONDO_LOGFILE,4);
|
---|
| 240 | mr_msg(0, _("Time started: %s"), mr_date());
|
---|
| 241 |
|
---|
| 242 | /* Make sure I'm root; abort if not */
|
---|
[128] | 243 | if (getuid() != 0) {
|
---|
[1256] | 244 | mr_log_exit(127, _("Please run as root."));
|
---|
[128] | 245 | }
|
---|
[1] | 246 |
|
---|
[1187] | 247 | /* If -V, -v or --version then echo version no. and quit */
|
---|
[128] | 248 | if (argc == 2
|
---|
| 249 | && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
|
---|
| 250 | || !strcmp(argv[argc - 1], "--version"))) {
|
---|
[1187] | 251 | printf(_("mondoarchive v%s\nSee man page for help\n"), PACKAGE_VERSION);
|
---|
[1256] | 252 | mr_exit(0, NULL);
|
---|
[128] | 253 | }
|
---|
[1] | 254 |
|
---|
[1256] | 255 | /* Conf file management */
|
---|
| 256 | /* Check md5 sum before */
|
---|
| 257 | /* Get content */
|
---|
| 258 | if (mr_conf_open(MONDO_CONF_DIR"/mondo.conf.dist") != 0) {
|
---|
| 259 | mr_log_exit(-1, "Unable to open "MONDO_CONF_DIR"/mondo.conf.dist");
|
---|
| 260 | }
|
---|
| 261 | mr_ar_store_conf(&mr_conf);
|
---|
| 262 | mr_conf_close();
|
---|
| 263 |
|
---|
| 264 | /* Add MONDO_SHARE + other environment variables for mindi */
|
---|
| 265 | setenv_mondo_var();
|
---|
| 266 |
|
---|
[1187] | 267 | /* Initialize variables */
|
---|
[128] | 268 | malloc_libmondo_global_strings();
|
---|
| 269 | diffs = 0;
|
---|
[1132] | 270 | bkpinfo = mr_malloc(sizeof(struct s_bkpinfo));
|
---|
[1100] | 271 | if (stat(MONDO_CACHE, &stbuf) != 0) {
|
---|
| 272 | mr_mkdir(MONDO_CACHE,0x755);
|
---|
| 273 | }
|
---|
| 274 |
|
---|
[1140] | 275 | /* BERLIOS: Hardcoded to be improved */
|
---|
| 276 | unlink(MONDO_CACHE"/mindi.conf");
|
---|
[1143] | 277 | unlink(MONDORESTORECFG);
|
---|
[1140] | 278 |
|
---|
[807] | 279 | /* Configure the bkpinfo structure, global file paths, etc. */
|
---|
[128] | 280 | g_main_pid = getpid();
|
---|
[1108] | 281 | mr_msg(9, "This");
|
---|
[1] | 282 |
|
---|
[128] | 283 | register_pid(g_main_pid, "mondo");
|
---|
| 284 | set_signals(TRUE); // catch SIGTERM, etc.
|
---|
| 285 | run_program_and_log_output("dmesg -n1", TRUE);
|
---|
[1] | 286 |
|
---|
[1108] | 287 | mr_msg(9, "Next");
|
---|
[128] | 288 | welcome_to_mondoarchive();
|
---|
| 289 | distro_specific_kludges_at_start_of_mondoarchive();
|
---|
| 290 | g_kernel_version = get_kernel_version();
|
---|
[1] | 291 |
|
---|
[128] | 292 | if (argc == 4 && !strcmp(argv[1], "getfattr")) {
|
---|
| 293 | g_loglevel = 10;
|
---|
| 294 | g_text_mode = TRUE;
|
---|
| 295 | setup_newt_stuff();
|
---|
| 296 | if (!strstr(argv[2], "filelist")) {
|
---|
[1187] | 297 | mr_msg(1,_("Sorry - filelist goes first\n"));
|
---|
[128] | 298 | finish(1);
|
---|
| 299 | } else {
|
---|
| 300 | finish(get_fattr_list(argv[2], argv[3]));
|
---|
| 301 | }
|
---|
| 302 | finish(0);
|
---|
[1] | 303 | }
|
---|
[128] | 304 | if (argc == 4 && !strcmp(argv[1], "setfattr")) {
|
---|
| 305 | g_loglevel = 10;
|
---|
| 306 | g_text_mode = TRUE;
|
---|
| 307 | setup_newt_stuff();
|
---|
| 308 | finish(set_fattr_list(argv[2], argv[3]));
|
---|
[1] | 309 | }
|
---|
[128] | 310 |
|
---|
| 311 | if (argc == 3 && !strcmp(argv[1], "wildcards")) {
|
---|
| 312 | g_loglevel = 10;
|
---|
| 313 | g_text_mode = TRUE;
|
---|
| 314 | setup_newt_stuff();
|
---|
[1241] | 315 | tmp = mr_stresc(argv[2], WILDCHARS, BACKSLASH);
|
---|
[128] | 316 | printf("in=%s; out=%s\n", argv[2], tmp);
|
---|
[1152] | 317 | mr_free(tmp);
|
---|
[128] | 318 | finish(1);
|
---|
[1] | 319 | }
|
---|
[128] | 320 |
|
---|
| 321 | if (argc == 4 && !strcmp(argv[1], "getfacl")) {
|
---|
| 322 | g_loglevel = 10;
|
---|
| 323 | g_text_mode = TRUE;
|
---|
| 324 | setup_newt_stuff();
|
---|
| 325 | if (!strstr(argv[2], "filelist")) {
|
---|
[1187] | 326 | mr_msg(1,_("Sorry - filelist goes first\n"));
|
---|
[128] | 327 | finish(1);
|
---|
| 328 | } else {
|
---|
| 329 | finish(get_acl_list(argv[2], argv[3]));
|
---|
| 330 | }
|
---|
| 331 | finish(0);
|
---|
| 332 | }
|
---|
| 333 | if (argc == 4 && !strcmp(argv[1], "setfacl")) {
|
---|
| 334 | g_loglevel = 10;
|
---|
| 335 | g_text_mode = TRUE;
|
---|
| 336 | setup_newt_stuff();
|
---|
| 337 | finish(set_acl_list(argv[2], argv[3]));
|
---|
| 338 | }
|
---|
[1] | 339 |
|
---|
[128] | 340 | if (argc > 2 && !strcmp(argv[1], "find-cd")) {
|
---|
| 341 | g_loglevel = 10;
|
---|
| 342 | g_text_mode = TRUE;
|
---|
| 343 | setup_newt_stuff();
|
---|
[1152] | 344 | malloc_string(tmp);
|
---|
[128] | 345 | if (find_cdrw_device(tmp)) {
|
---|
[1187] | 346 | mr_msg(1,_("Failed to find CDR-RW drive\n"));
|
---|
[128] | 347 | } else {
|
---|
[1187] | 348 | mr_msg(1,_("CD-RW is at %s\n"), tmp);
|
---|
[128] | 349 | }
|
---|
| 350 | tmp[0] = '\0';
|
---|
| 351 | if (find_cdrom_device(tmp, atoi(argv[2]))) {
|
---|
[1187] | 352 | mr_msg(1,_("Failed to find CD-ROM drive\n"));
|
---|
[128] | 353 | } else {
|
---|
[1187] | 354 | mr_msg(1,_("CD-ROM is at %s\n"), tmp);
|
---|
[128] | 355 | }
|
---|
[1152] | 356 | mr_free(tmp);
|
---|
[128] | 357 | finish(0);
|
---|
| 358 | }
|
---|
[1] | 359 |
|
---|
[128] | 360 | if (argc > 2 && !strcmp(argv[1], "find-dvd")) {
|
---|
| 361 | g_loglevel = 10;
|
---|
| 362 | g_text_mode = TRUE;
|
---|
| 363 | setup_newt_stuff();
|
---|
[1152] | 364 | malloc_string(tmp);
|
---|
[128] | 365 | if (find_dvd_device(tmp, atoi(argv[2]))) {
|
---|
[1187] | 366 | mr_msg(1,_("Failed to find DVD drive\n"));
|
---|
[128] | 367 | } else {
|
---|
[1187] | 368 | mr_msg(1,_("DVD is at %s\n"), tmp);
|
---|
[128] | 369 | }
|
---|
[1152] | 370 | mr_free(tmp);
|
---|
[128] | 371 | finish(0);
|
---|
| 372 | }
|
---|
[1] | 373 |
|
---|
[128] | 374 | if (argc > 2 && !strcmp(argv[1], "disksize")) {
|
---|
| 375 | printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2]));
|
---|
| 376 | finish(0);
|
---|
| 377 | }
|
---|
| 378 | if (argc > 2 && !strcmp(argv[1], "test-dev")) {
|
---|
| 379 | if (is_dev_an_NTFS_dev(argv[2])) {
|
---|
[1187] | 380 | mr_msg(1,_("%s is indeed an NTFS dev\n"), argv[2]);
|
---|
[128] | 381 | } else {
|
---|
[1187] | 382 | mr_msg(1,_("%s is _not_ an NTFS dev\n"), argv[2]);
|
---|
[128] | 383 | }
|
---|
| 384 | finish(0);
|
---|
| 385 | }
|
---|
| 386 |
|
---|
| 387 | if (pre_param_configuration(bkpinfo)) {
|
---|
| 388 | fatal_error
|
---|
| 389 | ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting...");
|
---|
| 390 | }
|
---|
[1140] | 391 | sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
|
---|
| 392 | bkpinfo->scratchdir);
|
---|
[128] | 393 |
|
---|
[1140] | 394 | /* Process command line, if there is one. If not, ask user for info. */
|
---|
[128] | 395 | if (argc == 1) {
|
---|
| 396 | g_text_mode = FALSE;
|
---|
| 397 | setup_newt_stuff();
|
---|
| 398 | res = interactively_obtain_media_parameters_from_user(bkpinfo, TRUE); /* yes, archiving */
|
---|
| 399 | if (res) {
|
---|
| 400 | fatal_error
|
---|
| 401 | ("Syntax error. Please review the parameters you have supplied and try again.");
|
---|
| 402 | }
|
---|
| 403 | } else {
|
---|
| 404 | res = handle_incoming_parameters(argc, argv, bkpinfo);
|
---|
| 405 | if (res) {
|
---|
[1187] | 406 | mr_msg(1,
|
---|
| 407 | _("Errors were detected in the command line you supplied.\n"));
|
---|
| 408 | mr_msg(1,_("Please review the log file - %s \n"),MONDO_LOGFILE);
|
---|
[1108] | 409 | mr_msg(1, "Mondoarchive will now exit.");
|
---|
[128] | 410 | finish(1);
|
---|
| 411 | }
|
---|
| 412 | setup_newt_stuff();
|
---|
[1] | 413 | }
|
---|
| 414 |
|
---|
| 415 | /* Finish configuring global structures */
|
---|
[128] | 416 | if (post_param_configuration(bkpinfo)) {
|
---|
| 417 | fatal_error
|
---|
| 418 | ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting...");
|
---|
| 419 | }
|
---|
[1] | 420 |
|
---|
[128] | 421 | log_to_screen
|
---|
[1187] | 422 | (_("BusyBox's sources are available from http://www.busybox.net"));
|
---|
| 423 |
|
---|
[128] | 424 | sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
|
---|
| 425 | bkpinfo->scratchdir);
|
---|
[1] | 426 |
|
---|
[128] | 427 | /* If we're meant to backup then backup */
|
---|
| 428 | if (bkpinfo->backup_data) {
|
---|
[541] | 429 | res = backup_data(bkpinfo);
|
---|
[128] | 430 | retval += res;
|
---|
| 431 | if (res) {
|
---|
[1187] | 432 | mr_strcat(say_at_end,
|
---|
| 433 | _("Data archived. Please check the logs, just as a precaution. "));
|
---|
[128] | 434 | } else {
|
---|
[1187] | 435 | mr_strcat(say_at_end, _("Data archived OK. "));
|
---|
[128] | 436 | }
|
---|
| 437 | }
|
---|
[1] | 438 |
|
---|
[1187] | 439 | /* If we're meant to verify then verify */
|
---|
[128] | 440 | if (bkpinfo->verify_data) {
|
---|
| 441 | res = verify_data(bkpinfo);
|
---|
| 442 | if (res < 0) {
|
---|
[1190] | 443 | mr_asprintf(&say_at_end2, _("%d difference%c found."), -res,
|
---|
[128] | 444 | (-res != 1) ? 's' : ' ');
|
---|
| 445 | res = 0;
|
---|
| 446 | }
|
---|
| 447 | retval += res;
|
---|
| 448 | }
|
---|
[1] | 449 |
|
---|
[1187] | 450 | /* Offer to write floppy disk images to physical disks */
|
---|
[128] | 451 | if (bkpinfo->backup_data && !g_skip_floppies) {
|
---|
| 452 | res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo);
|
---|
| 453 | retval += res;
|
---|
| 454 | }
|
---|
[1] | 455 |
|
---|
[1187] | 456 | /* Report result of entire operation (success? errors?) */
|
---|
[128] | 457 | if (!retval) {
|
---|
| 458 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
[1187] | 459 | _("Backup and/or verify ran to completion. Everything appears to be fine."));
|
---|
[128] | 460 | } else {
|
---|
| 461 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
[1187] | 462 | _("Backup and/or verify ran to completion. However, errors did occur."));
|
---|
[128] | 463 | }
|
---|
[1] | 464 |
|
---|
[1044] | 465 | if (does_file_exist("/var/cache/mindi/mondorescue.iso")) {
|
---|
[128] | 466 | log_to_screen
|
---|
[1187] | 467 | (_("/var/cache/mindi/mondorescue.iso, a boot/utility CD, is available if you want it."));
|
---|
[128] | 468 | }
|
---|
[1] | 469 |
|
---|
| 470 |
|
---|
[128] | 471 | if (length_of_file("/tmp/changed.files") > 2) {
|
---|
| 472 | if (g_text_mode) {
|
---|
| 473 | log_to_screen
|
---|
[1187] | 474 | (_("Type 'less /tmp/changed.files' to see which files don't match the archives"));
|
---|
[128] | 475 | } else {
|
---|
[1108] | 476 | mr_msg(1,
|
---|
[1187] | 477 | _("Type 'less /tmp/changed.files' to see which files don't match the archives"));
|
---|
[1108] | 478 | mr_msg(2, "Calling popup_changelist_from_file()");
|
---|
[128] | 479 | popup_changelist_from_file("/tmp/changed.files");
|
---|
[1108] | 480 | mr_msg(2, "Returned from popup_changelist_from_file()");
|
---|
[128] | 481 | }
|
---|
| 482 | } else {
|
---|
| 483 | unlink("/tmp/changed.files");
|
---|
| 484 | }
|
---|
| 485 | log_to_screen(say_at_end);
|
---|
[1187] | 486 | mr_free(say_at_end);
|
---|
[1190] | 487 | if (say_at_end2 != NULL) {
|
---|
| 488 | log_to_screen(say_at_end2);
|
---|
| 489 | mr_free(say_at_end2);
|
---|
| 490 | }
|
---|
[1187] | 491 |
|
---|
[1152] | 492 | mr_asprintf(&tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
|
---|
[128] | 493 | run_program_and_log_output(tmp, TRUE);
|
---|
[1152] | 494 | mr_free(tmp);
|
---|
[128] | 495 | run_program_and_log_output(g_erase_tmpdir_and_scratchdir, TRUE);
|
---|
[1] | 496 |
|
---|
[128] | 497 | run_program_and_log_output("mount", 2);
|
---|
[1] | 498 |
|
---|
[128] | 499 | system("rm -f /var/cache/mondo-archive/last-backup.aborted");
|
---|
| 500 | system("rm -Rf /tmp.mondo.* /mondo.scratch.*");
|
---|
| 501 | if (!retval) {
|
---|
[1187] | 502 | printf(_("Mondoarchive ran OK.\n"));
|
---|
[128] | 503 | } else {
|
---|
[1187] | 504 | printf(_("Errors occurred during backup. Please check logfile.\n"));
|
---|
[128] | 505 | }
|
---|
| 506 | distro_specific_kludges_at_end_of_mondoarchive();
|
---|
| 507 | register_pid(0, "mondo");
|
---|
| 508 | set_signals(FALSE);
|
---|
| 509 | chdir("/tmp"); // just in case there's something wrong with g_erase_tmpdir_and_scratchdir
|
---|
| 510 | system(g_erase_tmpdir_and_scratchdir);
|
---|
| 511 | free_libmondo_global_strings();
|
---|
[1080] | 512 | mr_free(bkpinfo);
|
---|
[1] | 513 |
|
---|
[128] | 514 | unlink("/tmp/filelist.full");
|
---|
| 515 | unlink("/tmp/filelist.full.gz");
|
---|
[1] | 516 |
|
---|
[128] | 517 | if (!g_cdrom_drive_is_here) {
|
---|
[1108] | 518 | mr_msg(10, "FYI, g_cdrom_drive_is_here was never used");
|
---|
[128] | 519 | }
|
---|
| 520 | if (!g_dvd_drive_is_here) {
|
---|
[1108] | 521 | mr_msg(10, "FYI, g_dvd_drive_is_here was never used");
|
---|
[128] | 522 | }
|
---|
[1] | 523 |
|
---|
[810] | 524 | /* finalize log file with time stamp */
|
---|
[1187] | 525 | mr_msg(1, "Time finished: %s", mr_date());
|
---|
[1132] | 526 | mr_msg_close();
|
---|
[810] | 527 |
|
---|
[128] | 528 | if (!g_text_mode) {
|
---|
| 529 | popup_and_OK
|
---|
[1187] | 530 | (_("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt."));
|
---|
| 531 | log_to_screen(_("See %s for details of backup run."), MONDO_LOGFILE);
|
---|
[128] | 532 | finish(retval);
|
---|
| 533 | } else {
|
---|
[1187] | 534 | printf(_("See %s for details of backup run.\n"), MONDO_LOGFILE);
|
---|
[1264] | 535 | mr_exit(retval, NULL);
|
---|
[128] | 536 | }
|
---|
| 537 |
|
---|
| 538 | return EXIT_SUCCESS;
|
---|
[1] | 539 | }
|
---|