Skip to content

Commit 9641661

Browse files
formatting edits to stats & estimation improvements
1 parent 5308710 commit 9641661

10 files changed

Lines changed: 160 additions & 78 deletions

scripts/bacchus-restore.sh

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ source "scripts/include/common/duration_readable.sh" || { echo "scripts/include/
4040
source "scripts/include/common/load_persistence.sh" || { echo "scripts/include/common/load_persistence.sh not found"; exit 1; }
4141
source "scripts/include/restore/completion_stats.sh" || { echo "scripts/include/restore/completion_stats.sh not found"; exit 1; }
4242
source "scripts/include/restore/process_volume.sh" || { echo "scripts/include/restore/process_volume.sh not found"; exit 1; }
43+
source "scripts/include/restore/print_estimate.sh" || { echo "scripts/include/restore/print_estimate.sh not found"; exit 1; }
44+
source "scripts/include/restore/compute_end.sh" || { echo "scripts/include/restore/compute_end.sh not found"; exit 1; }
4345

4446
BCS_TMPFILE=$(mktemp -u /tmp/baccus-XXXXXX)
4547
trap Cleanup EXIT
4648

47-
source=$(find "$BCS_SOURCE" -name "${BCS_BASENAME}".tar* | sort | tail -1)
49+
bcs_source="$BCS_SOURCE"
50+
source=$(find "$bcs_source" -name "${BCS_BASENAME}".tar* | sort | tail -1)
4851

4952
if [[ "$source" == *".gz"* ]]; then
5053
BCS_COMPRESS="on"
@@ -59,21 +62,11 @@ fi
5962
# Determine max uncompressed size of individual archive volume
6063
ramdisk_size_tmpdir="$BCS_TMPFILE".ramdisk_size
6164
mkdir "$ramdisk_size_tmpdir"
62-
source="$BCS_SOURCE"/"$BCS_BASENAME".tar
65+
source="$bcs_source"/"$BCS_BASENAME".tar
6366
Process_Volume "$BCS_BASENAME".tar "$ramdisk_size_tmpdir" "$ramdisk_size_tmpdir"
6467
BCS_VOLUMESIZE=$dest_actual_size
6568
rm -rf "$ramdisk_size_tmpdir"
6669

67-
# Determine uncompressed size of last archive volume
68-
ramdisk_size_tmpdir="$BCS_TMPFILE".ramdisk_size
69-
mkdir "$ramdisk_size_tmpdir"
70-
source=$(find "$BCS_SOURCE" -name "${BCS_BASENAME}".tar* | sort -V | tail -1)
71-
source="${source//.gpg/}"
72-
source="${source//.gz/}"
73-
Process_Volume "$BCS_BASENAME".tar "$ramdisk_size_tmpdir" "$ramdisk_size_tmpdir"
74-
bcs_volumesize_end=$dest_actual_size
75-
rm -rf "$ramdisk_size_tmpdir"
76-
7770
# Setup ramdisk if needed
7871
if [ "$BCS_COMPRESS" == "off" ] && [ -z "$BCS_PASSWORD" ]; then
7972
BCS_TARDIR="$BCS_DEST"
@@ -95,30 +88,36 @@ elif [ "$BCS_RAMDISK" == "on" ]; then
9588
fi
9689

9790
# Estimate total restore size and number of archive volumes
98-
total_volumes=$(find "$BCS_SOURCE" -name "${BCS_BASENAME}".tar* | wc -l)
99-
source_size_total=$(du -sk --apparent-size "$BCS_SOURCE" | awk '{print $1}')
91+
archive_volumes=$(find "$bcs_source" -name "${BCS_BASENAME}".tar* | wc -l)
92+
source_size_total=$(du -sk --apparent-size "$bcs_source" | awk '{print $1}')
10093

10194
if [ "$BCS_ESTIMATE" == "on" ]; then
102-
printf '\nEstimated number of volumes: %s\n' "$total_volumes"
103-
printf "Estimated size of source: %'.0fk\n" "$source_size_total"
104-
total_dest_size=$(( (total_volumes * BCS_VOLUMESIZE) + bcs_volumesize_end ))
105-
printf "Estimated size of restore: %'.0fk\n" "$total_dest_size"
106-
comp_ratio=$(( 100 - ( (source_size_total * 100) / total_dest_size) ))
107-
printf "Estimated compression ratio: %s%%\n" "$comp_ratio"
95+
Compute_End
96+
Print_Estimate
10897
fi
10998
printf '\n'
11099

111100
# Process first (possibly only) backup volume
112-
echo "$BCS_BASENAME".tar
101+
archive_max_name=$(( ${#BCS_BASENAME} + ${#archive_volumes} + 5 ))
102+
archive_max_num=$(( ${#archive_volumes} + 1 ))
103+
104+
printf "\
105+
%-${archive_max_name}s \
106+
%${archive_max_num}s \
107+
%4s\n"\
108+
"${BCS_BASENAME}.tar" \
109+
"/$archive_volumes" \
110+
"$(( 100 / archive_volumes ))%"
111+
113112
timestamp=$(date +%s)
114113

115-
source="$BCS_SOURCE"/"$BCS_BASENAME".tar
114+
source="$bcs_source"/"$BCS_BASENAME".tar
116115
Process_Volume "$BCS_BASENAME".tar "$BCS_DECRYPTDIR" "$BCS_COMPRESDIR"
117116

118117
# Populate external data structure with starting values
119118
export BCS_DATAFILE="$BCS_TMPFILE".runtime
120-
runtime_data=$(jo bcs_source="$BCS_SOURCE" \
121-
archive_volumes=$total_volumes \
119+
runtime_data=$(jo bcs_source="$bcs_source" \
120+
archive_volumes=$archive_volumes \
122121
start_timestamp=$timestamp \
123122
start_timestamp_running=0 \
124123
incremental_timestamp=$timestamp \

scripts/include/backup/bacchus-backup-new-volume.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,28 @@ case "$TAR_SUBCOMMAND" in
4545
esac
4646

4747
# Ensure sufficient available free space on target for this archive volume
48+
oldpath=$bcs_dest
4849
while true; do
4950
availablespace=$(df -kP "$bcs_dest" | awk '{print $4}' | tail -1)
5051
lowspace="$(( BCS_VOLUMESIZE * BCS_LOWDISKSPACE ))"
5152

5253
if [ "$availablespace" -lt "$lowspace" ]; then
5354
stop_timestamp=$(date +%s)
5455
printf "\nLOW AVAILABLE SPACE on %s (%sk < %sk)\n" "$bcs_dest" "$(printf "%'.0f" "$availablespace")" "$(printf "%'.0f" "$lowspace")"
55-
printf "Either free-up space or swap out storage device and press enter,\n"
56-
printf "Or enter a new destination path and press enter\n"
56+
printf "Either free-up space, or swap out the storage device,\n"
57+
printf "or enter a new destination path here.\n"
58+
printf "Press enter when ready\n"
5759
read -r newpath
5860
printf "\n"
5961
if [ -n "$newpath" ]; then
60-
dest_size_running=$(( dest_size_running + $(du -c "$bcs_dest"/"$BCS_BASENAME"* | tail -1 | awk '{ print $1 }') ))
6162
bcs_dest="$newpath"
6263
fi
6364
else
6465
if [ -n "$newpath" ]; then
66+
dest_size_running=$(( dest_size_running + $(du -c --apparent-size "$oldpath" | tail -1 | awk '{ print $1 }') ))
67+
6568
unset newpath
69+
6670
resume_timestamp=$(date +%s)
6771
start_timestamp_running=$(( start_timestamp_running + (resume_timestamp - stop_timestamp) ))
6872
incremental_timestamp_running=$(( incremental_timestamp_running + (resume_timestamp - stop_timestamp) ))
@@ -81,9 +85,8 @@ fi
8185
source="$tararchivedir"/"$TAR_ARCHIVE"
8286
destination="$bcs_dest"/"$TAR_ARCHIVE"
8387

84-
archive_source_size=$(stat -c %s "$source")
85-
archive_source_size_scaled=$(( archive_source_size / 1024 ))
86-
source_size_running=$(( source_size_running + archive_source_size_scaled ))
88+
archive_source_size=$(du -sk --apparent-size "$source" | awk '{print $1}')
89+
source_size_running=$(( source_size_running + archive_source_size ))
8790

8891
incremental_timestamp=$(date +%s)
8992

scripts/include/backup/completion_stats.sh

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,49 @@ function Completion_Stats()
44
# Compute & output completion statistics
55
#
66
# Make sure these global variable have values before calling this function
7-
# BCS_BASENAME
87
# TAR_VOLUME
98
#
109
# bcs_dest
1110
# dest_size_running
11+
# dest_size_running
1212
# source_size_running
13+
# source_size_total
1314
# start_timestamp
1415
# start_timestamp_running
1516

16-
local completion_timestamp
17-
local completion_time
1817
local avg_time
19-
local source_size_running_text
20-
local dest_size
21-
local dest_size_text
2218
local comp_ratio
19+
local completion_time
20+
local completion_timestamp
21+
local dest_size_running_text
22+
local source_size_total_text
23+
local tar_overhead
24+
local tar_overhead_text
2325

2426
completion_timestamp=$(date +%s)
2527
completion_time=$(( completion_timestamp - start_timestamp - start_timestamp_running ))
2628
avg_time=$(( (completion_time / (TAR_VOLUME - 1) ) ))
2729

28-
source_size_running_text=$(printf "%'.0f" "$source_size_running")
30+
source_size_total_text=$(printf "%'.0f" "$source_size_total")
31+
32+
tar_overhead=$(( source_size_running - source_size_total ))
33+
tar_overhead_text=$(printf "%'.0f" "$tar_overhead")
2934

30-
dest_size=$(( dest_size_running + $(du -c "$bcs_dest"/"$BCS_BASENAME"* | tail -1 | awk '{ print $1 }') ))
31-
dest_size_text=$(printf "%'.0f" "$dest_size")
35+
dest_size_running=$(( dest_size_running + $(du -c --apparent-size "$bcs_dest" | tail -1 | awk '{ print $1 }') ))
36+
dest_size_running_text=$(printf "%'.0f" "$dest_size_running")
3237

33-
comp_ratio=$(( 100 - ( (dest_size * 100) / source_size_running) ))
38+
comp_ratio=$(( 100 - ( (dest_size_running * 100) / source_size_total) ))
3439

3540
printf '\nBACKUP OPERATION COMPLETE\n'
3641
printf 'Total runtime: %s\n' "$(Duration_Readable $completion_time)"
3742
printf 'Average time per archive file: %s\n' "$(Duration_Readable $avg_time)"
3843
printf 'Number of archive files: %s\n' "$(( TAR_VOLUME - 1 ))"
39-
printf 'Total size of backup: %sk\n' "$source_size_running_text"
44+
printf 'Tar overhead: %sk\n' "$tar_overhead_text"
45+
printf 'Total size of backup: %sk\n' "$source_size_total_text"
4046
if [ "$dest_size_running" -ne 0 ]; then
41-
printf 'Total size of destinations: %sk\n' "$dest_size_text"
47+
printf 'Total size of destinations: %sk\n' "$dest_size_running_text"
4248
else
43-
printf 'Total size of destination: %sk\n' "$dest_size_text"
49+
printf 'Total size of destination: %sk\n' "$dest_size_running_text"
4450
fi
4551
printf 'Overall compression ratio: %s%%\n' "$comp_ratio"
4652
}

scripts/include/backup/incremental_stats.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function Incremental_Stats()
6060
incremental_time=$(( timestamp - incremental_timestamp - incremental_timestamp_running ))
6161

6262
if compgen -G "${bcs_dest}/${BCS_BASENAME}*" > /dev/null; then
63-
dest_size=$(( dest_size_running + $(du -c "${bcs_dest}/${BCS_BASENAME}"* | tail -1 | awk '{ print $1 }') ))
63+
dest_size=$(( dest_size_running + $(du -c --apparent-size "$bcs_dest" | tail -1 | awk '{ print $1 }') ))
6464
else
6565
dest_size=$dest_size_running
6666
fi

scripts/include/restore/bacchus-restore-new-volume.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ source "scripts/include/common/duration_readable.sh" || { echo "scripts/include
2727
source "scripts/include/common/load_persistence.sh" || { echo "scripts/include/common/load_persistence.sh not found"; exit 1; }
2828
source "scripts/include/restore/incremental_stats.sh" || { echo "scripts/include/restore/incremental_stats.sh not found"; exit 1; }
2929
source "scripts/include/restore/process_volume.sh" || { echo "scripts/include/restore/process_volume.sh not found"; exit 1; }
30+
source "scripts/include/restore/print_estimate.sh" || { echo "scripts/include/restore/print_estimate.sh not found"; exit 1; }
31+
source "scripts/include/restore/compute_end.sh" || { echo "scripts/include/restore/compute_end.sh not found"; exit 1; }
3032

3133
# Pull current runtime data from persistence file
3234
Load_Persistence
@@ -52,8 +54,9 @@ while true; do
5254
stop_timestamp=$(date +%s)
5355
printf "\nArchive volume: %s\n" "$(basename "$source")"
5456
printf "NOT FOUND in: %s\n" "$bcs_source"
55-
printf "Either place this file in the source directory and press enter\n"
56-
printf "Or enter a new source path and press enter\n"
57+
printf "Either place this file in the source directory,\n"
58+
printf "or enter a new source path here.\n"
59+
printf "Press enter when ready\n"
5760
read newpath
5861
printf "\n"
5962
if [ -n "$newpath" ]; then
@@ -62,15 +65,23 @@ while true; do
6265
else
6366
if [ -n "$newpath" ]; then
6467
unset newpath
65-
resume_timestamp=$(date +%s)
66-
start_timestamp_running=$(( start_timestamp_running + (resume_timestamp - stop_timestamp) ))
67-
incremental_timestamp_running=$(( incremental_timestamp_running + (resume_timestamp - stop_timestamp) ))
6868

6969
new_source_size=$(du -sk --apparent-size "$bcs_source" | awk '{print $1}')
7070
source_size_total=$(( source_size_total + new_source_size ))
7171

7272
new_volumes=$(find "$bcs_source" -name "${BCS_BASENAME}".tar* | wc -l)
7373
archive_volumes=$(( archive_volumes + new_volumes ))
74+
75+
if [ "$BCS_ESTIMATE" == "on" ]; then
76+
printf "ESTIMATE UPDATED"
77+
Compute_End
78+
Print_Estimate
79+
printf '\n'
80+
fi
81+
82+
resume_timestamp=$(date +%s)
83+
start_timestamp_running=$(( start_timestamp_running + (resume_timestamp - stop_timestamp) ))
84+
incremental_timestamp_running=$(( incremental_timestamp_running + (resume_timestamp - stop_timestamp) ))
7485
fi
7586
break
7687
fi

scripts/include/restore/completion_stats.sh

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,45 @@ function Completion_Stats()
44
# Compute & output completion statistics
55
#
66
# Make sure these global variable have values before calling this function
7+
#
8+
# BCS_DEST
9+
#
710
# archive_volumes
811
# dest_size_running
9-
# source_size_running
12+
# source_size_total
1013
# start_timestamp
1114
# start_timestamp_running
1215

1316
local avg_time
1417
local comp_ratio
1518
local completion_time
1619
local completion_timestamp
17-
local dest_size_running_text
18-
local source_size_running_text
20+
local dest_size
21+
local dest_size_text
22+
local source_size_total_text
23+
local tar_overhead
24+
local tar_overhead_text
1925

2026
completion_timestamp=$(date +%s)
2127
completion_time=$(( completion_timestamp - start_timestamp - start_timestamp_running ))
2228
avg_time=$(( (completion_time / archive_volumes) ))
2329

24-
source_size_running_text=$(printf "%'.0f" "$source_size_running")
25-
dest_size_running_text=$(printf "%'.0f" "$dest_size_running")
30+
source_size_total_text=$(printf "%'.0f" "$source_size_total")
31+
32+
dest_size=$(du -sk --apparent-size "$BCS_DEST" | awk '{print $1}')
33+
dest_size_text=$(printf "%'.0f" "$dest_size")
34+
35+
tar_overhead=$(( dest_size_running - dest_size ))
36+
tar_overhead_text=$(printf "%'.0f" "$tar_overhead")
2637

27-
comp_ratio=$(( 100 - ( (source_size_running * 100) / dest_size_running) ))
38+
comp_ratio=$(( 100 - ( (source_size_total * 100) / dest_size) ))
2839

2940
printf '\nRESTORE OPERATION COMPLETE\n'
3041
printf 'Total runtime: %s\n' "$(Duration_Readable $completion_time)"
3142
printf 'Average time per archive file: %s\n' "$(Duration_Readable $avg_time)"
3243
printf 'Number of archive files: %s\n' "$archive_volumes"
33-
printf 'Total size of source: %sk\n' "$source_size_running_text"
34-
printf 'Total size of restore: %sk\n' "$dest_size_running_text"
44+
printf 'Tar overhead: %sk\n' "$tar_overhead_text"
45+
printf 'Total size of source: %sk\n' "$source_size_total_text"
46+
printf 'Total size of restore: %sk\n' "$dest_size_text"
3547
printf 'Overall compression ratio: %s%%\n' "$comp_ratio"
3648
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
function Compute_End()
3+
{
4+
# Determine actual size of last archive volume at a given location
5+
#
6+
# Make sure these global variable have values before calling this function
7+
# BCS_BASENAME
8+
# BCS_TMPFILE
9+
#
10+
# bcs_source
11+
# dest_actual_size
12+
#
13+
# These variables are set in this function as globals and can
14+
# be accessed by the caller after completion
15+
#
16+
# bcs_volumesize_end
17+
18+
local ramdisk_size_tmpdir
19+
local source
20+
21+
# Determine uncompressed size of last archive volume
22+
ramdisk_size_tmpdir="$BCS_TMPFILE".ramdisk_size
23+
mkdir "$ramdisk_size_tmpdir"
24+
source=$(find "$bcs_source" -name "${BCS_BASENAME}".tar* | sort -V | tail -1)
25+
source="${source//.gpg/}"
26+
source="${source//.gz/}"
27+
Process_Volume "$BCS_BASENAME".tar "$ramdisk_size_tmpdir" "$ramdisk_size_tmpdir"
28+
bcs_volumesize_end=$dest_actual_size
29+
rm -rf "$ramdisk_size_tmpdir"
30+
}

0 commit comments

Comments
 (0)