-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbackup
More file actions
executable file
·57 lines (50 loc) · 936 Bytes
/
backup
File metadata and controls
executable file
·57 lines (50 loc) · 936 Bytes
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
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
###############################
#
# Create easily backups of
# files and directories
#
# written by Martin Scharm
# see http://binfalse.de
#
###############################
if [ $# -ne 1 ]
then
echo "Usage: `basename $0` [FILE/DIR TO BACKUP]"
exit 1
fi
if [ ! -r $1 ]
then
echo "$1 is not readable"
exit 1
fi
DATE=`date +"%F_%H-%M-%S"`
BACKUP=${1%/}_$DATE
function do_not_overwrite
{
if [ -e $1 ]
then
out="$1 exists, please try again later..."
for i in $(seq ${#out}); do echo -n 'v'; done; echo
echo "$out"
for i in $(seq ${#out}); do echo -n '^'; done; echo
exit 1
fi
}
if [ ! -d $1 ]
then
do_not_overwrite $BACKUP
cp $1 $BACKUP
else
BACKUP=$BACKUP.tgz
do_not_overwrite $BACKUP
tar czf $BACKUP $1
fi
if [ $? -eq 0 ]
then
echo "DONE! BackUp to File: $BACKUP"
exit 0
else
echo "FAILED!!"
exit 1
fi