Since today I have a very practical backup-function in my /etc/profile. I dont’t want to withhold it from you:
function backup () {
DATE=$(date +%Y-%m-%d-%H:%M)
if [ `echo $1 | grep "\."` ]
then
BU=$(echo $1 | sed -e "s/\(.*\)\(\..*$\)/\1-$DATE\2/g")
else
BU="$1-$DATE"
fi
if [ -e "$1" ] | [ ! -e "$BU" ]
then
cp $1 $BU
else
echo "$1: No such file or Directory"
fi
}
You can use this function by typing backup $filename. Then a copy of $filename will be created which is named in this style orginalname-date.ext.
Filed under Backup, Bash, Linux, Shell & no comments & no trackbacks
Trackback specific URI for this entry