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