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