-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.sh
343 lines (300 loc) · 12.4 KB
/
ui.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#!/bin/bash
# ui.sh - User interface functions for backup-webdev
# This file contains UI-related functions used across scripts
# Source the shared utilities
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/utils.sh"
# Print dashboard header
print_dashboard_header() {
printf "+------------------------------------------------------------------------------+\n"
printf "| %-76s |\n" "BACKUP DASHBOARD - $(date '+%Y-%m-%d %H:%M:%S')"
printf "+------------------------------------------------------------------------------+\n"
printf "| %-40s | %-10s | %-20s |\n" "PROJECT NAME" "SIZE" "STATUS"
printf "+------------------------------------------------------------------------------+\n"
}
# Print dashboard row
print_dashboard_row() {
local project=$1
local size=$2
local status=$3
printf "| %-40s | %-10s | %-20s |\n" "$project" "$size" "$status"
}
# Print dashboard footer
print_dashboard_footer() {
printf "+------------------------------------------------------------------------------+\n"
printf "| %-40s | %-10s | %-20s |\n" "TOTAL" "$1" "COMPLETED"
printf "+------------------------------------------------------------------------------+\n"
}
# Show help text for backup script
show_backup_help() {
echo "WebDev Backup Tool"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --silent Run in silent mode (no user interaction, for cron jobs)"
echo " --incremental Only backup files changed since last backup"
echo " --differential Only backup files changed since last full backup"
echo " --verify Verify backup integrity after completion"
echo " --thorough-verify Perform comprehensive integrity verification (includes extraction tests)"
echo " --compression LEVEL Set compression level (1-9, default: 6)"
echo " --email EMAIL Send notification email to specified address"
echo " --external Use external backup (cloud storage)"
echo " --cloud PROVIDER Upload backup to cloud storage (aws, do, dropbox, gdrive)"
echo " --bandwidth LIMIT Limit bandwidth usage in KB/s"
echo " --parallel NUM Use parallel compression with NUM threads"
echo " --dry-run Simulate backup without making any changes"
echo " -d, --dest, --destination DIR Set custom backup destination directory"
echo " -s, --source DIR Set custom source directory to backup"
echo " -h, --help Show this help message"
echo ""
echo "Default values:"
echo " Source directory: $DEFAULT_SOURCE_DIR"
echo " Backup destination: $DEFAULT_BACKUP_DIR"
echo ""
echo "Examples:"
echo " $0 # Run interactive backup with default paths"
echo " $0 --silent # Run silent backup with default paths"
echo " $0 --incremental # Only backup changed files"
echo " $0 --verify # Verify backup integrity"
echo " $0 --thorough-verify # Complete verification with extraction test"
echo " $0 --compression 9 # Use maximum compression"
echo " $0 -d /path/to/backup # Custom destination directory"
echo " $0 -s /path/to/source # Custom source directory"
echo " $0 --email [email protected] # Send email notification"
echo " $0 --parallel 4 # Use 4 threads for compression"
echo ""
exit 0
}
# Show help text for cleanup script
show_cleanup_help() {
echo "WebDev Backup Cleanup Tool"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -b, --backup-logs Backup logs before removing them"
echo " -a, --all-logs Remove all logs (default: keeps last 5 runs)"
echo " -d, --days DAYS Remove logs older than DAYS days"
echo " -s, --source DIR Use custom source directory"
echo " -t, --target DIR Use custom backup target directory"
echo " -y, --yes Skip confirmation prompts"
echo " --dry-run Show what would be done without doing it"
echo " -h, --help Show this help message"
echo ""
echo "Default values:"
echo " Source directory: $DEFAULT_SOURCE_DIR"
echo " Backup destination: $DEFAULT_BACKUP_DIR"
echo ""
echo "Examples:"
echo " $0 # Standard cleanup (keeps recent logs)"
echo " $0 -a # Remove all logs"
echo " $0 -d 30 # Remove logs older than 30 days"
echo " $0 -b -a # Backup all logs before removing them"
echo " $0 -t /mnt/backups # Use custom backup target"
echo ""
exit 0
}
# Show help text for restore script
show_restore_help() {
echo "WebDev Backup Restore Tool"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --list List available backups"
echo " --backup-date DATE Restore from specific backup date (YYYY-MM-DD_HH-MM-SS)"
echo " --latest Restore from latest backup (default)"
echo " --project PROJECT Restore specific project only"
echo " --file FILE Restore specific file only"
echo " --test Test restore without actually extracting files"
echo " -d, --dest DIR Set custom restore destination directory"
echo " -s, --source DIR Set custom backup source directory"
echo " -y, --yes Skip confirmation prompts"
echo " --dry-run Show what would be done without doing it"
echo " -h, --help Show this help message"
echo ""
echo "Default values:"
echo " Backup source: $DEFAULT_BACKUP_DIR"
echo " Restore destination: $DEFAULT_SOURCE_DIR"
echo ""
echo "Examples:"
echo " $0 --list # List available backups"
echo " $0 # Restore latest backup interactively"
echo " $0 --backup-date 2025-03-15_14-30-00 # Restore specific backup"
echo " $0 --project myproject # Restore only myproject"
echo " $0 --project myproject --file src/index.js # Restore specific file"
echo " $0 --test # Test restore without extracting files"
echo ""
exit 0
}
# Show help text for test script
show_test_help() {
echo "WebDev Backup Test Tool"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -s, --source DIR Set custom source directory to test with"
echo " -h, --help Show this help message"
echo ""
echo "Default values:"
echo " Source directory: $DEFAULT_SOURCE_DIR"
echo ""
echo "This script tests the backup functionality without actually transferring files."
echo "It runs a series of tests to verify that the backup process works correctly."
echo ""
exit 0
}
# Interactive project selection
select_projects() {
local projects=("$@")
local selected=()
local excluded=()
echo "Projects to backup:"
for ((i=0; i<${#projects[@]}; i++)); do
echo "[$i] ${projects[$i]}"
done
echo -e "\nTo exclude projects from backup, enter their numbers separated by spaces."
echo "Press Enter to backup all projects."
read -p "> " response
# Process all projects
for ((i=0; i<${#projects[@]}; i++)); do
if [[ "$response" =~ (^|[[:space:]])$i($|[[:space:]]) ]]; then
# Project is excluded
excluded+=("${projects[$i]}")
else
# Project is selected
selected+=("${projects[$i]}")
fi
done
# Report selection
if [ ${#excluded[@]} -gt 0 ]; then
echo -e "\nExcluded projects:"
for project in "${excluded[@]}"; do
echo " - $project"
done
fi
echo -e "\nSelected projects (${#selected[@]}):"
for project in "${selected[@]}"; do
echo " + $project"
done
# Return selected projects
echo "${selected[@]}"
}
# Display backup summary
display_backup_summary() {
local successful=$1
local failed=$2
local src_size=$3
local backup_size=$4
local location=$5
local is_external=${6:-false}
local cloud_provider=${7:-}
local start_time=${8:-}
local end_time=${9:-}
local duration_seconds=${10:-}
local duration_formatted=${11:-}
local formatted_src_size=$(format_size "$src_size")
local formatted_backup_size=$(format_size "$backup_size")
echo -e "\n${CYAN}===== Backup Summary =====${NC}"
echo "- Projects backed up: $successful"
if [ "$failed" -gt 0 ]; then
echo -e "- Projects failed: ${RED}$failed${NC}"
else
echo "- Projects failed: $failed"
fi
echo "- Source data size: $formatted_src_size"
echo "- Compressed size: $formatted_backup_size"
if [ "$src_size" -gt 0 ] && [ "$backup_size" -gt 0 ]; then
echo "- Overall compression ratio: $(awk "BEGIN {printf \"%.1f\", ($src_size/$backup_size)}")x"
fi
echo "- Backup location: $location"
# Add storage type information
if [ "$is_external" = true ]; then
echo -e "- Storage type: ${CYAN}EXTERNAL${NC} (${cloud_provider} cloud provider)"
else
echo -e "- Storage type: ${GREEN}INTERNAL${NC} (local storage)"
fi
# Add time information
if [ -n "$start_time" ] && [ -n "$end_time" ]; then
echo "- Started at: $start_time"
echo "- Completed at: $end_time"
if [ -n "$duration_formatted" ]; then
echo "- Total duration: $duration_formatted ($duration_seconds seconds)"
fi
else
# Add timestamp for backward compatibility
echo "- Completed at: $(date '+%Y-%m-%d %H:%M:%S')"
fi
}
# Show advanced options menu
show_advanced_options() {
echo -e "\n${CYAN}===== Advanced Backup Options =====${NC}"
echo "1) Backup Type"
echo " - [F]ull: Back up all files (default)"
echo " - [I]ncremental: Only back up files changed since last backup"
echo " - [D]ifferential: Only back up files changed since last full backup"
echo "2) Compression Level (1-9)"
echo " - 1: Fastest, lowest compression"
echo " - 6: Balanced (default)"
echo " - 9: Slowest, highest compression"
echo "3) Email Notification"
echo " - Enter email address to receive backup reports"
echo "4) Verification Options"
echo " - [Y]es: Verify backup integrity after completion"
echo " - [N]o: Skip verification (default)"
echo "5) Cloud Storage Integration"
echo " - [N]one: Local backup only (default)"
echo " - [DO]: Upload to DigitalOcean Spaces (recommended)"
echo " - [A]WS: Upload to Amazon S3"
echo " - [G]Drive: Upload to Google Drive"
echo " - [D]ropbox: Upload to Dropbox"
echo "6) Performance Options"
echo " - Parallel threads (1-8, default: 1)"
echo " - Bandwidth limit (KB/s, 0=unlimited)"
echo "7) Save as Default Configuration"
echo "8) Start Backup with Selected Options"
echo "0) Start Backup with Default Options"
read -p "Select option (0-8): " option
# Handle option selection
case "$option" in
0)
echo "Starting backup with default options..."
return 0
;;
1)
read -p "Select backup type (F/I/D): " backup_type
# Process backup type selection
;;
# Additional options handling would go here
*)
echo "Invalid option. Using default settings."
return 0
;;
esac
}
# Display restore options
display_restore_options() {
local backups=("$@")
echo -e "\n${CYAN}===== Available Backups =====${NC}"
if [ ${#backups[@]} -eq 0 ]; then
echo "No backups found."
return 1
fi
for ((i=0; i<${#backups[@]}; i++)); do
echo "[$i] ${backups[$i]}"
done
echo -e "\nEnter the number of the backup to restore, or press Enter for latest:"
read -p "> " selection
if [[ -z "$selection" ]]; then
# Default to latest backup (first in the list)
echo "${backups[0]}"
elif [[ "$selection" =~ ^[0-9]+$ ]] && [ "$selection" -lt "${#backups[@]}" ]; then
echo "${backups[$selection]}"
else
echo "Invalid selection."
return 1
fi
}
# End of UI functions