I keep re-writing the following script for cygwin/bash because I find myself working on proof of concept code, and new environments without source control systems in place.
I am posting it for two reasons: I will need it again and it is easier to remember cygwin/bash from my own examples.
The following script versions all new files in a directory:
#!/usr/bin/bash # The directory we are backing up to backupdir="/cygdrive/c/backup"; # Get the directory that will be backed up dir=$1; # Give user information echo "Versioning files in: $dir"; echo "Current backup in: $backupdir"; # If datestamp.file is not found then # this is a new directory, no changes found if [ ! -f $dir/datestamp.file ] then echo "Initial backup request"; echo '.' > $dir/datestamp.file; else datestring=`date +%D-%H-%M | sed 's/\//-/g'` #echo "datestring: $datestring"; for f in `find $dir -name "*" -newer $dir/datestamp.file`; do if [ $f = "." ]; then echo "Ignoring: $f"; else #echo "Currently processing: $f"; f2=${f/\./\/$backupdir}; if [ -d $f ] then echo "Creating directory: $backupdir/$f2"; mkdir -p $backupdir/$f2; else f2=$f-${datestring}; f2=${f2/\\./\/$backupdir}; echo "Versioning file to: $backupdir/$f2"; cp $f $backupdir/$f2; fi fi done fi |
0 comments:
Post a Comment