您当前的位置:linuxsea -> unix

UNIX备份与安装的辅助程序
作者:linuxsea  来源:linux海洋  发布时间:2006-10-21 19:50:11  发布人:admin

减小字体 增大字体

  在UNIX系统上,我们有时会遇到这种情况:在某台UNIX系统机上安装好一个几百M的应用系统(如一个数据库系统)后,若在一个局域网内安装另一台机器,只需使用RCP把相应目录及文件拷贝即可,而毋需再安装一次;但当另一台机器不在一个局域网内,只是一个低速的广域网,怎么利用已安装好的机器来快速安装呢?显然使用RCP已不现实,这时我们可以把已安装好的UNIX系统上的相应目录合并成一个文件,然后拷贝到另一硬盘上;携带该硬盘至需待装机处,把合并后的文件拷贝到待装机上,再把文件还原成目录,这样便完成了安装。有兴趣的可修改该程序,编写一个UNIX上的arj实用工具。
  笔者在维护下属单位的系统中常使用这种方法,速度快,方便。
  该程序不仅适应于安装,而且也适应于用DOS系统备份UNIX系统上的应用。
  附源程序:(已调试通过,并多次实现使用)
  
QUOTE:
#include
  #include
  #include
  #include
  #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  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  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);
  }
  }
  }

[] [返回上一页] [打 印] [收 藏]
下一篇文章:unix常用命令
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论…]
· 入门提高
· 开发区
· 网络与应用
· unix
· 新闻与认证

相关文章

· 实现Windows与Unix、Linux间数据交换
· 新手看招 硬盘安装Ubuntu一次就搞定
· 系统管理 从头开始对ubuntu进行优化
· 什么是Linux?Linux与UNIX之间的关系
· 老手经验谈 介绍UNIX高手的十大习惯
· [图文] Ubuntu Linux操作系统中的用户管..
· 使用Mount bind时需要注意的权限问题
· 关于国内UNIX主机常见安全漏洞的描述
· 通过LoadRunner监控Linux的资源状况
· 如何成为一个UNIX系统的“好色”之徒
· Ubuntu Linux使用过程中的一些小技巧
· 各类UNIX和Linux密码丢失后的解决方法
· [图文] Ubuntu Linux系统中安装GNOME开始..
· Ubuntu 6.10系统下使用超级终端Kermit
· Ubuntu6.06 Linux安装Mplayer过程解析



© 2006-2008 Linuxsea.net, all rights reserved