Backup of files in the directory.

I was working on some scripts and the changes that I was making in the scripts was very dynamic, which I did want to keep backing up in the version control system. But for the peace of my mind, I wanted to keep a copy of the scripts, whenever it was in working state.

Since I had multiple files, so it would make more sense to have a script that could copy all the files in the current directory to “old” directory without over-writing the existing files. So, I wrote a script that would postfix the files with a number. With this approach, finally what I had was the following:

#!/bin/bash -
#          FILE:
#         USAGE:  ./
#   DESCRIPTION:  Backup all the current files.
#       OPTIONS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: Amit Agarwal (aka),
#       COMPANY:
#       CREATED: 08/19/2011 02:43:32 PM IST
#      REVISION:  ---

count=$(cat old/count)
if [[ ! -f old/count ]]
  count=$(ls -1 old |sed 's/.*\.//'|grep -vi "[a-z]"|sort|tail -1)
echo $count >old/count
[[ ! -d old ]] && mkdir old
for i in *
	[[ -f $i ]] && cp $i old/${i%%.*}.$count
echo "Backed up to $count"
Enhanced by Zemanta

This site uses Akismet to reduce spam. Learn how your comment data is processed.