1 | /***************************************************************************
|
---|
2 | $Id: libmondo-cli.c 2332 2009-08-18 13:33:19Z bruno $
|
---|
3 | *******************************************************************/
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * @file
|
---|
7 | * Functions for handling command-line arguments passed to mondoarchive.
|
---|
8 | */
|
---|
9 |
|
---|
10 | /** @def BOOT_LOADER_CHARS The characters allowed for boot loader on this platform. */
|
---|
11 |
|
---|
12 | #include <pthread.h>
|
---|
13 | #include "my-stuff.h"
|
---|
14 | #include "mr_mem.h"
|
---|
15 | #include "mr_str.h"
|
---|
16 | #include "mondostructures.h"
|
---|
17 | #include "libmondo-cli-EXT.h"
|
---|
18 | #include "libmondo.h"
|
---|
19 |
|
---|
20 | extern int g_loglevel;
|
---|
21 | extern bool g_text_mode;
|
---|
22 | extern char g_startdir[MAX_STR_LEN]; ///< ????? @bug ?????
|
---|
23 | extern char *MONDO_OPTIONS;
|
---|
24 |
|
---|
25 | /*@ file pointer **************************************************/
|
---|
26 | extern FILE *g_tape_stream;
|
---|
27 |
|
---|
28 | /*@ long long *****************************************************/
|
---|
29 | extern long long g_tape_posK;
|
---|
30 |
|
---|
31 | /*@ long **********************************************************/
|
---|
32 | extern long g_noof_sets;
|
---|
33 |
|
---|
34 | /*@ bool******** **************************************************/
|
---|
35 | bool g_debugging = FALSE; ///< ????? @bug ????? @ingroup globalGroup
|
---|
36 | bool g_running_live = FALSE; ///< ????? @bug ????? @ingroup globalGroup
|
---|
37 | extern bool g_cd_recovery;
|
---|
38 |
|
---|
39 | extern void setup_tmpdir(char *path);
|
---|
40 | extern double g_kernel_version;
|
---|
41 | extern int g_current_media_number;
|
---|
42 | extern pid_t g_main_pid;
|
---|
43 | extern char *resolve_softlinks_to_get_to_actual_device_file(char *);
|
---|
44 |
|
---|
45 | /* Stuff that handles the -I and -E option when a whole disk DSF is used */
|
---|
46 | typedef struct mounted_fs_struct {
|
---|
47 | char device[MAX_STR_LEN]; /* The name of the device */
|
---|
48 | char mount_point[MAX_STR_LEN]; /* The devices mount point */
|
---|
49 | unsigned char check; /* 1 == included on DSF */
|
---|
50 | struct mounted_fs_struct *next;
|
---|
51 | } MOUNTED_FS_STRUCT;
|
---|
52 | static MOUNTED_FS_STRUCT *DSF_Head = NULL; /* Points to the first entry of mounted_fs_struct list */
|
---|
53 | static MOUNTED_FS_STRUCT *DSF_Tail = NULL; /* Points to the last entry of mounted_fs_struct list */
|
---|
54 | static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr);
|
---|
55 | static void free_mounted_fs_list (void);
|
---|
56 | static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list);
|
---|
57 | static int create_list_of_non_NFS_mounted_file_systems (void);
|
---|
58 | static MOUNTED_FS_STRUCT *find_mount_point_in_list (const char *mount_point);
|
---|
59 | static MOUNTED_FS_STRUCT *find_device_in_list (const char *device);
|
---|
60 |
|
---|
61 | /* Do we use extended attributes and acl ?
|
---|
62 | * By default no, use --acl & --attr options to force their usage */
|
---|
63 | extern char *g_getfacl;
|
---|
64 | extern char *g_getfattr;
|
---|
65 |
|
---|
66 | /* Reference to global bkpinfo */
|
---|
67 | extern struct s_bkpinfo *bkpinfo;
|
---|
68 |
|
---|
69 | extern void free_MR_global_filenames(void);
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * @addtogroup cliGroup
|
---|
73 | * @{
|
---|
74 | */
|
---|
75 | /**
|
---|
76 | * Populate @p bkpinfo from the command-line parameters stored in @p argc and @p argv.
|
---|
77 | * @param argc The argument count, including the program name; @p argc passed to main().
|
---|
78 | * @param argv The argument vector; @p argv passed to main().
|
---|
79 | * @param bkpinfo The backup information structure to populate.
|
---|
80 | * @return The number of problems with the command line (0 for success).
|
---|
81 | */
|
---|
82 | int
|
---|
83 | handle_incoming_parameters(int argc, char *argv[])
|
---|
84 | {
|
---|
85 | /*@ int *** */
|
---|
86 | int res = 0;
|
---|
87 | int retval = 0;
|
---|
88 | int i = 0, j;
|
---|
89 |
|
---|
90 | /*@ buffers *************** */
|
---|
91 | char *tmp = NULL;
|
---|
92 | char flag_val[128][MAX_STR_LEN];
|
---|
93 | bool flag_set[128];
|
---|
94 |
|
---|
95 | for (i = 0; i < 128; i++) {
|
---|
96 | flag_val[i][0] = '\0';
|
---|
97 | flag_set[i] = FALSE;
|
---|
98 | }
|
---|
99 | for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
|
---|
100 | bkpinfo->media_size[j] = 650;
|
---|
101 | } /* default */
|
---|
102 | res =
|
---|
103 | retrieve_switches_from_command_line(argc, argv, flag_val,
|
---|
104 | flag_set);
|
---|
105 | retval += res;
|
---|
106 | if (!retval) {
|
---|
107 | res = process_switches(flag_val, flag_set);
|
---|
108 | retval += res;
|
---|
109 | }
|
---|
110 | log_msg(3, "Switches:-");
|
---|
111 | for (i = 0; i < 128; i++) {
|
---|
112 | if (flag_set[i]) {
|
---|
113 | log_msg(3, "-%c %s", i, flag_val[i]);
|
---|
114 | }
|
---|
115 | }
|
---|
116 | mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
|
---|
117 | paranoid_system(tmp);
|
---|
118 | mr_free(tmp);
|
---|
119 |
|
---|
120 | mr_asprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir);
|
---|
121 | paranoid_system(tmp);
|
---|
122 | mr_free(tmp);
|
---|
123 | return (retval);
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 |
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Store the sizespec(s) stored in @p value into @p bkpinfo.
|
---|
131 | * @param bkpinfo The backup information structure; the @c bkpinfo->media_size field will be populated.
|
---|
132 | * @param value The sizespec (e.g. "2g", "40m").
|
---|
133 | * @return 0, always.
|
---|
134 | * @bug Return code not needed.
|
---|
135 | */
|
---|
136 | int process_the_s_switch(char *value)
|
---|
137 | {
|
---|
138 | int j;
|
---|
139 | char tmp[MAX_STR_LEN], *p;
|
---|
140 |
|
---|
141 | assert(bkpinfo != NULL);
|
---|
142 | assert(value != NULL);
|
---|
143 |
|
---|
144 | bkpinfo->media_size[0] = -1; /* dummy value */
|
---|
145 | for (j = 1, p = value; j < MAX_NOOF_MEDIA && strchr(p, ',');
|
---|
146 | j++, p = strchr(p, ',') + 1) {
|
---|
147 | strncpy(tmp, p, MAX_STR_LEN);
|
---|
148 | *(strchr(tmp, ',')) = '\0';
|
---|
149 | bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp);
|
---|
150 | log_msg(3, "media_size[%d] = %ld", j, bkpinfo->media_size[j]);
|
---|
151 | }
|
---|
152 | for (; j <= MAX_NOOF_MEDIA; j++) {
|
---|
153 | bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p);
|
---|
154 | }
|
---|
155 | for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
|
---|
156 | if (bkpinfo->media_size[j] <= 0) {
|
---|
157 | log_msg(1, "You gave media #%d an invalid size\n", j);
|
---|
158 | return (-1);
|
---|
159 | }
|
---|
160 | }
|
---|
161 | return (0);
|
---|
162 | }
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Frees the memory for all of the structures on the linked list of
|
---|
166 | * all of the non-NFS mounted file systems.
|
---|
167 | */
|
---|
168 | static void free_mounted_fs_list (void) {
|
---|
169 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
---|
170 | MOUNTED_FS_STRUCT *DSFnext = NULL;
|
---|
171 |
|
---|
172 | DSFptr = DSF_Head;
|
---|
173 | while (DSFptr != NULL) {
|
---|
174 | DSFnext = DSFptr->next;
|
---|
175 | mr_free(DSFptr);
|
---|
176 | DSFptr = DSFnext;
|
---|
177 | }
|
---|
178 | DSF_Head = NULL;
|
---|
179 | DSF_Tail = NULL;
|
---|
180 | }
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Creates a singly linked list of all of the non-NFS mounted file systems.
|
---|
184 | * @param DSFptr A pointer to the structure MOUNTED_FS_STRUCT used to hold
|
---|
185 | * the list of mounted file systems.
|
---|
186 | * @return None.
|
---|
187 | */
|
---|
188 | static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr)
|
---|
189 | {
|
---|
190 | assert (DSFptr);
|
---|
191 | if (DSF_Head == NULL) {
|
---|
192 | DSF_Head = DSFptr;
|
---|
193 | } else {
|
---|
194 | DSF_Tail->next = DSFptr;
|
---|
195 | }
|
---|
196 | DSFptr->next = NULL;
|
---|
197 | DSF_Tail = DSFptr;
|
---|
198 | }
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Find the structure, in the singly linked list of all of the non-NFS
|
---|
202 | * mounted file systems, that contains the specified device.
|
---|
203 | * @param device The device to find
|
---|
204 | * @return NULL if it didn't find the device, a pointer to the
|
---|
205 | * structure if it did.
|
---|
206 | */
|
---|
207 | static MOUNTED_FS_STRUCT *find_device_in_list (const char *device)
|
---|
208 | {
|
---|
209 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
---|
210 |
|
---|
211 | DSFptr = DSF_Head;
|
---|
212 | while (DSFptr != NULL) {
|
---|
213 | if (!strcmp(DSFptr->device, device)) {
|
---|
214 | break;
|
---|
215 | }
|
---|
216 | DSFptr = DSFptr->next;
|
---|
217 | }
|
---|
218 | return (DSFptr);
|
---|
219 | }
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Find the structure, in the singly linked list of all of the non-NFS
|
---|
223 | * mounted file systems, that contains the specified mount point.
|
---|
224 | * @param mount_point The mount point to find
|
---|
225 | * @return NULL is it didn't find the mount point, a pointer to the
|
---|
226 | * structure if it did.
|
---|
227 | */
|
---|
228 | static MOUNTED_FS_STRUCT *find_mount_point_in_list (const char *mount_point)
|
---|
229 | {
|
---|
230 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
---|
231 |
|
---|
232 | DSFptr = DSF_Head;
|
---|
233 | while (DSFptr != NULL) {
|
---|
234 | if (!strcmp(DSFptr->mount_point, mount_point)) {
|
---|
235 | break;
|
---|
236 | }
|
---|
237 | DSFptr = DSFptr->next;
|
---|
238 | }
|
---|
239 | return (DSFptr);
|
---|
240 | }
|
---|
241 |
|
---|
242 | /**
|
---|
243 | * Creates a linked list of all of the non-NFS mounted file systems.
|
---|
244 | * We use a linked list because we don't know how many mounted file
|
---|
245 | * there are (and there can be a lot).
|
---|
246 | * @return 0 on success and greated than 0 on failure.
|
---|
247 | */
|
---|
248 | static int create_list_of_non_NFS_mounted_file_systems (void)
|
---|
249 | {
|
---|
250 | int i = 0;
|
---|
251 | int mount_cnt = 0;
|
---|
252 | char *mounted_file_system = NULL;
|
---|
253 | char *command = NULL;
|
---|
254 | char *token = NULL;
|
---|
255 | char token_chars[] =" :\t\r\f\a\0";
|
---|
256 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
---|
257 |
|
---|
258 | free_mounted_fs_list();
|
---|
259 | /********
|
---|
260 | * Find the number of mounted file system entries and their respective mount points.
|
---|
261 | * I can't return all of the entries as one string because it's length can be longer
|
---|
262 | * than MAX_STR_LEN which is used in call_program_and_get_last_line_of_output().
|
---|
263 | * So start looping and get the number of mounted file systems and query them one by one.
|
---|
264 | ********/
|
---|
265 | /* Get the number of mounted file systems ((those that start with "/dev/" */
|
---|
266 | mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");
|
---|
267 | log_msg(5, "Running: %s", command);
|
---|
268 | mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
|
---|
269 | mr_free(command);
|
---|
270 |
|
---|
271 | mount_cnt = atoi(mounted_file_system);
|
---|
272 | log_msg (5, "mount_cnt: %d", mount_cnt);
|
---|
273 | mr_free(mounted_file_system);
|
---|
274 |
|
---|
275 | for (i=mount_cnt; i > 0; i--) {
|
---|
276 | mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);
|
---|
277 | log_msg(5, "Running: %s", command);
|
---|
278 | mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
|
---|
279 | mr_free(command);
|
---|
280 |
|
---|
281 | log_msg (5, "mounted_file_system: %s", mounted_file_system);
|
---|
282 | if ((token = strtok(mounted_file_system, token_chars)) == NULL) {
|
---|
283 | log_msg (4, "Could not get the list of mounted file systems");
|
---|
284 | mr_free(mounted_file_system);
|
---|
285 | mr_free(token);
|
---|
286 | return (1);
|
---|
287 | }
|
---|
288 | if (token) {
|
---|
289 | log_msg (5, "token: %s", token);
|
---|
290 | }
|
---|
291 | while (token != NULL) {
|
---|
292 | log_msg (5, "token: %s", token);
|
---|
293 | if ((DSFptr = (MOUNTED_FS_STRUCT *) calloc(1, sizeof(MOUNTED_FS_STRUCT))) == NULL) {
|
---|
294 | fatal_error ("Cannot allocate memory");
|
---|
295 | }
|
---|
296 | add_mounted_fs_struct(DSFptr);
|
---|
297 | strcpy(DSFptr->device, token);
|
---|
298 | mr_free(token);
|
---|
299 | if ((token = strtok(NULL, token_chars)) == NULL) {
|
---|
300 | log_msg (5, "Ran out of entries on the mounted file systems list");
|
---|
301 | mr_free(mounted_file_system);
|
---|
302 | mr_free(token);
|
---|
303 | return (1);
|
---|
304 | }
|
---|
305 | log_msg (5, "token: %s", token);
|
---|
306 | strcpy(DSFptr->mount_point, token);
|
---|
307 | mr_free(token);
|
---|
308 | token = strtok(NULL, token_chars);
|
---|
309 | }
|
---|
310 | mr_free(mounted_file_system);
|
---|
311 | }
|
---|
312 | /********
|
---|
313 | * DSFptr = DSF_Head;
|
---|
314 | * while (DSFptr != NULL) {
|
---|
315 | * printf ("Dev: %s MP: %s Check: %d\n", DSFptr->device, DSFptr->mount_point, DSFptr->check);
|
---|
316 | * DSFptr = DSFptr->next;
|
---|
317 | * }
|
---|
318 | ********/
|
---|
319 | return (0);
|
---|
320 | }
|
---|
321 |
|
---|
322 | /**
|
---|
323 | * Given a whole disk device special file, determine which mounted file systems
|
---|
324 | * are on the dsf's partitions and which mounted file systems are not.
|
---|
325 | * @param dsf The whole disk device special file.
|
---|
326 | * @param included_dsf_list A char pointer used to hold the list of mount points
|
---|
327 | * that are on the dsf. Memory for the array will be allocated within the function.
|
---|
328 | * @param excluded_dsf_list A char pointer used to hold the list of mount points
|
---|
329 | * that are not on the dsf. Memory for the array will be allocated within the function.
|
---|
330 | * @return 0 on success, -1 if no device special file was passed in, -2 if a device
|
---|
331 | * special file was passed in but it has no partitions on it, or 1 on failure
|
---|
332 | */
|
---|
333 | static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list) {
|
---|
334 | int i = 0;
|
---|
335 | int c = 0;
|
---|
336 | int lastpos = 0;
|
---|
337 | char VG[MAX_STR_LEN];
|
---|
338 | char *tmp = NULL;
|
---|
339 | char *command = NULL;
|
---|
340 | char *partition_list = NULL;
|
---|
341 | char partitions[64][MAX_STR_LEN];
|
---|
342 | char *mount_list = NULL;
|
---|
343 | char *token = NULL;
|
---|
344 | char token_chars[] =" \t\r\f\a\0";
|
---|
345 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
---|
346 |
|
---|
347 | memset((char *)partitions, 0, sizeof(partitions));
|
---|
348 |
|
---|
349 | log_msg(5, "dsf: %s", dsf);
|
---|
350 |
|
---|
351 | /********
|
---|
352 | * See if a device special file was passed in (i.e. it must start with /dev/
|
---|
353 | ********/
|
---|
354 | if (strncmp(dsf, "/dev/", 5)) {
|
---|
355 | log_msg (5, "%s does not start with /dev/ and (probably) is not a device special file", dsf);
|
---|
356 | return (-1);
|
---|
357 | }
|
---|
358 | log_msg(5, " %s looks like a device special file", dsf);
|
---|
359 | /* Verify that the dsf exists */
|
---|
360 | mr_asprintf(command, "ls -al %s 2>/dev/null | wc -l", dsf);
|
---|
361 | log_msg(5, " Executing: %s", command);
|
---|
362 | mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
|
---|
363 | mr_free(command);
|
---|
364 |
|
---|
365 | log_msg(5, " Return value: %s", tmp);
|
---|
366 | c = atoi(tmp);
|
---|
367 | mr_free(tmp);
|
---|
368 |
|
---|
369 | if (!c) {
|
---|
370 | log_to_screen("Cannot find device special file %s", dsf);
|
---|
371 | return (1);
|
---|
372 | }
|
---|
373 | log_msg(5, " %s device special file exists", dsf);
|
---|
374 |
|
---|
375 | /* Get a list of the mounted file systems */
|
---|
376 | if (create_list_of_non_NFS_mounted_file_systems()) {
|
---|
377 | log_to_screen ("Could not get the list of mounted file systems");
|
---|
378 | return (1);
|
---|
379 | }
|
---|
380 | log_msg (5, "Processing dsf: %s", dsf);
|
---|
381 | /********
|
---|
382 | * Get a list of the dsf's partitions. There could be no partitions on the disk
|
---|
383 | * or a dsf of a partition was passed in (e.g. /dev/sda1 instead of /dev/sda).
|
---|
384 | * Either way, it's an error.
|
---|
385 | ********/
|
---|
386 | mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
|
---|
387 | log_msg(4, "Executing: %s", command);
|
---|
388 | mr_asprintf(partition_list, "%s", call_program_and_get_last_line_of_output(command));
|
---|
389 | mr_free(command);
|
---|
390 | log_msg(4, "Partition list for %s: %s", dsf, partition_list);
|
---|
391 | if (!strlen(partition_list)) {
|
---|
392 | /* There were no partitions on the disk */
|
---|
393 | log_msg(4, "Cannot find any partitions on device special file %s", dsf);
|
---|
394 | return (-2);
|
---|
395 | }
|
---|
396 |
|
---|
397 | /* Fill the partition list */
|
---|
398 | i = 0;
|
---|
399 | lastpos = 0;
|
---|
400 | while ((token = mr_strtok(partition_list, token_chars, &lastpos)) != NULL) {
|
---|
401 | log_msg (5, "Found partition: %s", token);
|
---|
402 | strcpy(partitions[i++], token);
|
---|
403 | mr_free(token);
|
---|
404 | }
|
---|
405 | mr_free(partition_list);
|
---|
406 |
|
---|
407 | /********
|
---|
408 | * At this point, we have a list of all of the partitions on the dsf. Now try to
|
---|
409 | * see which partitions have a file system on them.
|
---|
410 | *
|
---|
411 | * Loop through each partition on the disk and:
|
---|
412 | *
|
---|
413 | * - If the partition is swap, it ignores it.
|
---|
414 | *
|
---|
415 | * - If the partition is mounted (e.g. /dev/sda1 is mounted on /boot), it adds an entry
|
---|
416 | * to the linked list, copies to it the device name and mount point, and sets check == 1.
|
---|
417 | *
|
---|
418 | * - If the partition is part of a Volume Group that has Logical Volumes mounted, it adds
|
---|
419 | * an entry to the linked list for each mounted Logical Volume in that Volume Group, copying
|
---|
420 | * to it the device name and mount point, and sets check == 1. Note that if the Volume Group
|
---|
421 | * contains more than one disk, it will still add the entry even if the Logical Volume's
|
---|
422 | * extents are not on the dsf that was passed in to the function. For example, Volume Group
|
---|
423 | * VolGroup00 contains the disks /dev/sda1 and /dev/sdb1, and the Logical Volumes LogVol01,
|
---|
424 | * which is mounted on /var and has all of its extents on /dev/sda1, and LogVol02, which is
|
---|
425 | * mounted as /usr and has all of its extents on /dev/sdb1. If you pass /dev/sda into the
|
---|
426 | * function, both /var and /usr will be archived even though /usr is actually on/dev/sdb.
|
---|
427 | *
|
---|
428 | * - If the partition is part of a Volume Group that has Logical Volumes used in a mounted
|
---|
429 | * software raid device, it adds an entry to the linked list, copies to it the software raid
|
---|
430 | * device name and mount point, and sets check == 1.
|
---|
431 | *
|
---|
432 | * - If the partition is part of a mounted software raid device, it adds an entry to the linked
|
---|
433 | * list, copies to it the software raid device name and mount point, and sets check == 1.
|
---|
434 | *
|
---|
435 | ********/
|
---|
436 | for (i=0; strlen(partitions[i]); i++) {
|
---|
437 | log_msg(4, "Processing partition: %s", partitions[i]);
|
---|
438 | /* See if it's swap. If it is, ignore it. */
|
---|
439 | mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'",
|
---|
440 | dsf, partitions[i]);
|
---|
441 | log_msg(4, " Running: %s", command);
|
---|
442 | mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
|
---|
443 | mr_free(command);
|
---|
444 |
|
---|
445 | log_msg(4, " Return value: %s", tmp);
|
---|
446 | c = strlen(tmp);
|
---|
447 | mr_free(tmp);
|
---|
448 |
|
---|
449 | if (c) {
|
---|
450 | log_msg(4, "It's swap. Ignoring partition %s", partitions[i]);
|
---|
451 | continue;
|
---|
452 | }
|
---|
453 | /* It's not swap. See if we can find the mount point from the mount command. */
|
---|
454 | mr_asprintf(command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
|
---|
455 | mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
|
---|
456 | mr_free(command);
|
---|
457 |
|
---|
458 | if (strlen(tmp)) {
|
---|
459 | log_msg(4, " %s is mounted: %s", partitions[i], tmp);
|
---|
460 | if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) {
|
---|
461 | log_msg (4, "Can't find mount point %s in mounted file systems list", tmp);
|
---|
462 | mr_free(tmp);
|
---|
463 | return (1);
|
---|
464 | }
|
---|
465 | DSFptr->check = 1;
|
---|
466 | mr_free(tmp);
|
---|
467 | continue;
|
---|
468 | }
|
---|
469 | mr_free(tmp);
|
---|
470 | /* It's not swap and it's not mounted. See if it's LVM */
|
---|
471 | log_msg(4, " It's not mounted. Checking to see if it's LVM...");
|
---|
472 | /* Get the partition ID; 8e for LVM */
|
---|
473 | mr_asprintf(command, "parted2fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]);
|
---|
474 | log_msg(4, " Running: %s", command);
|
---|
475 | mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
|
---|
476 | mr_free(command);
|
---|
477 | if (strlen(tmp)) {
|
---|
478 | log_msg(4, " Partition ID: %s", tmp);
|
---|
479 | if (!strcasecmp(tmp, "8e")) {
|
---|
480 | /* It's LVM: Find the VG it's in */
|
---|
481 | log_msg(4, " It's LVM: Find the VG it's in...");
|
---|
482 | mr_asprintf(command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
|
---|
483 | log_msg(4, " Running: %s", command);
|
---|
484 | strcpy(VG, call_program_and_get_last_line_of_output(command));
|
---|
485 | mr_free(command);
|
---|
486 | log_msg(4, " Volume Group: %s", VG);
|
---|
487 | if (strlen(VG)) {
|
---|
488 | /* Found the Volume Group. Now find all of the VG's mount points */
|
---|
489 | log_msg(4, " Found the Volume Group. Now find all of the VG's mount points");
|
---|
490 | mr_asprintf(command, "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", VG, VG);
|
---|
491 | log_msg(4, " Running: %s", command);
|
---|
492 | mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
|
---|
493 | mr_free(command);
|
---|
494 | log_msg(4, " VG %s mount_list: %s", VG, mount_list);
|
---|
495 | lastpos = 0;
|
---|
496 | while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
|
---|
497 | log_msg (5, "mount point token: %s", token);
|
---|
498 | if ((DSFptr = find_mount_point_in_list(token)) == NULL) {
|
---|
499 | log_msg (4, "Can't find mount point %s in mounted file systems list", token);
|
---|
500 | mr_free(tmp);
|
---|
501 | mr_free(token);
|
---|
502 | return (1);
|
---|
503 | }
|
---|
504 | DSFptr->check = 1;
|
---|
505 | mr_free(token);
|
---|
506 | }
|
---|
507 | /********
|
---|
508 | * Now we want to see if there are any software raid devices using
|
---|
509 | * any of the Logical Volumes on the Volume Group.
|
---|
510 | *******/
|
---|
511 | mr_free(mount_list);
|
---|
512 | mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
|
---|
513 | log_msg (5, "Running: %s", command);
|
---|
514 | mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
|
---|
515 | mr_free(command);
|
---|
516 | log_msg(4, " Software raid device list: %s", mount_list);
|
---|
517 | lastpos = 0;
|
---|
518 | while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
|
---|
519 | mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
|
---|
520 | log_msg (5, "Running: %s", command);
|
---|
521 | mr_free(tmp);
|
---|
522 | mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
|
---|
523 | mr_free(command);
|
---|
524 | log_msg(4, "Number of Software raid device: %s", tmp);
|
---|
525 | if (atoi(tmp)) {
|
---|
526 | /* This device is on our disk */
|
---|
527 | if ((DSFptr = find_device_in_list(token)) == NULL) {
|
---|
528 | log_msg (4, "Can't find device %s in mounted file systems list", token);
|
---|
529 | mr_free(tmp);
|
---|
530 | mr_free(token);
|
---|
531 | return (1);
|
---|
532 | }
|
---|
533 | DSFptr->check = 1;
|
---|
534 | }
|
---|
535 | mr_free(token);
|
---|
536 | }
|
---|
537 | mr_free(mount_list);
|
---|
538 | } else {
|
---|
539 | log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
|
---|
540 | mr_free(tmp);
|
---|
541 | return (1);
|
---|
542 | }
|
---|
543 | mr_free(tmp);
|
---|
544 | continue;
|
---|
545 | }
|
---|
546 | } else {
|
---|
547 | log_msg (4, "Error finding partition type for the partition %s", partitions[i]);
|
---|
548 | }
|
---|
549 | mr_free(tmp);
|
---|
550 | /********
|
---|
551 | * It's not swap, mounted, or LVM. See if it's used in a software raid device.
|
---|
552 | ********/
|
---|
553 | log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device.");
|
---|
554 | mr_asprintf(command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
|
---|
555 | log_msg(4, " Running: %s", command);
|
---|
556 | mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
|
---|
557 | mr_free(command);
|
---|
558 | if (!strlen(tmp)) {
|
---|
559 | log_msg(4, " Partition %s is not used in a non-LVM software raid device", partitions[i]);
|
---|
560 | mr_free(tmp);
|
---|
561 | continue;
|
---|
562 | }
|
---|
563 | log_msg (5, " UUID: %s", tmp);
|
---|
564 | /* Get the Software raid device list */
|
---|
565 | mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
|
---|
566 | log_msg (5, " Running: %s", command);
|
---|
567 | mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
|
---|
568 | mr_free(command);
|
---|
569 | log_msg(4, " Software raid device list: %s", mount_list);
|
---|
570 | /* Loop through the software raid device list to see if we can find the partition */
|
---|
571 | lastpos = 0;
|
---|
572 | while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
|
---|
573 | mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
|
---|
574 | log_msg(4, " Running: %s", command);
|
---|
575 | mr_free(tmp);
|
---|
576 | mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
|
---|
577 | mr_free(command);
|
---|
578 | if (!atoi(tmp)) {
|
---|
579 | log_msg (4," Didn't find partition %s in software raid device %s", partitions[i], token);
|
---|
580 | } else {
|
---|
581 | if ((DSFptr = find_device_in_list(token)) == NULL) {
|
---|
582 | log_msg (4, "Can't find device %s in mounted file systems list", token);
|
---|
583 | mr_free(tmp);
|
---|
584 | mr_free(token);
|
---|
585 | return (1);
|
---|
586 | }
|
---|
587 | DSFptr->check = 1;
|
---|
588 | break;
|
---|
589 | }
|
---|
590 | mr_free(token);
|
---|
591 | }
|
---|
592 | mr_free(tmp);
|
---|
593 | }
|
---|
594 | mr_free(partition_list);
|
---|
595 | mr_free(mount_list);
|
---|
596 |
|
---|
597 | /* Determine how much memory to allocate for included_dsf_list and excluded_dsf_list */
|
---|
598 | i = 0;
|
---|
599 | DSFptr= DSF_Head;
|
---|
600 | while (DSFptr != NULL) {
|
---|
601 | i += strlen(DSFptr->mount_point) + 1;
|
---|
602 | DSFptr = DSFptr->next;
|
---|
603 | }
|
---|
604 | log_msg (5, "i: %d", i);
|
---|
605 | if ((*included_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {
|
---|
606 | fatal_error ("Cannot allocate memory");
|
---|
607 | }
|
---|
608 | if ((*excluded_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {
|
---|
609 | fatal_error ("Cannot allocate memory");
|
---|
610 | }
|
---|
611 | DSFptr= DSF_Head;
|
---|
612 | while (DSFptr != NULL) {
|
---|
613 | if (DSFptr->check) {
|
---|
614 | log_msg (5, "%s is mounted on %s and is on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf);
|
---|
615 | strcat(*included_dsf_list, DSFptr->mount_point);
|
---|
616 | strcat(*included_dsf_list, " ");
|
---|
617 | } else {
|
---|
618 | log_msg (4, "%s is mounted on %s and is NOT on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf);
|
---|
619 | strcat(*excluded_dsf_list, DSFptr->mount_point);
|
---|
620 | strcat(*excluded_dsf_list, " ");
|
---|
621 | }
|
---|
622 | DSFptr = DSFptr->next;
|
---|
623 | }
|
---|
624 | log_msg (5, "included_dsf_list: %s", *included_dsf_list);
|
---|
625 | log_msg (5, "excluded_dsf_list: %s", *excluded_dsf_list);
|
---|
626 | return (0);
|
---|
627 | }
|
---|
628 |
|
---|
629 |
|
---|
630 | /**
|
---|
631 | * Process mondoarchive's command-line switches.
|
---|
632 | * @param bkpinfo The backup information structure to populate.
|
---|
633 | * @param flag_val An array of the argument passed to each switch (the letter is the index).
|
---|
634 | * If a switch is not set or has no argument, the field in @p flag_val doesn't matter.
|
---|
635 | * @param flag_set An array of <tt>bool</tt>s indexed by switch letter: TRUE if it's set,
|
---|
636 | * FALSE if it's not.
|
---|
637 | * @return The number of problems with the switches, or 0 for success.
|
---|
638 | * @bug Maybe include a list of all switches (inc. intentionally undocumented ones not in the manual!) here?
|
---|
639 | */
|
---|
640 | int
|
---|
641 | process_switches(char flag_val[128][MAX_STR_LEN], bool flag_set[128])
|
---|
642 | {
|
---|
643 |
|
---|
644 | /*@ ints *** */
|
---|
645 | int i = 0;
|
---|
646 | int retval = 0;
|
---|
647 | int percent = 0;
|
---|
648 | int lastpos = 0;
|
---|
649 |
|
---|
650 | /*@ buffers ** */
|
---|
651 | char *tmp = NULL;
|
---|
652 | char *tmp1 = NULL;
|
---|
653 | char *tmp2 = NULL;
|
---|
654 | char *psz = NULL;
|
---|
655 | char *p = NULL;
|
---|
656 | char *q = NULL;
|
---|
657 | char *token = NULL;
|
---|
658 | char *mounted_on_dsf = NULL;
|
---|
659 | char *not_mounted_on_dsf = NULL;
|
---|
660 | char token_chars[] =" \t\r\f\a\0";
|
---|
661 |
|
---|
662 | long itbs = 0L;
|
---|
663 |
|
---|
664 | struct stat buf;
|
---|
665 |
|
---|
666 | malloc_string(tmp);
|
---|
667 |
|
---|
668 | assert(bkpinfo != NULL);
|
---|
669 | assert(flag_val != NULL);
|
---|
670 | assert(flag_set != NULL);
|
---|
671 |
|
---|
672 | bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
|
---|
673 |
|
---|
674 | /* compulsory */
|
---|
675 | i = flag_set['c'] + flag_set['i'] + flag_set['n'] +
|
---|
676 | flag_set['t'] + flag_set['u'] + flag_set['r'] +
|
---|
677 | flag_set['w'] + flag_set['C'] + flag_set['U'];
|
---|
678 | if ((i == 0) && (! bkpinfo->restore_data)) {
|
---|
679 | retval++;
|
---|
680 | log_to_screen("You must specify the media type\n");
|
---|
681 | }
|
---|
682 | if (i > 1) {
|
---|
683 | retval++;
|
---|
684 | log_to_screen("Please specify only one media type\n");
|
---|
685 | }
|
---|
686 |
|
---|
687 | if (flag_set['K']) {
|
---|
688 | g_loglevel = atoi(flag_val['K']);
|
---|
689 | log_msg(1,"Loglevel forced to %d",g_loglevel);
|
---|
690 | if (g_loglevel < 3) {
|
---|
691 | g_loglevel = 3;
|
---|
692 | }
|
---|
693 | }
|
---|
694 |
|
---|
695 | if ((flag_set['L'] && flag_set['0']) && (! bkpinfo->restore_data)) {
|
---|
696 | retval++;
|
---|
697 | log_to_screen("You cannot have 'no compression' _and_ LZOP.\n");
|
---|
698 | }
|
---|
699 | if (! bkpinfo->restore_data) {
|
---|
700 | bkpinfo->backup_data = flag_set['O'];
|
---|
701 | }
|
---|
702 | bkpinfo->verify_data = flag_set['V'];
|
---|
703 |
|
---|
704 | if (flag_set['I'] && !bkpinfo->backup_data) {
|
---|
705 | log_to_screen("-I switch is ignored if just verifying");
|
---|
706 | }
|
---|
707 | if (flag_set['E'] && !bkpinfo->backup_data) {
|
---|
708 | log_to_screen("-E switch is ignored if just verifying");
|
---|
709 | }
|
---|
710 |
|
---|
711 | tmp1 = find_home_of_exe("afio");
|
---|
712 | if (!tmp1) {
|
---|
713 | mr_free(tmp1);
|
---|
714 | tmp1 = find_home_of_exe("star");
|
---|
715 | if (tmp1) {
|
---|
716 | mr_free(tmp1);
|
---|
717 | flag_set['R'] = TRUE;
|
---|
718 | log_msg(1, "Using star instead of afio");
|
---|
719 | } else {
|
---|
720 | mr_free(tmp1);
|
---|
721 | fatal_error("Neither afio nor star is installed. Please install at least one.");
|
---|
722 | }
|
---|
723 | }
|
---|
724 | mr_free(tmp1);
|
---|
725 |
|
---|
726 | if (flag_set['R']) {
|
---|
727 | bkpinfo->use_star = TRUE;
|
---|
728 | if (flag_set['L']) {
|
---|
729 | fatal_error("You may not use star and lzop at the same time.");
|
---|
730 | }
|
---|
731 | tmp1 = find_home_of_exe("star");
|
---|
732 | if (!tmp1) {
|
---|
733 | mr_free(tmp1);
|
---|
734 | fatal_error("Please install 'star' RPM or tarball if you are going to use -R. Thanks.");
|
---|
735 | }
|
---|
736 | mr_free(tmp1);
|
---|
737 | }
|
---|
738 |
|
---|
739 | if ((flag_set['W']) && (! bkpinfo->restore_data)) {
|
---|
740 | bkpinfo->nonbootable_backup = TRUE;
|
---|
741 | log_to_screen("Warning - you have opted for non-bootable backup");
|
---|
742 | if (flag_set['f'] || flag_set['l']) {
|
---|
743 | log_to_screen
|
---|
744 | ("You don't need to specify bootloader or bootdevice");
|
---|
745 | }
|
---|
746 | }
|
---|
747 |
|
---|
748 | if (flag_set['I']) {
|
---|
749 | if (bkpinfo->include_paths && bkpinfo->include_paths[0] == '-') {
|
---|
750 | retval++;
|
---|
751 | log_to_screen("Please supply a sensible value with '-I'\n");
|
---|
752 | }
|
---|
753 |
|
---|
754 | mr_asprintf(tmp1, "%s", flag_val['I']);
|
---|
755 | p = tmp1;
|
---|
756 | q = tmp1;
|
---|
757 |
|
---|
758 | /* Cut the flag_val['I'] in parts containing all paths to test them */
|
---|
759 | while (p != NULL) {
|
---|
760 | q = strchr(p, ' ');
|
---|
761 | if (q != NULL) {
|
---|
762 | *q = '\0';
|
---|
763 | if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
|
---|
764 | log_msg(1, "ERROR ! %s doesn't exist", p);
|
---|
765 | fatal_error("ERROR ! You specified a directory to include which doesn't exist");
|
---|
766 | }
|
---|
767 | p = q+1 ;
|
---|
768 | } else {
|
---|
769 | if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
|
---|
770 | log_msg(1, "ERROR ! %s doesn't exist", p);
|
---|
771 | fatal_error("ERROR ! You specified a directory to include which doesn't exist");
|
---|
772 | }
|
---|
773 | p = NULL;
|
---|
774 | }
|
---|
775 | }
|
---|
776 | mr_free(tmp1);
|
---|
777 | while ((token = mr_strtok(flag_val['I'], token_chars, &lastpos)) != NULL) {
|
---|
778 | switch (get_dsf_mount_list(token, &mounted_on_dsf, ¬_mounted_on_dsf)) {
|
---|
779 | /* It's a dsf but not a whole disk dsf */
|
---|
780 | case -2:
|
---|
781 | log_to_screen("Could %s be a partition instead of a whole disk device special file?\n Ignored.", token);
|
---|
782 | break;
|
---|
783 | /* Fatal error; exit */
|
---|
784 | case 1:
|
---|
785 | mr_free(token);
|
---|
786 | fatal_error("Error processing -I option");
|
---|
787 | /* Everything is OK; process to archive data */
|
---|
788 | case 0:
|
---|
789 | log_to_screen("Archiving only the following file systems on %s:\n", token);
|
---|
790 | log_to_screen(" %s\n", mounted_on_dsf);
|
---|
791 | mr_asprintf(p, "/");
|
---|
792 | mr_free(bkpinfo->include_paths);
|
---|
793 | bkpinfo->include_paths = p;
|
---|
794 | if (strlen(not_mounted_on_dsf)) {
|
---|
795 | log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf);
|
---|
796 | log_to_screen("Not archiving the following file systems:\n");
|
---|
797 | log_to_screen(" %s\n", not_mounted_on_dsf);
|
---|
798 | mr_strcat(bkpinfo->exclude_paths, " %s ", not_mounted_on_dsf);
|
---|
799 | }
|
---|
800 | break;
|
---|
801 | /* A device special file was not passed in. Process it as a path. */
|
---|
802 | case -1:
|
---|
803 | mr_strcat(bkpinfo->include_paths, " %s ", token);
|
---|
804 | break;
|
---|
805 | }
|
---|
806 | mr_free(token);
|
---|
807 | }
|
---|
808 | if (bkpinfo->include_paths != NULL) {
|
---|
809 | log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
|
---|
810 | }
|
---|
811 | if (bkpinfo->exclude_paths != NULL) {
|
---|
812 | log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths);
|
---|
813 | }
|
---|
814 | log_msg(4, "Finished with the -I option");
|
---|
815 | }
|
---|
816 |
|
---|
817 | if (g_kernel_version >= 2.6 && !flag_set['d']
|
---|
818 | && (flag_set['c'] || flag_set['w']) && (! bkpinfo->restore_data)) {
|
---|
819 | fatal_error
|
---|
820 | ("If you are using the 2.6.x kernel, please specify the CD-R(W) device.");
|
---|
821 | }
|
---|
822 |
|
---|
823 |
|
---|
824 | if (flag_set['J']) {
|
---|
825 | if (flag_set['I']) {
|
---|
826 | retval++;
|
---|
827 | log_to_screen
|
---|
828 | ("Please do not use -J in combination with -I. If you want to make a list of files to backup, that's fine, use -J <filename> but please don't muddy the waters by combining -J with -I. Thanks. :-)");
|
---|
829 | }
|
---|
830 | bkpinfo->make_filelist = FALSE;
|
---|
831 | mr_asprintf(bkpinfo->include_paths, "%s", flag_val['J']);
|
---|
832 | }
|
---|
833 |
|
---|
834 | if ((flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) && (! bkpinfo->restore_data)) {
|
---|
835 | if (!flag_set['r'] && g_kernel_version <= 2.5
|
---|
836 | && strstr(flag_val['d'], "/dev/")) {
|
---|
837 | fatal_error
|
---|
838 | ("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag.");
|
---|
839 | }
|
---|
840 | if (flag_set['r'] && g_kernel_version <= 2.5
|
---|
841 | && !strstr(flag_val['d'], "/dev/")) {
|
---|
842 | fatal_error
|
---|
843 | ("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag.");
|
---|
844 | }
|
---|
845 | if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) {
|
---|
846 | log_to_screen
|
---|
847 | ("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk...");
|
---|
848 | }
|
---|
849 |
|
---|
850 | if (system("which cdrecord > /dev/null 2> /dev/null")
|
---|
851 | && system("which dvdrecord > /dev/null 2> /dev/null")) {
|
---|
852 | fatal_error
|
---|
853 | ("Please install dvdrecord/cdrecord and try again.");
|
---|
854 | }
|
---|
855 | if (flag_set['C']) {
|
---|
856 | bkpinfo->cdrw_speed = atoi(flag_val['C']);
|
---|
857 | if (bkpinfo->cdrw_speed < 1) {
|
---|
858 | fatal_error
|
---|
859 | ("You specified a silly speed for a CD-R[W] drive");
|
---|
860 | }
|
---|
861 | if (!flag_set['L']) {
|
---|
862 | log_to_screen
|
---|
863 | ("You must use -L with -C. Therefore I am setting it for you.");
|
---|
864 | flag_set['L'] = 1;
|
---|
865 | flag_val['L'][0] = '\0';
|
---|
866 | }
|
---|
867 | } else {
|
---|
868 | log_msg(3, "flag_val['c'] = %s", flag_val['c']);
|
---|
869 | log_msg(3, "flag_val['w'] = %s", flag_val['w']);
|
---|
870 | // log_msg(3, "flag_set['r'] = %i", flag_set['r'] );
|
---|
871 | if (flag_set['c']) {
|
---|
872 | bkpinfo->cdrw_speed = atoi(flag_val['c']);
|
---|
873 | } else if (flag_set['w']) {
|
---|
874 | bkpinfo->cdrw_speed = atoi(flag_val['w']);
|
---|
875 | } else if (flag_set['r']) {
|
---|
876 | bkpinfo->cdrw_speed = 1; /*atoi(flag_val['r']); */
|
---|
877 | }
|
---|
878 |
|
---|
879 | if (bkpinfo->cdrw_speed < 1) {
|
---|
880 | fatal_error
|
---|
881 | ("You specified a silly speed for a CD-R[W] drive");
|
---|
882 | }
|
---|
883 | }
|
---|
884 | }
|
---|
885 |
|
---|
886 | if ((flag_set['t'] && !flag_set['d']) && (! bkpinfo->restore_data)) {
|
---|
887 | log_it("Hmm! No tape drive specified. Let's see what we can do.");
|
---|
888 | if ((tmp1 = find_tape_device_and_size(NULL)) == NULL) {
|
---|
889 | fatal_error("Tape device not specified. I couldn't find it either.");
|
---|
890 | }
|
---|
891 | strcpy(flag_val['d'], tmp1);
|
---|
892 | mr_free(tmp1);
|
---|
893 | flag_set['d'] = TRUE;
|
---|
894 | strcpy(flag_val['d'], p);
|
---|
895 | mr_free(p);
|
---|
896 | log_to_screen("You didn't specify a tape streamer device. I'm assuming %s", flag_val['d']);
|
---|
897 | percent = 0;
|
---|
898 | }
|
---|
899 |
|
---|
900 | if (flag_set['U']) // USB
|
---|
901 | {
|
---|
902 | if (! flag_set['d']) {
|
---|
903 | fatal_error
|
---|
904 | ("You need to specify a device file with -d for bootable USB device usage");
|
---|
905 | }
|
---|
906 | if ((!flag_set['s']) && (! bkpinfo->restore_data)) {
|
---|
907 | fatal_error("You did not specify a size (-s) for your USB device. Aborting");
|
---|
908 | }
|
---|
909 | }
|
---|
910 |
|
---|
911 | if (flag_set['r']) // DVD
|
---|
912 | {
|
---|
913 | if (flag_set['m']) {
|
---|
914 | fatal_error
|
---|
915 | ("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m.");
|
---|
916 | }
|
---|
917 | if (!flag_set['d']) {
|
---|
918 | if ((tmp1 = find_dvd_device(flag_val['d'])) != NULL) {
|
---|
919 | strcpy(flag_val['d'],tmp1);
|
---|
920 | mr_free(tmp1);
|
---|
921 | flag_set['d'] = TRUE;
|
---|
922 | log_to_screen("I guess DVD drive is at %s", flag_val['d']);
|
---|
923 | }
|
---|
924 | }
|
---|
925 | if (strchr(flag_val['d'], ',')) {
|
---|
926 | fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
|
---|
927 | }
|
---|
928 | if (! bkpinfo->restore_data) {
|
---|
929 | tmp1 = find_home_of_exe("growisofs");
|
---|
930 | if (!tmp1) {
|
---|
931 | mr_free(tmp1);
|
---|
932 | fatal_error("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it.");
|
---|
933 | }
|
---|
934 | mr_free(tmp1);
|
---|
935 |
|
---|
936 | tmp1 = find_home_of_exe("dvd+rw-format");
|
---|
937 | if (!tmp1) {
|
---|
938 | mr_free(tmp1);
|
---|
939 | fatal_error("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it.");
|
---|
940 | }
|
---|
941 | mr_free(tmp1);
|
---|
942 |
|
---|
943 | if (!flag_set['s']) {
|
---|
944 | sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB
|
---|
945 | strcat(flag_val['s'], "m");
|
---|
946 | log_to_screen("You did not specify a size (-s) for DVD. I'm guessing %s.", flag_val['s']);
|
---|
947 | flag_set['s'] = 1;
|
---|
948 | }
|
---|
949 | }
|
---|
950 | }
|
---|
951 |
|
---|
952 | if (flag_set['t'] || flag_set['u']) { /* tape size */
|
---|
953 | if (strchr(flag_val['d'], ',')) {
|
---|
954 | fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
|
---|
955 | }
|
---|
956 | if ((flag_set['O']) && (! bkpinfo->restore_data)) {
|
---|
957 | if (flag_set['s']) {
|
---|
958 | if (flag_set['t']) {
|
---|
959 | fatal_error
|
---|
960 | ("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway.");
|
---|
961 | }
|
---|
962 | if (process_the_s_switch(flag_val['s'])) {
|
---|
963 | fatal_error("Bad -s switch");
|
---|
964 | }
|
---|
965 | } else if (flag_set['u'] || flag_set['t']) {
|
---|
966 | for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
|
---|
967 | bkpinfo->media_size[i] = 0;
|
---|
968 | }
|
---|
969 | } else {
|
---|
970 | retval++;
|
---|
971 | log_to_screen("Tape size not specified.\n");
|
---|
972 | }
|
---|
973 | }
|
---|
974 | } else if (! bkpinfo->restore_data) { /* CD|USB size */
|
---|
975 | if (flag_set['s']) {
|
---|
976 | if (process_the_s_switch(flag_val['s'])) {
|
---|
977 | fatal_error("Bad -s switch");
|
---|
978 | }
|
---|
979 | }
|
---|
980 | if (flag_set['w']) {
|
---|
981 | bkpinfo->wipe_media_first = TRUE;
|
---|
982 | } /* CD-RW */
|
---|
983 | }
|
---|
984 |
|
---|
985 | if (flag_set['n']) {
|
---|
986 | mr_free(bkpinfo->nfs_mount);
|
---|
987 | mr_asprintf(bkpinfo->nfs_mount, "%s", flag_val['n']);
|
---|
988 | if (!flag_set['d']) {
|
---|
989 | mr_free(bkpinfo->nfs_remote_dir);
|
---|
990 | mr_asprintf(bkpinfo->nfs_remote_dir, "/");
|
---|
991 | }
|
---|
992 | /* test if we specified a user for the NFS dialog */
|
---|
993 | p = strchr(bkpinfo->nfs_mount, '@');
|
---|
994 | if (p != NULL) {
|
---|
995 | /* User found. Store the 2 values */
|
---|
996 | bkpinfo->nfs_user = bkpinfo->nfs_mount;
|
---|
997 | p++;
|
---|
998 | /* new NFS mount */
|
---|
999 | bkpinfo->nfs_mount = p;
|
---|
1000 | p--;
|
---|
1001 | *p = '\0';
|
---|
1002 | }
|
---|
1003 | mr_asprintf(tmp1, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->nfs_mount);
|
---|
1004 | mr_free(bkpinfo->isodir);
|
---|
1005 | mr_asprintf(bkpinfo->isodir, "%s", call_program_and_get_last_line_of_output(tmp1));
|
---|
1006 | mr_free(tmp1);
|
---|
1007 |
|
---|
1008 | if (strlen(bkpinfo->isodir) < 3) {
|
---|
1009 | log_to_screen("NFS share is not mounted. Trying to mount it for you.\n");
|
---|
1010 | mr_asprintf(tmp1, "mount %s", bkpinfo->nfs_mount);
|
---|
1011 | i = system(tmp1);
|
---|
1012 | mr_free(tmp1);
|
---|
1013 | if (i) {
|
---|
1014 | log_to_screen("Unable to mount NFS share %s. Please mount manually.\n", bkpinfo->nfs_mount);
|
---|
1015 | retval++;
|
---|
1016 | } else {
|
---|
1017 | mr_asprintf(tmp1, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->nfs_mount);
|
---|
1018 | mr_free(bkpinfo->isodir);
|
---|
1019 | mr_asprintf(bkpinfo->isodir, "%s", call_program_and_get_last_line_of_output(tmp1));
|
---|
1020 | mr_free(tmp1);
|
---|
1021 |
|
---|
1022 | if (strlen(bkpinfo->isodir) < 3) {
|
---|
1023 | retval++;
|
---|
1024 | log_to_screen("NFS share %s is strangely not mounted. Please mount manually...\n", bkpinfo->nfs_mount);
|
---|
1025 | }
|
---|
1026 | }
|
---|
1027 | }
|
---|
1028 | log_msg(3, "mount = %s", bkpinfo->nfs_mount);
|
---|
1029 | log_msg(3, "isodir= %s", bkpinfo->isodir);
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 | if (flag_set['c']) {
|
---|
1033 | bkpinfo->backup_media_type = cdr;
|
---|
1034 | }
|
---|
1035 | if (flag_set['C']) {
|
---|
1036 | bkpinfo->backup_media_type = cdstream;
|
---|
1037 | }
|
---|
1038 | if (flag_set['i']) {
|
---|
1039 | bkpinfo->backup_media_type = iso;
|
---|
1040 | }
|
---|
1041 | if (flag_set['n']) {
|
---|
1042 | bkpinfo->backup_media_type = nfs;
|
---|
1043 | /* Never try to eject a NFS device */
|
---|
1044 | bkpinfo->please_dont_eject = TRUE;
|
---|
1045 | }
|
---|
1046 | if (flag_set['r']) {
|
---|
1047 | bkpinfo->backup_media_type = dvd;
|
---|
1048 | }
|
---|
1049 | if (flag_set['t']) {
|
---|
1050 | bkpinfo->backup_media_type = tape;
|
---|
1051 | }
|
---|
1052 | if (flag_set['u']) {
|
---|
1053 | bkpinfo->backup_media_type = udev;
|
---|
1054 | }
|
---|
1055 | if (flag_set['w']) {
|
---|
1056 | bkpinfo->backup_media_type = cdrw;
|
---|
1057 | }
|
---|
1058 | if (flag_set['U']) {
|
---|
1059 | bkpinfo->backup_media_type = usb;
|
---|
1060 | /* Never try to eject a USB device */
|
---|
1061 | bkpinfo->please_dont_eject = TRUE;
|
---|
1062 | }
|
---|
1063 | if (flag_set['z']) {
|
---|
1064 | tmp1 = find_home_of_exe("getfattr");
|
---|
1065 | if (tmp1) {
|
---|
1066 | mr_asprintf(g_getfattr,"getfattr");
|
---|
1067 | }
|
---|
1068 | mr_free(tmp1);
|
---|
1069 |
|
---|
1070 | tmp1 = find_home_of_exe("getfacl");
|
---|
1071 | if (tmp1) {
|
---|
1072 | mr_asprintf(g_getfacl,"getfacl");
|
---|
1073 | }
|
---|
1074 | mr_free(tmp1);
|
---|
1075 | }
|
---|
1076 |
|
---|
1077 | /* optional, popular */
|
---|
1078 | if (flag_set['g']) {
|
---|
1079 | g_text_mode = FALSE;
|
---|
1080 | }
|
---|
1081 |
|
---|
1082 | if (flag_set['E']) {
|
---|
1083 | if (bkpinfo->exclude_paths && bkpinfo->exclude_paths[0] == '-') {
|
---|
1084 | retval++;
|
---|
1085 | log_to_screen("Please supply a sensible value with '-E'\n");
|
---|
1086 | }
|
---|
1087 | mr_asprintf(tmp1, "%s", flag_val['E']);
|
---|
1088 |
|
---|
1089 | p = tmp1;
|
---|
1090 | q = tmp1;
|
---|
1091 |
|
---|
1092 | /* Cut the flag_val['E'] in parts containing all paths to test them */
|
---|
1093 | while (p != NULL) {
|
---|
1094 | q = strchr(p, ' ');
|
---|
1095 | if (q != NULL) {
|
---|
1096 | *q = '\0';
|
---|
1097 | /* Fix bug 14 where ending / cause a problem later
|
---|
1098 | * so handled here for the moment */
|
---|
1099 | q--;
|
---|
1100 | if (*q == '/') {
|
---|
1101 | *q = '\0';
|
---|
1102 | }
|
---|
1103 | q++;
|
---|
1104 | /* End of bug fix */
|
---|
1105 | if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
|
---|
1106 | log_msg(1, "WARNING ! %s doesn't exist", p);
|
---|
1107 | }
|
---|
1108 | p = q+1 ;
|
---|
1109 | } else {
|
---|
1110 | if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
|
---|
1111 | log_msg(1, "WARNING ! %s doesn't exist", p);
|
---|
1112 | }
|
---|
1113 | p = NULL;
|
---|
1114 | }
|
---|
1115 | }
|
---|
1116 | mr_free(tmp1);
|
---|
1117 | lastpos = 0;
|
---|
1118 | while ((token = mr_strtok(flag_val['E'], token_chars, &lastpos)) != NULL) {
|
---|
1119 | switch (get_dsf_mount_list(token, &mounted_on_dsf, ¬_mounted_on_dsf)) {
|
---|
1120 | case 1:
|
---|
1121 | log_msg(1, "WARNING ! a path doesn't exist in -E option");
|
---|
1122 | break;
|
---|
1123 | /* Everything is OK; proceed to archive data */
|
---|
1124 | case 0:
|
---|
1125 | if (strlen(mounted_on_dsf)) {
|
---|
1126 | log_to_screen("Excluding the following file systems on %s:\n", token);
|
---|
1127 | log_to_screen(" %s\n", mounted_on_dsf);
|
---|
1128 | log_msg (5, "Adding to bkpinfo->exclude_paths due to -E option: %s", mounted_on_dsf);
|
---|
1129 | mr_strcat(bkpinfo->exclude_paths, " %s ", mounted_on_dsf);
|
---|
1130 | }
|
---|
1131 | break;
|
---|
1132 | /* It's a dsf but not a whole disk dsf */
|
---|
1133 | case -2:
|
---|
1134 | log_to_screen("Could %s be a partition instead of a whole disk device special file?\nIgnored.", token);
|
---|
1135 | break;
|
---|
1136 | /* A device special file was not passed in. Process it as a path. */
|
---|
1137 | case -1:
|
---|
1138 | mr_strcat(bkpinfo->exclude_paths, " %s ", token);
|
---|
1139 | break;
|
---|
1140 | }
|
---|
1141 | mr_free(token);
|
---|
1142 | }
|
---|
1143 | if (bkpinfo->exclude_paths != NULL) {
|
---|
1144 | log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths);
|
---|
1145 | }
|
---|
1146 | log_msg(4, "Finished with the -E option");
|
---|
1147 | }
|
---|
1148 |
|
---|
1149 | if (flag_set['e']) {
|
---|
1150 | bkpinfo->please_dont_eject = TRUE;
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | if ((flag_set['N']) && (! bkpinfo->restore_data)) // exclude NFS mounts & devices
|
---|
1154 | {
|
---|
1155 | mr_asprintf(psz, "%s", list_of_NFS_mounts_only());
|
---|
1156 | mr_strcat(bkpinfo->exclude_paths, " %s ", psz);
|
---|
1157 | mr_free(psz);
|
---|
1158 |
|
---|
1159 | if (bkpinfo->exclude_paths != NULL) {
|
---|
1160 | log_msg(3, "-N means we're now excluding %s", bkpinfo->exclude_paths);
|
---|
1161 | }
|
---|
1162 | }
|
---|
1163 |
|
---|
1164 | if (flag_set['b']) {
|
---|
1165 | mr_asprintf(psz, "%s", flag_val['b']);
|
---|
1166 | log_msg(1, "psz = '%s'", psz);
|
---|
1167 | if (psz[strlen(psz) - 1] == 'k') {
|
---|
1168 | psz[strlen(psz) - 1] = '\0';
|
---|
1169 | itbs = atol(psz) * 1024L;
|
---|
1170 | } else {
|
---|
1171 | itbs = atol(psz);
|
---|
1172 | }
|
---|
1173 | mr_free(psz);
|
---|
1174 | log_msg(1, "'%s' --> %ld", flag_val['b'], itbs);
|
---|
1175 | log_msg(1, "Internal tape block size is now %ld bytes", itbs);
|
---|
1176 | if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) {
|
---|
1177 | fatal_error
|
---|
1178 | ("Are you nuts? Silly, your internal tape block size is. Abort, I shall.");
|
---|
1179 | }
|
---|
1180 | bkpinfo->internal_tape_block_size = itbs;
|
---|
1181 | }
|
---|
1182 |
|
---|
1183 | if ((flag_set['D']) && (! bkpinfo->restore_data)) {
|
---|
1184 | bkpinfo->differential = 1;
|
---|
1185 | // bkpinfo->differential = atoi (flag_val['D']);
|
---|
1186 | if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) {
|
---|
1187 | fatal_error
|
---|
1188 | ("The D option should be between 1 and 9 inclusive");
|
---|
1189 | }
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | if (flag_set['x']) {
|
---|
1193 | mr_asprintf(bkpinfo->image_devs, flag_val['x']);
|
---|
1194 | if ((run_program_and_log_output("which ntfsclone", 2)) && (! bkpinfo->restore_data)) {
|
---|
1195 | fatal_error("Please install ntfsprogs package/tarball.");
|
---|
1196 | }
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | if (flag_set['m']) {
|
---|
1200 | bkpinfo->manual_cd_tray = TRUE;
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | if ((flag_set['k']) && (! bkpinfo->restore_data)) {
|
---|
1204 | mr_asprintf(bkpinfo->kernel_path, "%s", flag_val['k']);
|
---|
1205 | if (!strcmp(bkpinfo->kernel_path, "failsafe")) {
|
---|
1206 | mr_free(bkpinfo->kernel_path);
|
---|
1207 | mr_asprintf(bkpinfo->kernel_path, "FAILSAFE");
|
---|
1208 | }
|
---|
1209 | if (strcmp(bkpinfo->kernel_path, "FAILSAFE") && !does_file_exist(bkpinfo->kernel_path)) {
|
---|
1210 | retval++;
|
---|
1211 | log_to_screen("You specified kernel '%s', which does not exist\n", bkpinfo->kernel_path);
|
---|
1212 | }
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | if (flag_set['p']) {
|
---|
1216 | mr_free(bkpinfo->prefix);
|
---|
1217 | mr_asprintf(bkpinfo->prefix, "%s", flag_val['p']);
|
---|
1218 | log_msg(1,"Prefix forced to %s",bkpinfo->prefix);
|
---|
1219 | }
|
---|
1220 |
|
---|
1221 | if (flag_set['d']) { /* backup directory (if ISO/NFS) */
|
---|
1222 | if (flag_set['i']) {
|
---|
1223 | mr_free(bkpinfo->isodir);
|
---|
1224 | mr_asprintf(bkpinfo->isodir, "%s", flag_val['d']);
|
---|
1225 | mr_asprintf(tmp1, "ls -l %s", bkpinfo->isodir);
|
---|
1226 | if (run_program_and_log_output(tmp1, 2)) {
|
---|
1227 | mr_free(tmp1);
|
---|
1228 | fatal_error("output folder does not exist - please create it");
|
---|
1229 | }
|
---|
1230 | mr_free(tmp1);
|
---|
1231 | } else if (flag_set['n']) {
|
---|
1232 | mr_free(bkpinfo->nfs_remote_dir);
|
---|
1233 | mr_asprintf(bkpinfo->nfs_remote_dir, "%s", flag_val['d']);
|
---|
1234 | } else { /* backup device (if tape/CD-R/CD-RW) */
|
---|
1235 | mr_free(bkpinfo->media_device);
|
---|
1236 | mr_asprintf(bkpinfo->media_device, "%s", flag_val['d']);
|
---|
1237 | }
|
---|
1238 | }
|
---|
1239 |
|
---|
1240 | if ((flag_set['n']) && (! bkpinfo->restore_data)) {
|
---|
1241 | mr_asprintf(tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->nfs_remote_dir);
|
---|
1242 | if (bkpinfo->nfs_user) {
|
---|
1243 | mr_asprintf(tmp2, "su - %s -c \"echo hi > %s\"", bkpinfo->nfs_user, tmp1);
|
---|
1244 | } else {
|
---|
1245 | mr_asprintf(tmp2, "echo hi > %s", tmp1);
|
---|
1246 | }
|
---|
1247 | i = run_program_and_log_output(tmp2, 2);
|
---|
1248 | mr_free(tmp2);
|
---|
1249 |
|
---|
1250 | if (i) {
|
---|
1251 | retval++;
|
---|
1252 | log_to_screen(tmp2, "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n", bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount);
|
---|
1253 | }
|
---|
1254 | unlink(tmp1);
|
---|
1255 | mr_free(tmp1);
|
---|
1256 | }
|
---|
1257 |
|
---|
1258 | if (!flag_set['d'] && (flag_set['c'] || flag_set['w'] || flag_set['C'])) {
|
---|
1259 | if (g_kernel_version >= 2.6) {
|
---|
1260 | tmp2 = popup_and_get_string("Device", "Please specify the device", bkpinfo->media_device);
|
---|
1261 | if (tmp2 == NULL) {
|
---|
1262 | fatal_error("User opted to cancel.");
|
---|
1263 | }
|
---|
1264 | bkpinfo->media_device = tmp2;
|
---|
1265 | } else {
|
---|
1266 | bkpinfo->media_device = find_cdrw_device();
|
---|
1267 | if (bkpinfo->media_device == NULL) {
|
---|
1268 | retval++;
|
---|
1269 | log_to_screen("Tried and failed to find CD-R[W] drive automatically.\n");
|
---|
1270 | } else {
|
---|
1271 | flag_set['d'] = TRUE;
|
---|
1272 | strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);
|
---|
1273 | }
|
---|
1274 | }
|
---|
1275 | }
|
---|
1276 |
|
---|
1277 | if ((!flag_set['d'] && !flag_set['n'] && !flag_set['C']) && (! bkpinfo->restore_data)) {
|
---|
1278 | retval++;
|
---|
1279 | log_to_screen("Please specify the backup device/directory.\n");
|
---|
1280 | fatal_error
|
---|
1281 | ("You didn't use -d to specify the backup device/directory.");
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | for (i = '0'; i <= '9'; i++) {
|
---|
1285 | if (flag_set[i]) {
|
---|
1286 | bkpinfo->compression_level = i - '0';
|
---|
1287 | } /* not '\0' but '0' */
|
---|
1288 | }
|
---|
1289 |
|
---|
1290 | if (flag_set['S']) {
|
---|
1291 | mr_asprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'], random() % 32768);
|
---|
1292 | }
|
---|
1293 |
|
---|
1294 | if (flag_set['T']) {
|
---|
1295 | setup_tmpdir(flag_val['T']);
|
---|
1296 | mr_asprintf(tmp1, "touch %s/.foo.dat", bkpinfo->tmpdir);
|
---|
1297 | i = run_program_and_log_output(tmp1, 1);
|
---|
1298 | mr_free(tmp1);
|
---|
1299 |
|
---|
1300 | if (i) {
|
---|
1301 | log_to_screen("Please specify a tempdir which I can write to. :)");
|
---|
1302 | fatal_error("I cannot write to the tempdir you specified.");
|
---|
1303 | }
|
---|
1304 | mr_asprintf(tmp1, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->tmpdir, bkpinfo->tmpdir);
|
---|
1305 | i = run_program_and_log_output(tmp1, 1);
|
---|
1306 | mr_free(tmp1);
|
---|
1307 |
|
---|
1308 | if (i) {
|
---|
1309 | retval++;
|
---|
1310 | log_to_screen("Please don't specify a SAMBA or VFAT or NFS tmpdir.");
|
---|
1311 | fatal_error("I cannot write to the tempdir you specified.");
|
---|
1312 | }
|
---|
1313 | }
|
---|
1314 |
|
---|
1315 | if ((flag_set['A']) && (! bkpinfo->restore_data)) {
|
---|
1316 | mr_asprintf(bkpinfo->call_after_iso, "%s", flag_val['A']);
|
---|
1317 | }
|
---|
1318 |
|
---|
1319 | if ((flag_set['B']) && (! bkpinfo->restore_data)) {
|
---|
1320 | mr_asprintf(bkpinfo->call_before_iso, "%s", flag_val['B']);
|
---|
1321 | }
|
---|
1322 |
|
---|
1323 | if ((flag_set['H']) && (! bkpinfo->restore_data)) {
|
---|
1324 | g_cd_recovery = TRUE;
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | if ((flag_set['l']) && (! bkpinfo->restore_data)) {
|
---|
1328 | #ifdef __FreeBSD__
|
---|
1329 | # define BOOT_LOADER_CHARS "GLBMR"
|
---|
1330 | #else
|
---|
1331 | # ifdef __IA64__
|
---|
1332 | # define BOOT_LOADER_CHARS "GER"
|
---|
1333 | # else
|
---|
1334 | # define BOOT_LOADER_CHARS "GLR"
|
---|
1335 | # endif
|
---|
1336 | #endif
|
---|
1337 | if (!strchr(BOOT_LOADER_CHARS, (bkpinfo->boot_loader = flag_val['l'][0]))) {
|
---|
1338 | log_msg(1, "%c? What is %c? I need G, L, E or R.", bkpinfo->boot_loader, bkpinfo->boot_loader);
|
---|
1339 | fatal_error("Please specify GRUB, LILO, ELILO or RAW with the -l switch");
|
---|
1340 | }
|
---|
1341 | #undef BOOT_LOADER_CHARS
|
---|
1342 | }
|
---|
1343 |
|
---|
1344 | if (flag_set['f']) {
|
---|
1345 | mr_free(bkpinfo->boot_device);
|
---|
1346 | bkpinfo->boot_device = resolve_softlinks_to_get_to_actual_device_file(flag_val['f']);
|
---|
1347 | }
|
---|
1348 |
|
---|
1349 | if ((flag_set['P']) && (! bkpinfo->restore_data)) {
|
---|
1350 | mr_free(bkpinfo->postnuke_tarball);
|
---|
1351 | mr_asprintf(bkpinfo->postnuke_tarball, "%s", flag_val['P']);
|
---|
1352 | }
|
---|
1353 |
|
---|
1354 | if (flag_set['Q']) {
|
---|
1355 | i = which_boot_loader(NULL);
|
---|
1356 | log_msg(3, "boot loader is %c", i);
|
---|
1357 | printf("boot loader is %c\n", i);
|
---|
1358 | finish(0);
|
---|
1359 | }
|
---|
1360 | mr_free(tmp);
|
---|
1361 |
|
---|
1362 | if ((flag_set['L']) && (! bkpinfo->restore_data)) {
|
---|
1363 | bkpinfo->use_lzo = TRUE;
|
---|
1364 | if (run_program_and_log_output("which lzop", 2)) {
|
---|
1365 | retval++;
|
---|
1366 | log_to_screen
|
---|
1367 | ("Please install LZOP. You can't use '-L' until you do.\n");
|
---|
1368 | }
|
---|
1369 | }
|
---|
1370 |
|
---|
1371 | if ((flag_set['G']) && (! bkpinfo->restore_data)) {
|
---|
1372 | bkpinfo->use_gzip = TRUE;
|
---|
1373 | if (run_program_and_log_output("which gzip", 2)) {
|
---|
1374 | retval++;
|
---|
1375 | log_to_screen
|
---|
1376 | ("Please install gzip. You can't use '-G' until you do.\n");
|
---|
1377 | }
|
---|
1378 | }
|
---|
1379 |
|
---|
1380 | bkpinfo->use_obdr = FALSE;
|
---|
1381 | if (flag_set['o']) {
|
---|
1382 | if ((!flag_set['t']) && (! bkpinfo->restore_data)) {
|
---|
1383 | log_to_screen("OBDR support is only available for tapes. Use the -t option");
|
---|
1384 | fatal_error("Aborting");
|
---|
1385 | }
|
---|
1386 | bkpinfo->use_obdr = TRUE;
|
---|
1387 | }
|
---|
1388 |
|
---|
1389 | #ifndef __FreeBSD__
|
---|
1390 | if ((!is_this_a_valid_disk_format("vfat")) && (! bkpinfo->restore_data)) {
|
---|
1391 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
1392 | log_to_screen
|
---|
1393 | ("Your kernel appears not to support vfat filesystems. I am therefore");
|
---|
1394 | log_to_screen
|
---|
1395 | ("using LILO instead of SYSLINUX as the media boot loader.");
|
---|
1396 | }
|
---|
1397 | if ((run_program_and_log_output("which mkfs.vfat", 2)) && (! bkpinfo->restore_data)) {
|
---|
1398 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
1399 | #ifdef __IA32__
|
---|
1400 | log_to_screen
|
---|
1401 | ("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as");
|
---|
1402 | log_to_screen
|
---|
1403 | ("your boot loader. I shall therefore use LILO instead.");
|
---|
1404 | #endif
|
---|
1405 | #ifdef __IA64__
|
---|
1406 | log_to_screen
|
---|
1407 | ("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI");
|
---|
1408 | log_to_screen("environment correctly. Please install it.");
|
---|
1409 | fatal_error("Aborting");
|
---|
1410 | #endif
|
---|
1411 | }
|
---|
1412 | #ifdef __IA64__
|
---|
1413 | /* We force ELILO usage on IA64 */
|
---|
1414 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
1415 | #endif
|
---|
1416 | #endif
|
---|
1417 |
|
---|
1418 | if (! bkpinfo->restore_data) {
|
---|
1419 | i = flag_set['O'] + flag_set['V'];
|
---|
1420 | if (i == 0) {
|
---|
1421 | retval++;
|
---|
1422 | log_to_screen("Specify backup (-O), verify (-V) or both (-OV).\n");
|
---|
1423 | }
|
---|
1424 | }
|
---|
1425 |
|
---|
1426 | if ((! bkpinfo->restore_data) && (flag_set['Z'])) {
|
---|
1427 | fatal_error
|
---|
1428 | ("The -Z switch is only valid in restore mode");
|
---|
1429 | }
|
---|
1430 |
|
---|
1431 | if (flag_set['Z']) {
|
---|
1432 | if (! strcmp(flag_val['Z'], "nuke")) {
|
---|
1433 | bkpinfo->restore_mode = nuke;
|
---|
1434 | } else if (! strcmp(flag_val['Z'], "interactive")) {
|
---|
1435 | bkpinfo->restore_mode = interactive;
|
---|
1436 | } else if (! strcmp(flag_val['Z'], "compare")) {
|
---|
1437 | bkpinfo->restore_mode = compare;
|
---|
1438 | } else if (! strcmp(flag_val['Z'], "mbr")) {
|
---|
1439 | bkpinfo->restore_mode = mbr;
|
---|
1440 | } else if (! strcmp(flag_val['Z'], "iso")) {
|
---|
1441 | bkpinfo->restore_mode = isoonly;
|
---|
1442 | } else if (! strcmp(flag_val['Z'], "isonuke")) {
|
---|
1443 | bkpinfo->restore_mode = isonuke;
|
---|
1444 | } else {
|
---|
1445 | bkpinfo->restore_mode = interactive;
|
---|
1446 | }
|
---|
1447 | }
|
---|
1448 |
|
---|
1449 | /* and finally... */
|
---|
1450 |
|
---|
1451 | return (retval);
|
---|
1452 | }
|
---|
1453 |
|
---|
1454 |
|
---|
1455 |
|
---|
1456 | /**
|
---|
1457 | * Get the switches from @p argc and @p argv using getopt() and place them in
|
---|
1458 | * @p flag_set and @p flag_val.
|
---|
1459 | * @param argc The argument count (@p argc passed to main()).
|
---|
1460 | * @param argv The argument vector (@p argv passed to main()).
|
---|
1461 | * @param flag_val An array indexed by switch letter - if a switch is set and
|
---|
1462 | * has an argument then set flag_val[switch] to that argument.
|
---|
1463 | * @param flag_set An array indexed by switch letter - if a switch is set then
|
---|
1464 | * set flag_set[switch] to TRUE, else set it to FALSE.
|
---|
1465 | * @return The number of problems with the command line (0 for success).
|
---|
1466 | */
|
---|
1467 | int
|
---|
1468 | retrieve_switches_from_command_line(int argc, char *argv[],
|
---|
1469 | char flag_val[128][MAX_STR_LEN],
|
---|
1470 | bool flag_set[128])
|
---|
1471 | {
|
---|
1472 | /*@ ints ** */
|
---|
1473 | int opt = 0;
|
---|
1474 | int i = 0;
|
---|
1475 | int len;
|
---|
1476 |
|
---|
1477 | /*@ bools *** */
|
---|
1478 | bool bad_switches = FALSE;
|
---|
1479 |
|
---|
1480 | assert(flag_val != NULL);
|
---|
1481 | assert(flag_set != NULL);
|
---|
1482 |
|
---|
1483 | for (i = 0; i < 128; i++) {
|
---|
1484 | flag_val[i][0] = '\0';
|
---|
1485 | flag_set[i] = FALSE;
|
---|
1486 | }
|
---|
1487 | while ((opt =
|
---|
1488 | getopt(argc, argv, MONDO_OPTIONS))
|
---|
1489 | != -1) {
|
---|
1490 | if (opt == '?') {
|
---|
1491 | bad_switches = TRUE;
|
---|
1492 | } else {
|
---|
1493 | if (flag_set[opt]) {
|
---|
1494 | bad_switches = TRUE;
|
---|
1495 | log_to_screen("Switch -%c previously defined as %s\n", opt, flag_val[opt]);
|
---|
1496 | } else {
|
---|
1497 | flag_set[opt] = TRUE;
|
---|
1498 | if (optarg) {
|
---|
1499 | len = strlen(optarg);
|
---|
1500 | if (optarg[0] != '/' && optarg[len - 1] == '/') {
|
---|
1501 | optarg[--len] = '\0';
|
---|
1502 | log_to_screen
|
---|
1503 | ("Warning - param '%s' should not have trailing slash!",
|
---|
1504 | optarg);
|
---|
1505 | }
|
---|
1506 | if (opt == 'd') {
|
---|
1507 | if (strchr(flag_val[opt], '/')
|
---|
1508 | && flag_val[opt][0] != '/') {
|
---|
1509 | log_to_screen("-%c flag --- must be absolute path --- '%s' isn't absolute", opt, flag_val[opt]);
|
---|
1510 | bad_switches = TRUE;
|
---|
1511 | }
|
---|
1512 | }
|
---|
1513 | strcpy(flag_val[opt], optarg);
|
---|
1514 | }
|
---|
1515 | }
|
---|
1516 | }
|
---|
1517 | }
|
---|
1518 | for (i = optind; i < argc; i++) {
|
---|
1519 | bad_switches = TRUE;
|
---|
1520 | log_to_screen("Invalid arg -- %s\n", argv[i]);
|
---|
1521 | }
|
---|
1522 | return (bad_switches);
|
---|
1523 | }
|
---|
1524 |
|
---|
1525 |
|
---|
1526 |
|
---|
1527 |
|
---|
1528 | /**
|
---|
1529 | * Print a not-so-helpful help message and exit.
|
---|
1530 | */
|
---|
1531 | void help_screen()
|
---|
1532 | {
|
---|
1533 | log_msg(1, "Type 'man mondoarchive' for more information\n");
|
---|
1534 | exit(1);
|
---|
1535 | }
|
---|
1536 |
|
---|
1537 |
|
---|
1538 | /**
|
---|
1539 | * Terminate Mondo in response to a signal.
|
---|
1540 | * @param sig The signal number received.
|
---|
1541 | */
|
---|
1542 | void terminate_daemon(int sig)
|
---|
1543 | {
|
---|
1544 | char *tmp = NULL;
|
---|
1545 | char *tmp2 = NULL;
|
---|
1546 |
|
---|
1547 | switch (sig) {
|
---|
1548 | case SIGINT:
|
---|
1549 | mr_asprintf(tmp, "SIGINT");
|
---|
1550 | mr_asprintf(tmp2, "You interrupted me :-)");
|
---|
1551 | break;
|
---|
1552 | case SIGKILL:
|
---|
1553 | mr_asprintf(tmp, "SIGKILL");
|
---|
1554 | mr_asprintf(tmp2,
|
---|
1555 | "I seriously have no clue how this signal even got to me. Something's wrong with your system.");
|
---|
1556 | break;
|
---|
1557 | case SIGTERM:
|
---|
1558 | mr_asprintf(tmp, "SIGTERM");
|
---|
1559 | mr_asprintf(tmp2, "Got terminate signal");
|
---|
1560 | break;
|
---|
1561 | case SIGHUP:
|
---|
1562 | mr_asprintf(tmp, "SIGHUP");
|
---|
1563 | mr_asprintf(tmp2, "Hangup on line");
|
---|
1564 | break;
|
---|
1565 | case SIGSEGV:
|
---|
1566 | mr_asprintf(tmp, "SIGSEGV");
|
---|
1567 | mr_asprintf(tmp2,
|
---|
1568 | "Internal programming error. Please send a backtrace as well as your log.");
|
---|
1569 | break;
|
---|
1570 | case SIGPIPE:
|
---|
1571 | mr_asprintf(tmp, "SIGPIPE");
|
---|
1572 | mr_asprintf(tmp2, "Pipe was broken");
|
---|
1573 | break;
|
---|
1574 | case SIGABRT:
|
---|
1575 | mr_asprintf(tmp, "SIGABRT");
|
---|
1576 | mr_asprintf(tmp2, "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message.");
|
---|
1577 | break;
|
---|
1578 | default:
|
---|
1579 | mr_asprintf(tmp, "(Unknown)");
|
---|
1580 | mr_asprintf(tmp2, "(Unknown)");
|
---|
1581 | }
|
---|
1582 |
|
---|
1583 | mr_strcat(tmp, " signal received from OS");
|
---|
1584 | log_to_screen(tmp);
|
---|
1585 | mr_free(tmp);
|
---|
1586 |
|
---|
1587 | log_to_screen(tmp2);
|
---|
1588 | mr_free(tmp2);
|
---|
1589 | if (sig == SIGABRT) {
|
---|
1590 | sleep(10);
|
---|
1591 | }
|
---|
1592 | kill_buffer();
|
---|
1593 |
|
---|
1594 | free_MR_global_filenames();
|
---|
1595 |
|
---|
1596 | fatal_error("MondoRescue is terminating in response to a signal from the OS");
|
---|
1597 | finish(254); // just in case
|
---|
1598 | }
|
---|
1599 |
|
---|
1600 |
|
---|
1601 |
|
---|
1602 |
|
---|
1603 | /**
|
---|
1604 | * Turn signal-trapping on or off.
|
---|
1605 | * @param on If TRUE, turn it on; if FALSE, turn it off (we still trap it, just don't do as much).
|
---|
1606 | */
|
---|
1607 | void set_signals(int on)
|
---|
1608 | {
|
---|
1609 | int signals[] = { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 };
|
---|
1610 | int i;
|
---|
1611 |
|
---|
1612 | signal(SIGPIPE, sigpipe_occurred);
|
---|
1613 | for (i = 0; signals[i]; i++) {
|
---|
1614 | if (on) {
|
---|
1615 | signal(signals[i], terminate_daemon);
|
---|
1616 | } else {
|
---|
1617 | signal(signals[i], termination_in_progress);
|
---|
1618 | }
|
---|
1619 | }
|
---|
1620 | }
|
---|
1621 |
|
---|
1622 |
|
---|
1623 |
|
---|
1624 |
|
---|
1625 | /**
|
---|
1626 | * Exit immediately without cleaning up.
|
---|
1627 | * @param sig The signal we are exiting due to.
|
---|
1628 | */
|
---|
1629 | void termination_in_progress(int sig)
|
---|
1630 | {
|
---|
1631 | log_msg(1, "Termination in progress");
|
---|
1632 | usleep(1000);
|
---|
1633 | pthread_exit(0);
|
---|
1634 | }
|
---|
1635 |
|
---|
1636 | /* @} - end of cliGroup */
|
---|