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