#!/bin/csh -f # ------------------------------------------------------------------------------ # C shell script to tar and zip all the files in the specified directory tree. # The resulting archive is stored in the parent directory in a file named: # dir_yyyy_mm_dd_hh_mm_ss.tar.gz # where "dir" is the name of the directory archived, and yyyy_mm_dd_hh_mm_ss # is a date/time stamp. # ------------------------------------------------------------------------------ # Parameters: # $1 = directory to archive Default = current directory # ------------------------------------------------------------------------------ # Revision History: # $Log: arc.csh,v $ # Revision 1.1 89/11/18 01:31:50 stluka # Initial revision # # Original version received from Van Gale 11/17/89. # ------------------------------------------------------------------------------ # Check for incorrect usage if ($#argv > 1) then set verb = $0 echo "Usage: $verb:t directory_name" exit 1 endif # Default the directory to be archived to the current directory, unless # explicitly specified. if ($#argv == 1) then set dir = "$1" else set dir = "." endif # Check for the existence of the directory to be archived. if (! -d $dir) then echo "Directory $dir not found." exit 1 endif # Determine the name to give to the archive (full name of directory to be # archived plus date/time plus extension ".tar.gz"). set archive = `cd $dir;pwd`_`date +%Y_%m_%d_%H_%M_%S.tar.gz` # Check for the existence of the archive file to avoid overwriting it. if (-e $archive) then echo "Archive $archive exists. Not overwritten." exit 1 endif # Combine all the files into one zipped tarball in the parent directory. # Note: The current directory is changed to the parent of the directory to # be archived so that the archive will contain names relative to the # parent. This is important to make sure that the files are restored # to the correct locations by unarc.csh. # Note: The specified directory is expanded (by pwd), then its simple name # (relative to its parent) is used on the tar command. This ensures # that the right directory is archived. Otherwise, for example, the # argument "." (current directory) would cause a cd to "../." (the # parent of the current directory and an archive of "." (the parent # directory). set child = `cd $dir;pwd` set child = $child:t cd $dir/.. echo "Creating archive $archive from directory tree $cwd/$child..." tar cvp -f $archive -z $child if ($status) then echo "Error during tar. Check file $archive." exit 1 endif