📄 backup.c
字号:
len=snprintf(cmd,4096,"%s -%c -v -P -f %s -X sitback.excludelist",conf__tar,conf__tar_action,conf__archive); else { if(conf__compress && strstr(conf__compressapp,"gzip")!=NULL) { len=snprintf(cmd,4096,"%s -%c -v -P -f %sarchive.tar.gz -X sitback.excludelist",conf__tar,conf__tar_action,conf__temp); } else if(conf__compress && strstr(conf__compressapp,"bzip2")!=NULL) { len=snprintf(cmd,4096,"%s -%c -v -P -f %sarchive.tar.bz2 -X sitback.excludelist",conf__tar,conf__tar_action,conf__temp); } else if(conf__compress && strstr(conf__compressapp,"zip")!=NULL) { len=snprintf(cmd,4096,"%s -%c -v -P -f %sarchive.tar.zip -X sitback.excludelist",conf__tar,conf__tar_action,conf__temp); } else if(conf__compress && strstr(conf__compressapp,"compress")!=NULL) { len=snprintf(cmd,4096,"%s -%c -v -P -f %sarchive.tar.Z -X sitback.excludelist",conf__tar,conf__tar_action,conf__temp); } else { len=snprintf(cmd,4096,"%s -%c -v -P -f %sarchive.tar -X sitback.excludelist",conf__tar,conf__tar_action,conf__temp); } } /*compression*/ if(conf__compress) len+=snprintf(&cmd[len],4096-len," --use-compress-program %s",conf__compressapp); /* remote device ?? */ if(conf__rhost[0]!='\0') len+=snprintf(&cmd[len],4096-len," --rsh-command=%s",conf__rsh); /* follow symlinks debug("commandline: '%s'\n",commandline);?? */ if(conf__follow_symlinks) len+=snprintf(&cmd[len],4096-len," -h"); /*Multiple or fixed length volumes*/ if(conf__volume_length!=0) len+=snprintf(&cmd[len],4096-len," -L %d",conf__volume_length); else if(conf__allow_multiple) len+=snprintf(&cmd[len],4096-len," -M"); /*start mark*/ len+=snprintf(&cmd[len],4096-len," %s",conf__start_mark); /*archive list*/ len+=snprintf(&cmd[len],4096-len," sitback.archivelist"); /*exclude list*/ len+=snprintf(&cmd[len],4096-len," sitback.excludelist"); /*archive id*/ len+=snprintf(&cmd[len],4096-len," sitback.archiveid"); /*archive name*/ len+=snprintf(&cmd[len],4096-len," sitback.archivename"); /*file locations. Not included if were are only updating/creating archive info*/ if(conf__update_archiveinfo==0 && conf__filelist!=NULL) { /* rewind the list */ while(conf__filelist->prev!=NULL) conf__filelist=conf__filelist->prev; /* add the locations */ while(1) { len+=snprintf(&cmd[len],4096-len," \"%s\"",conf__filelist->target); /* next file location */ if(conf__filelist->next==NULL) break; else conf__filelist=conf__filelist->next; } } /* debug garbage */ debug("ready to execute..:\n"); debug(" '%s'\n",cmd); /*execute and wait for the process to finish*/ UI__Message("- Creating archive\n"); if((pid=Execute(cmd))<0) return -1; debug("Waiting for pid %d\n",pid); waitpid(pid,&status,0); debug("Backup has finished.. status is %d\n",status); /*no problems*/ return status;}/******************************************************************** int __execute_filecopy_backup() Execute a filecopy backup arguments: none return: return code on success -1 on error (unable to exec)********************************************************************/int __execute_filecopy_backup(){ int pid; int status=0; char cmd[4096]; int len; struct stat statbuf; /* First create the target directory (ignore errors if it already exists) */ if(mkdir(conf__archive,0700)) { if(errno!=EEXIST) { log("Error while creating target directory '%s'\n",strerror(errno)); UI__Warning("Error while creating target directory '%s'\n",strerror(errno)); return -1; } else { /* Make sure it is a directory, and that we can access it */ if(stat(conf__archive,&statbuf)) { UI__Warning("Unable to stat() the target directory\n"); log("Unable to stat() the target directory\n"); return -1; } if(!S_ISDIR(statbuf.st_mode)) { UI__Warning("Archive directory can not be created because a file with that name already exists\n"); log("Archive directory can not be created because a file with that name already exists\n"); return -1; } if(access(conf__archive,R_OK | W_OK | X_OK)) { UI__Warning("Missing permissions on archive directory\n"); log("Missing permissions on archive directory\n"); return -1; } debug("Archive directory exists and is- writeable\n"); } } else { debug("Created archive directory\n"); } /* Begin the copy command */ len=sprintf(cmd,"cp -dpRfv sitback.archivelist sitback.excludelist sitback.archiveid sitback.archivename"); /* rewind the files list */ while(conf__filelist->prev!=NULL) conf__filelist=conf__filelist->prev; /* add the locations */ while(1) { len+=snprintf(&cmd[len],4096-len," \"%s\"",conf__filelist->target); /* next file location */ if(conf__filelist->next==NULL) break; else conf__filelist=conf__filelist->next; } /* End the copy command */ len+=snprintf(&cmd[len],4096," %s",conf__archive); /* debug garbage */ debug("ready to execute..:\n"); debug(" '%s'\n",cmd); /*execute and wait for the process to finish*/ UI__Message("- Copying files\n"); if((pid=Execute(cmd))<0) return -1; waitpid(pid,&status,0); debug("Backup has finished.. status is %d\n",status); /*no problems*/ return status;}/******************************************************************** int __execute_iso_backup() Execute a iso/cdr/cdrw backup arguments: archive: If NULL, do a regular backup, else take the file indicated and write it to the cd return: return code on success -1 on error (unable to exec)********************************************************************/int __execute_iso_backup(char *archive){ int pid; int status=0; char cmd[4096]; int len; char options[1024]=""; int tracksize; time_t currtime=time(NULL); struct tm *timeptr=localtime(&currtime); char timestamp[30]; FILE *file; /* If the 'CD ON THE FLY' option is included, create the cd directory without a temporary iso image */ if(conf__cd_on_the_fly && (conf__type==CDR || conf__type==CDRW || conf__type==TARCDR || conf__type==TARCDRW || conf__type==ZIPCDR || conf__type==ZIPCDRW)) return __execute_iso_backup_on_the_fly(archive); /* remove the temp./previous iso file */ if(conf__type==ISO || conf__type==TARISO || conf__type==ZIPISO) unlink(conf__archive); else { if(conf__temp[0]=='\0') snprintf(cmd,1024,"%s/sitback.iso",conf__homedir); else snprintf(cmd,1024,"%ssitback.iso",conf__temp); unlink(cmd); } /* Begin the mkisofs command */ len=sprintf(cmd,"%s -allow-lowercase -allow-multidot -p sitback_%s -A \"%s\" ",conf__mkisofs,VERSION,conf__archive_name); if(conf__follow_symlinks) len+=sprintf(&cmd[len],"-f "); len+=sprintf(&cmd[len],"-l -J -L -r -relaxed-filenames -v -U -graft-points -D "); if(conf__type==ISO || conf__type==TARISO || conf__type==ZIPISO) len+=sprintf(&cmd[len],"-o %s ",conf__archive); else { if(conf__temp[0]=='\0') len+=sprintf(&cmd[len],"-o %s/sitback.iso ",conf__homedir); else len+=sprintf(&cmd[len],"-o %ssitback.iso ",conf__temp); } /* The file(s) to write */ if(archive==NULL) { /* Standard stuff */ if(conf__no_info==0) { len+=sprintf(&cmd[len],"sitback.archivelist sitback.excludelist sitback.archiveid sitback.archivename "); } /* rewind the files list */ while(conf__filelist->prev!=NULL) conf__filelist=conf__filelist->prev; /* add the locations */ debug ("Including files from the filelist in the iso image\n"); while(1) { if(conf__add_to_root==0) len+=snprintf(&cmd[len],4096-len,"\"%s/=%s\" ",&conf__filelist->target[1],conf__filelist->target); else len+=snprintf(&cmd[len],4096-len,"\"%s\" ",conf__filelist->target); /* next file location */ if(conf__filelist->next==NULL) break; else conf__filelist=conf__filelist->next; } /* Add timestamp */ sprintf(timestamp,"%04d%02d%02d%02d%02d%02d.timestamp",timeptr->tm_year+1900,timeptr->tm_mon,timeptr->tm_mday,timeptr->tm_hour,timeptr->tm_min,timeptr->tm_sec); if((file=fopen(timestamp,"w"))!=NULL) { fprintf(file,"%04d%02d%02d%02d%02d%02d",timeptr->tm_year+1900,timeptr->tm_mon,timeptr->tm_mday,timeptr->tm_hour,timeptr->tm_min,timeptr->tm_sec); fclose(file); } len+=snprintf(&cmd[len],4096-len,"%s",timestamp); } else { /* Include the specified file */ debug("Including the file '%s' in the iso image\n",archive); len+=snprintf(&cmd[len],4096-len,"%s",archive); /* Add timestamp */ sprintf(timestamp,"%04d%02d%02d%02d%02d%02d.timestamp",timeptr->tm_year+1900,timeptr->tm_mon,timeptr->tm_mday,timeptr->tm_hour,timeptr->tm_min,timeptr->tm_sec); if((file=fopen(timestamp,"w"))!=NULL) { fprintf(file,"%04d%02d%02d%02d%02d%02d",timeptr->tm_year+1900,timeptr->tm_mon,timeptr->tm_mday,timeptr->tm_hour,timeptr->tm_min,timeptr->tm_sec); fclose(file); } len+=snprintf(&cmd[len],4096-len," %s",timestamp); } /* Make sure we do not have a trailing blankspace */ if(cmd[strlen(cmd)-1]==' ') cmd[strlen(cmd)-1]='\0'; /* debug garbage */ debug("ready to execute..:\n"); debug(" '%s'\n",cmd); /*execute and wait for the process to finish*/ UI__Message("- Creating cd image\n"); if((pid=Execute(cmd))<0) return -1; waitpid(pid,&status,0); debug("Iso creating has finished.. status is %d\n",status); /* Any errors */ if(status) { UI__Warning("Error while creating iso image. Check report for details\n"); return -1; } /* Any further actions ?? */ if(conf__type==CDR || conf__type==CDRW || conf__type==TARCDR || conf__type==TARCDRW || conf__type==ZIPCDR || conf__type==ZIPCDRW) { /* get the tracksize of this cd */ UI__Message("- Calculating size of archive\n"); tracksize=__tracksize(archive); if(tracksize==-1) return -1; /* Should the cd be blanked ?? */ if(conf__type==CDRW || conf__type==TARCDRW || conf__type==ZIPCDRW) { /* Blank the disc */ debug("Blanking cd-rw\n"); UI__Message("- Blanking cd-rw\n"); if(conf__speed[0]=='\0') snprintf(cmd,4096,"%s -v blank=fast -nofix dev=%s tsize=%d",conf__cdrecord,conf__archive,tracksize); else snprintf(cmd,4096,"%s -v blank=fast -nofix speed=%s dev=%s tsize=%d",conf__cdrecord,conf__speed,conf__archive,tracksize); if((pid=Execute(cmd))<0) return -1; waitpid(pid,&status,0); if(status!=0) return -1; /* Done */ debug("Blanking complete\n"); } /* Prepare the set of extra options for cdrecord (if any) */ len=0; if(conf__buffersize[0]!='\0') len+=snprintf(&options[len],1024,"fs=%s ",conf__buffersize); if(conf__eject) len+=snprintf(&options[len],1024,"-eject "); /* Write the cd */ sleep(3); /* Allow the status output to flush */ debug("Writing iso image to cd\n"); UI__Message("- Writing cd\n"); if(tracksize!=0) { if(conf__speed[0]=='\0') { if(conf__temp[0]=='\0') { if(conf__type==CDR || conf__type==TARCDR || conf__type==ZIPCDR || conf__fixate) snprintf(cmd,4096,"%s %s-v dev=%s tsize=%d %s/sitback.iso",conf__cdrecord,options,conf__archive,tracksize*2048,conf__homedir); else snprintf(cmd,4096,"%s %s-v -nofix dev=%s tsize=%d %s/sitback.iso",conf__cdrecord,options,conf__archive,tracksize*2048,conf__homedir); } else { if(conf__type==CDR || conf__type==TARCDR || conf__type==ZIPCDR || conf__fixate) snprintf(cmd,4096,"%s %s-v dev=%s tsize=%d %ssitback.iso",conf__cdrecord,options,conf__archive,tracksize*2048,conf__temp); else snprintf(cmd,4096,"%s %s-v -nofix dev=%s tsize=%d %ssitback.iso",conf__cdrecord,options,conf__archive,tracksize*2048,conf__temp); } } else { if(conf__temp[0]=='\0') { if(conf__type==CDR || conf__fixate) snprintf(cmd,4096,"%s %s-v speed=%s dev=%s tsize=%d %s/sitback.iso",conf__cdrecord,options,conf__speed,conf__archive,tracksize*2048,conf__homedir); else snprintf(cmd,4096,"%s %s-v speed=%s -nofix dev=%s tsize=%d %s/sitback.iso",conf__cdrecord,options,conf__speed,conf__archive,tracksize*2048,conf__homedir); } else { if(conf__type==CDR || conf__fixate) snprintf(cmd,4096,"%s %s-v speed=%s dev=%s tsize=%d %ssitback.iso",conf__cdrecord,options,conf__speed,conf__archive,tracksize*2048,conf__temp); else snprintf(cmd,4096,"%s %s-v speed=%s -nofix dev=%s tsize=%d %ssitback.iso",conf__cdrecord,options,conf__speed,conf__archive,tracksize*2048,conf__temp); } } } else { debug("No tracksize\n"); if(conf__speed[0]=='\0') { if(conf__temp[0]=='\0') { if(conf__type==CDR || conf__fixate) snprintf(cmd,4096,"%s %s-v dev=%s %s/sitback.iso",conf__cdrecord,options,conf__archive,conf__homedir); else snprintf(cmd,4096,"%s %s-v -nofix dev=%s %s/sitback.iso",conf__cdrecord,options,conf__archive,conf__homedir); } else { if(conf__type==CDR || conf__fixate) snprintf(cmd,4096,"%s %s-v dev=%s %ssitback.iso",conf__cdrecord,options,conf__archive,conf__temp); else snprintf(cmd,4096,"%s %s-v -nofix dev=%s %ssitback.iso",conf__cdrecord,options,conf__archive,conf__temp); } } else { if(conf__temp[0]=='\0') { if(conf__type==CDR || conf__fixate) snprintf(cmd,4096,"%s %s-v speed=%s dev=%s %s/sitback.iso",conf__cdrecord,options,conf__speed,conf__archive,conf__homedir); else snprintf(cmd,4096,"%s %s-v speed=%s -nofix dev=%s %s/sitback.iso",conf__cdrecord,options,conf__speed,conf__archive,conf__homedir); } else { if(conf__type==CDR || conf__fixate)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -