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