//------------------------------------------------------------------ // This is a backup utility that will copy a file to the backup dir // and timestamp it. // It was designed to exist in each subdirectory of NACHOS and to // copy files to a directory entitled: backup // This way, any backups will be outside (one level down) from the // scope of the submit program. // // Theoretical usage: // 1) setup the directory backup: mkdir backup // 2) run "save" from this userprog directory (have a copy in it) // // Sample: // save addrspace.cc // save addrspace.h now both files are in /backup // with a timestamp at the end // // To compile: gcc save.cc -o save // // Designed by Will Page and Ryan Cunningham for CSCI402 (c) 2003 // University of Southern California // Updated: 25.Feb.03 //------------------------------------------------------------------ #include #include #include #include int main(int argc, char **argv) { char comline[200]; char stamp[11]; time_t clk = time(NULL); tm *curtime = localtime( &clk ); // prepare arg* for looking at first passed param argc--; argv++; printf("File to backup: %s\n",*argv); strcpy(comline, "cp "); strcat(comline, *argv); strcat(comline, " backup/"); strcat(comline, *argv); strcat(comline, "."); //int tm_min; /* minutes after the hour - [0, 59] */ //int tm_hour; /* hour since midnight - [0, 23] */ //int tm_mday; /* day of the month - [1, 31] */ //int tm_mon; /* mons since jan - [0-11] */ printf("Seed: %ld\n",time(NULL)); printf("Mon: %d Day: %d Hour: %d Min: %d\n",curtime->tm_mon,curtime->tm_mday,curtime->tm_hour,curtime->tm_min); stamp[0] = (curtime->tm_mon + 1) / 10 + '0'; stamp[1] = (curtime->tm_mon + 1) % 10 + '0'; stamp[2] = curtime->tm_mday / 10 + '0'; stamp[3] = curtime->tm_mday % 10 + '0'; stamp[4] = '-'; stamp[5] = curtime->tm_hour / 10 + '0'; stamp[6] = curtime->tm_hour % 10 + '0'; stamp[7] = ':'; stamp[8] = curtime->tm_min / 10 + '0'; stamp[9] = curtime->tm_min % 10 + '0'; stamp[10] = '\0'; printf("Stamp: %s\n", stamp); strcat(comline, stamp); printf("%s -> %s\n",*argv,comline); system(comline); printf("%c",7); //ding that we are done. return 0; }