-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy patharchive.sh
executable file
·43 lines (36 loc) · 1.1 KB
/
archive.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash -
#===============================================================================
#
# FILE: archive.sh
#
# USAGE: ./archive.sh filename target_path
#
# DESCRIPTION: Archive a single file to given directory.
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Dilawar Singh (), [email protected]
# ORGANIZATION: NCBS Bangalore
# CREATED: 07/02/2016 09:23:42 AM
# REVISION: ---
#===============================================================================
set -o nounset # Treat unset variables as an error
set -e
if [ $# -lt 2 ]; then
echo "USGAE: $0 filename destination"
exit
fi
FILE="$1"
DEST="$2"
mkdir -p ${DEST}
# First, append the timestamp and git-id to filename.
GITID=`git log --pretty=format:'%h' -n 1 || echo ""`
NOW=$(date +"%c" | tr ' :' '__' )
INPUTFILE=`basename $FILE`
EXTENSION="${INPUTFILE##*.}"
FILENAME="${INPUTFILE%.*}"
NEWNAME="${DEST}/${FILENAME}_${GITID}_${NOW}.${EXTENSION}"
echo "Archiving $FILE to $NEWNAME"
rsync -azv --progress $FILE $NEWNAME