glib 1.2 way of doing a tar/find backup?



I have a directory that has data stored in it every 5 minutes throughout
the day.  I keep seven days of data. Sometimes I need to save about an
hour or two hours of that data to DVD.  I can tar and gzip the data
really easy into a temp directory using a shell command:

tar -czf /tmp/20040808_backup.tar.gz `find /data/monday -daystart -cmin
+1440 -cmin -2880`

How can I do this in C/glib/gtk =< 1.2?  

Using glade I've made a GUI just for backing put this data ... and I've
got a lot of the code working just fine.  The user can select a day to
archive and use slider bars to adjust the start and end times for the
data backup.  Now I need to actually do the backup part based upon user
selections. 

I'm not allowed to upgrade any of the software, so I have to use 
glib 1.2  I'm also a beginner in learning C/glib/gtk.

Any help would be appreciated with creating the tar.gz file. ;-)  Here's
what I have so far with the target function:


void create_tar_file (GtkButton *button, gchar *day)
{
        GtkLabel *main_label;
        main_label = (gpointer)lookup_widget(GTK_WIDGET(button), "label_main");
        
        GtkProgressBar *progress_bar1;
        progress_bar1 = (gpointer)lookup_widget(GTK_WIDGET(button),
"progressbar1");
        
        gchar *update_label;
        gchar *find_command;
        gint cmin_start, cmin_stop;
        gchar string_start[10], string_end[10];
        gint child_stat = 0;
        gboolean test = TRUE;
        gint process_status;
        gint progress = 0;
        pid_t pid;
        
        g_print("\nSTART OF CREATE TAR FILE FUNCTION\n");
        update_label = g_strconcat("Please Wait:\nArchiving ", day, " Files",
NULL);
        gtk_label_set_text(main_label, update_label);
        
        cmin_start = ((gint)g_hash_table_lookup(daysTable, day)) -
((gint)((24.0 - start_sun) * 60));
        cmin_stop = ((gint)g_hash_table_lookup(daysTable, day)) - ((gint)((24.0
- end_sun) * 60));
        
        sprintf(string_start, "%d", cmin_start);
        sprintf(string_end, "%d", cmin_stop);
        
        tar_filename = g_strconcat("/tmp/", day, ".tar.gz ", NULL);
        
        unlink(find_backup_file);
        
        find_command = g_strconcat("/tmp/", day, ".tar.gz `", find_exe, " ",
rolloverdir, "/", day, "`", NULL);
        
        g_print("%s find command: %s\n", day, (gchar *)find_command);
        
        pid = fork();
        if (pid == -1) {
                g_error("Forking Failed");
        } else if (pid == 0) {
                // This is the child .... all code for the child.
                g_print("Running the command:\n");
                if (execlp("find", "find", "/home/tony/", NULL) != 0) {
                        g_error("The child process exited abnormally in find command");
                        _exit(-1);
                }
        } else {
                // This is the parent ... all code for the parent.
                while (test) {
                        process_status = waitpid((pid_t)pid, &child_stat, WNOHANG);
                        if (process_status == 0) {
                                // process still running ... update progress bar.
                                gtk_progress_set_value (GTK_PROGRESS (progress_bar1), progress);
                                progress = (progress + 1) % 2;
                                gtk_main_iteration();
                                test = TRUE;
                        } else if (process_status == pid) {
                                // child exited ... reset the progress bar somehow.
                                g_print("Child exited: Stopping progress bar.\n");
                                update_label = g_strconcat("Finished Archiving ", day, " Files.",
NULL);
                                gtk_label_set_text(main_label, update_label);
                                g_print("Finished Archiving %s Files\n", day);
                                g_free(find_command);
                                test = FALSE;
                        } else {
                                g_error("Some sort of error while checking process_status\n");
                                test = FALSE;
                                _exit(-1);
                        }
                }
        }
        g_print("\nEND OF MAIN BACKUP FUNCTION\n");
}

Thanks for the help :-)

--Tony





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]