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