• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

[转贴]UNIX备份与安装的辅助程序

发布: 2007-6-08 22:43 | 作者: seanhe | 来源: | 查看: 21次 | 进入软件测试论坛讨论

领测软件测试网
[color=blue:058a6f686c]
  在UNIX系统上,我们有时会遇到这种情况:在某台UNIX系统机上安装好一个几百M的应用系统(如一个数据库系统)后,若在一个局域网内安装另一台机器,只需使用RCP把相应目录及文件拷贝即可,而毋需再安装一次;但当另一台机器不在一个局域网内,只是一个低速的广域网,怎么利用已安装好的机器来快速安装呢?显然使用RCP已不现实,这时我们可以把已安装好的UNIX系统上的相应目录合并成一个文件,然后拷贝到另一硬盘上;携带该硬盘至需待装机处,把合并后的文件拷贝到待装机上,再把文件还原成目录,这样便完成了安装。有兴趣的可修改该程序,编写一个UNIX上的arj实用工具。
  笔者在维护下属单位的系统中常使用这种方法,速度快,方便。
  该程序不仅适应于安装,而且也适应于用DOS系统备份UNIX系统上的应用。
  附源程序:(已调试通过,并多次实现使用)
  #include<sys/types.h>
  #include<sys/stat.h>
  #include<stdio.h>
  #include<ftw.h>
  #define AR″ ″
  FILE farj;intlist();
  void arx();
  main(argc,argv)
  int argc;char argv[]
  {charfname1[100],opt[1];
  if(argc<4){printf(″\nusage:myar a|x arj—filepathdestpath\n″);exit(1);}
  strcpy(opt,argv[1]);
  if(opt[0]==″ a ″){strcpy(fname1,argv[2]);
  if((farj=fopen(fname1,″ wb ″))==NULL)
  {printf(″\nerrorin open file%s\n″,fname1);exit(1);}
  else ftw(argv[3],list,1);}
  else if(opt[0]==″ x ″arx(argv[2],argv[3]);
  else{printf(″\nusage:myar a|x arj-filepathdestpath\n″);exit(1);}
  fclose(farj);}
  intlist(name,status,type)
  char name;struct stat status;inttype;
  {int size,left,bb=80;char buf[80],buf1[80];FILE ft;
  charfname[100];if(type==FTW-NS)return(0);
  if(type==FTW-F){
  sprintf(buf,″%s%30%d%d\n″,name,status->st—mode&0777,status->st—reserved1,status->st-reserved2,status->st-size);
  /若UNIX是SCO-UNIX可把″st-reserved1″改成″st-uid″把″st-reserved2″改成″st-gid″/
  fwrite(buf,strlen(buf),1,farj);printf(″\nbeing add%s″,name);
  strcpy(fname,name);ft=fopen(fname,″rb″);size=status->st-size;
  if(ft==NULL){printf(“\nerrorin open%s",fname);
  exit(1);}
  while(fread(buf1,bb,1,ft)>0)fwrite(buf1,bb,1,farj);left=size%bb;
  if(left>0){fread(buf1,left,1,ft);fwrite(buf1,left,1,farj);}
  fclose(ft);}
  else
  fprintf(farj,″%s%30%d\n″,name,status->st—mode&0777,status->st—reserved1,status->st—reserved2);
  return(0);
  }
  / ==================== /
  / the follow function for extract /
  void arx(filepath,destpath)
  charfilepath[100],destpath[100];
  {FILE ft;
  int acc,owner,grp,size,s1=80,s2,i,len,p,sp,sl;
  charfname[70],fnamet[70],fname[70],path[70],str[80],buf[80];
  strcpy(fname1,filepath);
  if((farj=fopen(fnam1,″rb″)=NULL){perror(″farj″;exit(1);}
  while(!feof(farj)){
  fgets(buf,s1,farj);
  acc=0;owner=0;grp=0;size=0;
  sscanf(buf,″%s%30%d%d%d″,fnamet,&acc,&owner,&grp,&size);
  if(fnamet[0]==″ ″){len=strlen(fanmet);
  for(i=1;i<len;i++)path[i-1]=fnamet[i];
  path[len-1]=″\0″;
  strcpy(str,″ mkdir ″);
  strcat(str,destpath);
  if(path[0]==″/″);
  else  strcat(str,″/″);
  strcat(str,path);
  printf(″\nbeing%s″,str);
  system(str);
  continue;}
  else{printf(″\nbeing extracted from\n%s″,fnamet);
  if(fnamet[0]==″/″)
  sprintf(fname,″%s/%s″,destpath,fnamet);
  else
  sprintf(fname,″%s/%s,destpath,fnamet);
  if((ft=fopen(fname,″ab″))==NULL){
  perror(″\nopen ft=″);
  printf(″%s\n″,fname);
  continue;}
  sp=0;
  while(sp<size){
  if(size-sp >=s1){fread(buf,s1,1,farj);fwrite(buf,s1,1,ft);
  sp=sp+s1;}
  else{fread(buf,size-sp,1,farj);
  fwrite(buf,size-sp,1,ft);
  sp=size;
  break;}}
  fclose(ft);
  if(chmod(fname,acc)< 0) printf(″\nerrorin chmod:%s″,fname);
  if(chown(fname,owner,grp)==-1)printf(″\nerror inchown:%s″,fname);
  }
  }
  } 

作者单位:王丽君(农业银行广西全州县支行)[/color:058a6f686c]

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网