#!/bin/sh # #- bufile -- #- This application makes a backup copy of a file. #- # Usage: # bufile [-l] file # # The copy will named backup/file_YYYYMMDDHHMMSS, where the # suffix is the creation time. A local directory named backup # will be created if it does not already exist. # # With -l option, process will prompt for a log entry, which will be appended # to backup/file.log # # Copyright (c) 2011 Gordon D. Carrie # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # Please send feedback to dev0@trekix.net if [ $# -eq 1 ] then fl=$1 elif [ $# -eq 2 -a $1 = "-l" ] then fl=$2 log=backup/${fl}.log else echo Usage: $0 file exit 1 fi mkdir -p backup sfx=`date +"%Y%m%d%H%M%S"` fl_bu=backup/${fl}_$sfx cp $fl $fl_bu chmod 444 $fl_bu if test $log then touch $log printf "\n%s\n" $sfx >> $log echo "Enter log entry:" cat >> $log fi echo $fl_bu