-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup
executable file
·43 lines (40 loc) · 880 Bytes
/
backup
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/sh
ARGS=("$@")
DEST=""
while [[ $# -gt 0 ]]; do
opt="$1"
shift;
current_arg="$1"
case "$opt" in
"-d"|"--destination" ) DEST="$1"; shift;;
# * ) echo "ERROR: Invalid option: \""$opt"\"" >&2; exit 1;;
esac
done
if [ "$DEST" == "" ]
then
echo "Destination = ."
else
echo "Destination = $DEST"
fi
set -- "${ARGS[@]}"
for arg in "$@"
do
#echo "$arg"
if [[ (("$arg" != "-d")) && (("$arg" != "$DEST")) ]]
then
TIME=$(stat -f "%Sm" -t "%b %e %H_%M %G" $arg | awk '{print $3;}')
DATE=$(stat -f "%Sm" -t "%b %e %H_%M %G" $arg | awk '{print tolower($1$2);}')
YEAR=$(stat -f "%Sm" -t "%b %e %H_%M %G" $arg | awk '{print $4;}')
BFNAME="$TIME"
BFNAME+="_$DATE"
BFNAME+="_$YEAR"
BFNAME+="_$arg"
#echo "$BFNAME"
if [[ "$DEST" == "" ]]
then
/bin/cp -p -i "$arg" "$BFNAME"
else
/bin/cp -p -i "$arg" "$DEST/$BFNAME"
fi
fi
done