-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup
More file actions
executable file
·113 lines (106 loc) · 1.84 KB
/
backup
File metadata and controls
executable file
·113 lines (106 loc) · 1.84 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
OPTIND=1
inc_backup=0
verbose=0
ramdisk=0
ramdisk_path=""
target="/backup/"
source=$(pwd)
size=1024m
type=tmpfs
backupname=""
ramdisk_check ()
{
if mount | grep ${ramdisk_path%/*} > /dev/null
then
return 1
else
return 0
fi
}
while getopts ":h?ir:vt:s:S:t:" opt
do
case "$opt" in
i)
if [ $inc_backup -ne 0 ]
then
echo Duplicate Arguments.
exit 1
fi
inc_backup=1
;;
r)
if [ $ramdisk -ne 0 ]
then
echo Duplicate Arguments.
exit 1
fi
ramdisk=1
ramdisk_path=$OPTARG
;;
t)
if [ $(target) != "/backup/" ]
then
echo Duplicate Arguments.
exit 1
fi
target=$OPTARG
;;
s)
if [ $(source) != $(pwd) ]
then
echo Duplicate Arguments.
exit 1
fi
source_directory=$OPTARG
;;
S)
size=$OPTARG
;;
t)
type=$OPTARG
;;
:)
echo "Option $OPTARG requires an argument."
exit 2
;;
h|\?)
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
if [ $inc_backup -ne 0 ]
then
echo "Using incremental backup scheme."
fi
if [ $ramdisk -ne 0 ]
then
ramdisk_check
if [ $? -ne 1 ]
then
echo "Ramdisk not mounted"
input=""
while [ "$input" != "y" ] && [ "$input" != "n" ]
do
echo "Attempt to mount new ramdisk at $ramdisk_path?(y/n)"
read input
done
if [ "$input" == n ]
then
echo "Aborting backup."
exit 3
else
mount -t $type -o size=$size $type $ramdisk_path
if [ $? -ne 0 ]
then
echo "An error occured!"
exit 4
fi
echo "Ramdisk successfully created at $ramdisk_path."
fi
else
echo "Ramdisk is already mounted at $ramdisk_path. Continuing using this ramdisk."
fi
backupname=
fi