#! /usr/bin/perl -w ### # # Backup the contents of a folder, perl-style # ### ### # Copyright (c) 2002 Regents of The University of Michigan. # All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose and without fee is hereby granted, # provided that the above copyright notice appears in all copies and # that both that copyright notice and this permission notice appear # in supporting documentation, and that the name of The University # of Michigan not be used in advertising or publicity pertaining to # distribution of the software without specific, written prior # permission. This software is supplied as is without expressed or # implied warranties of any kind. # # Research Systems Unix Group # The University of Michigan # c/o Wesley Craig # 4251 Plymouth Road B1F2, #2600 # Ann Arbor, MI 48105-2785 ### use strict; my ( $projectdir ) = "/Users/user/src/CurrentProject"; my ( $backupdir ) = "/Volumes/Storage/backups"; my ( $newbackupdir ) =`date | awk '{ print $3 "-" $2 "-" $6 "-" $4 "-backup" }'`; my ( $oldhandle ); # Turn on autoflush feature, to prevent buffering: $|++; $oldhandle = select( STDERR ); $|++; select( $oldhandle ); # Messages to stdout appear in the iHook window print "Preparing to backup $projectdir...\n"; # ...except messages beginning with a % sign. # This starts an indeterminate progress bar (barberpole): print "%BEGINPOLE\n"; unless( -e "$backupdir" ) { print "Creating backup archive directory...\n"; system( "mkdir '$backupdir'" ); if ( $? != 0 ) { # messages to stderr appear in the drawer. # This message, an error, is redirected to stderr # so it will appear in the drawer. print STDERR "Couldn't create $backupdir\n"; exit( 2 ); } } # Tell the user we're creating the directory print "Creating $backupdir/$newbackupdir...\n"; system( "mkdir '$backupdir/$newbackupdir'" ); if ( $? == 0 ) { # again, redirect error messages to stderr, and to the drawer. print STDERR "Couldn't create $backupdir/$newbackupdir\n"; } # start a determinate progress bar, while indicating # we've created the new backup dir print "%20\n"; # just for fun, change the background of the iHook window print "%BACKGROUND /Library/Images/mountains.png\n"; print "Clearing $projectdir\'s temporary space...\n"; system( "rm -rf '$projectdir/tmp'" ); # update the progress bar print "%40\n"; # update the message in the iHook window print "Backing up $projectdir...\n"; system( "ditto -rsrcFork '$projectdir' '$backupdir/$newbackupdir'" ); if ( $? == 0 ) { print "Backup of $projectdir failed.\n"; exit( 2 ); } # we're done, fill the progress bar and remove it from the screen print "%100\n"; # update the message in the iHook window print "Backup complete.\n"; # wait a second, then exit sleep( 1 ); exit( 0 );