#!/bin/csh -f ############################################################################# # # This script will delete files in the ~user1 home directory, and then copy # all files in the ~user2 home directory to the ~user1 directory. # # It is intended that the script is executed by user user1, to restore the # default files from ~user2/$bupdir, which is a backup directory. # # # Instructions to make backup directory: # (1) As user1, set permissions from ~user1 as follows: # chmod -R ug+r,go-w,go+X,u+w * (user1 and user2 same group) # # Check about the .* -- this is expanded and includes the .. directory => # alot of errors produced. # # (2) As user2, delete all files in backup directory... # \rm -rf .* * # (3) As user2, copy files to backup directory. # cd ~$user1 ; tar cf - . | (cd ~$user2/bup; tar xf -) # # Note: MIDAS creates sockets which cannot be tar'ed: # tar: ./midwork/xhelp00 is not a file. Not dumped # Ignore this. The sockets will be created as needed. # # # Author: James Brewer # Version: 1.0 Date: Apr.1, 2000 ############################################################################# # # Check script arguments... # if($#argv != 0 ) then echo "Usage: $0 exit(-1) endif # # Define action on interrupt (^c)... # onintr goodbail # # Set script variables... # set user1 = drs # home directory to be reset set user2 = drsast # where user1's files will be restored from set bupdir = drs_bup # user2's directory where backup is stored. # # Only user1 should use this script... # if(`whoami` != $user1) then echo $0": To be executed by user "$user1" only. Aborted..." exit(-1) endif # # Warn user of consequences! # clear echo ">>>>> WARNING WARNING WARNING WARNING WARNING WARNING <<<<<" echo " " echo "This will delete files in ~"$user1" and restore from ~"$user2/$bupdir echo " " echo -n "Are you sure you want to continue? [Y/N] " set reply = $< if ($reply != Y) then echo $0": Aborted..." exit (-1) endif # # Last chance to change mind... # @ n=10 while ($n > 0) clear echo "WARNING: "$n "seconds to deletion (^c to stop)" @ n -= 1 sleep 1 end # # If interrupted now, files may be damaged... # onintr badbail # # Change to ~$user1, measure disk usage, and then delete files... # cd ~$user1 set olduse = `bdf . | tail -1 | tr -s ' ' | cut -f3 -d' '` echo " " echo ">>> Deleting files in ~"$user1"..." rm -rf .* * # # Restore files from ~$user2/$bupdir to ~$user1 # echo " " echo ">>> Restoring files from ~"$user2/$bupdir" to ~"$user1"..." cd ~$user2/$bupdir ; tar cf - . | (cd ~$user1; tar xf -) # # Report on disk space... # set newuse = `bdf . | tail -1 | tr -s ' ' | cut -f3 -d' '` set avail = `bdf . | tail -1 | tr -s ' ' | cut -f4 -d' '` @ recov = $olduse - $newuse echo " " echo ">>> Disk space recovered: "$recov" kilobytes" echo ">>> Disk space available: "$avail" kilobytes" # # Notice to user... # echo " " echo ">>> To ensure your path, desktop session etc. are " echo ">>> the default, now log back into the "$user1" account." exit(1) goodbail: echo " " echo $0": No files were deleted." echo $0": Aborted..." exit(-1) badbail: echo " " echo $0": WARNING: Files may have been deleted." echo $0": Aborted..."