-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse-backup-args.sh
More file actions
144 lines (143 loc) · 4.78 KB
/
parse-backup-args.sh
File metadata and controls
144 lines (143 loc) · 4.78 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
# parse-backup-args.sh - CLI argument parsing for backup.sh
# Sourced by backup.sh - sets backup options from command line
# Requires: utils.sh, ui.sh (for validate_path, RED/NC, show_backup_help)
# Parse command line arguments (consumes $@ via shift)
while [[ $# -gt 0 ]]; do
case $1 in
--silent)
SILENT_MODE=true
shift
;;
--quick)
SILENT_MODE=true
QUICK_BACKUP=true
shift
;;
--incremental)
INCREMENTAL_BACKUP=true
DIFFERENTIAL_BACKUP=false
shift
;;
--differential)
DIFFERENTIAL_BACKUP=true
INCREMENTAL_BACKUP=false
shift
;;
--verify)
VERIFY_BACKUP=true
VERIFY_EXPLICITLY_SET=true
shift
;;
--no-verify)
VERIFY_BACKUP=false
VERIFY_EXPLICITLY_SET=true
shift
;;
--thorough-verify)
VERIFY_BACKUP=true
THOROUGH_VERIFY=true
VERIFY_EXPLICITLY_SET=true
shift
;;
--compression)
if [[ -n "$2" && "$2" =~ ^[1-9]$ ]]; then
COMPRESSION_LEVEL="$2"
shift 2
else
echo -e "${RED}Error: Compression argument requires a number between 1 and 9${NC}"
exit 1
fi
;;
--email)
if [[ -n "$2" && "$2" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
EMAIL_NOTIFICATION="$2"
shift 2
else
echo -e "${RED}Error: Email argument requires a valid email address${NC}"
exit 1
fi
;;
--cloud)
if [[ -n "$2" && "$2" =~ ^(aws|s3|do|spaces|digitalocean|dropbox|gdrive|google)$ ]]; then
CLOUD_PROVIDER="$2"
EXTERNAL_BACKUP=true
shift 2
else
echo -e "${RED}Error: Cloud provider must be one of: aws, s3, do, spaces, digitalocean, dropbox, gdrive, google${NC}"
exit 1
fi
;;
--external)
EXTERNAL_BACKUP=true
CLOUD_PROVIDER="${CLOUD_PROVIDER:-$DEFAULT_CLOUD_PROVIDER}"
shift
;;
--bandwidth)
if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then
BANDWIDTH_LIMIT="$2"
shift 2
else
echo -e "${RED}Error: Bandwidth argument requires a number in KB/s${NC}"
exit 1
fi
;;
--parallel)
if [[ -n "$2" && "$2" =~ ^[1-8]$ ]]; then
PARALLEL_THREADS="$2"
shift 2
else
echo -e "${RED}Error: Parallel threads argument requires a number between 1 and 8${NC}"
exit 1
fi
;;
--dry-run)
DRY_RUN=true
shift
;;
--destination|--dest|-d)
if [[ -n "$2" && "$2" != --* ]]; then
_dir="${2/#\~/$HOME}"
CUSTOM_BACKUP_DIR=$(validate_path "$_dir" "dir") || { echo -e "${RED}Error: Invalid destination path${NC}"; exit 1; }
shift 2
else
echo -e "${RED}Error: Destination argument requires a directory path${NC}"
exit 1
fi
;;
--sources)
if [[ -n "$2" ]]; then
IFS=',' read -ra custom_dirs <<< "$2"
for _dir in "${custom_dirs[@]}"; do
_dir=$(echo "$_dir" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
_dir="${_dir/#\~/$HOME}"
_validated=$(validate_path "$_dir" "dir") || { echo -e "${RED}Error: Invalid source path: $_dir${NC}"; exit 1; }
CUSTOM_SOURCE_DIRS+=("$_validated")
done
shift 2
else
echo -e "${RED}Error: --sources requires a comma-separated list of directories${NC}"
exit 1
fi
;;
--source|-s)
if [[ -n "$2" && "$2" != --* ]]; then
_dir="${2/#\~/$HOME}"
_validated=$(validate_path "$_dir" "dir") || { echo -e "${RED}Error: Invalid source path${NC}"; exit 1; }
CUSTOM_SOURCE_DIRS+=("$_validated")
shift 2
else
echo -e "${RED}Error: Source argument requires a directory path${NC}"
exit 1
fi
;;
-h|--help)
show_backup_help
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
echo "Use --help to see available options"
exit 1
;;
esac
done