Skip to content

Commit 53b6efb

Browse files
refactor restore for separate process volume function file
1 parent bb46582 commit 53b6efb

3 files changed

Lines changed: 84 additions & 95 deletions

File tree

scripts/bacchus-restore-new-volume.sh

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
source "scripts/include/common/duration_readable.sh" || { echo "scripts/include/common/duration_readable.sh not found"; exit 1; }
2121
source "scripts/include/common/load_persistence.sh" || { echo "scripts/include/common/load_persistence.sh not found"; exit 1; }
2222
source "scripts/include/restore/incremental_stats.sh" || { echo "scripts/include/restore/incremental_stats.sh not found"; exit 1; }
23+
source "scripts/include/restore/process_volume.sh" || { echo "scripts/include/restore/process_volume.sh not found"; exit 1; }
2324

2425
# Pull current runtime data from persistence file
2526
Load_Persistence
@@ -68,32 +69,8 @@ else
6869
fi
6970

7071
last_timestamp="$(date +%s)"
71-
72-
source_actual=$(stat -c %s "$source")
73-
source_actual=$(( source_actual / 1024 ))
74-
75-
if [ -n "$BCS_PASSWORD" ]; then
76-
if [ "$BCS_COMPRESS" == "on" ]; then
77-
destination="$BCS_DECRYPTDIR"/"$filename".gz
78-
else
79-
destination="$BCS_DECRYPTDIR"/"$filename"
80-
fi
81-
echo "$BCS_PASSWORD" | gpg -qd --batch --cipher-algo AES256 --compress-algo none --passphrase-fd 0 --no-mdc-warning -o "$destination" "$source"
82-
source="$destination"
83-
fi
84-
85-
if [ "$BCS_COMPRESS" == "on" ]; then
86-
destination="$BCS_COMPRESDIR"/"$filename"
87-
pigz -9cd "$source" > "$destination"
88-
#gzip -9cd "$source" > "$destination"
89-
if [ -n "$BCS_PASSWORD" ]; then
90-
rm -f "$source"
91-
fi
92-
source="$destination"
93-
fi
94-
95-
dest_actual=$(stat -c %s "$source")
96-
dest_actual=$(( dest_actual / 1024 ))
72+
source="$bcs_source"/"$filename"
73+
Process_Volume "$filename" "$BCS_DECRYPTDIR" "$BCS_COMPRESDIR"
9774

9875
case "$TAR_FD" in
9976
none) exit 0
@@ -106,8 +83,8 @@ esac
10683
runtime_data=$(jo bcs_source="$bcs_source" \
10784
start_timestamp="$start_timestamp" \
10885
last_timestamp="$last_timestamp" \
109-
source_size_running="$(( source_size_running + source_actual ))" \
110-
dest_size_running="$(( dest_size_running + dest_actual ))" \
86+
source_size_running="$(( source_size_running + source_actual_size ))" \
87+
dest_size_running="$(( dest_size_running + dest_actual_size ))" \
11188
archive_volumes=$(( archive_volumes + 1 )) )
11289
echo "$runtime_data" > "$BCS_DATAFILE"
11390

scripts/bacchus-restore.sh

Lines changed: 10 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -36,41 +36,23 @@ source "scripts/include/common/cleanup.sh" || { echo "scripts/include/common/cle
3636
source "scripts/include/common/duration_readable.sh" || { echo "scripts/include/common/duration_readable.sh not found"; exit 1; }
3737
source "scripts/include/common/load_persistence.sh" || { echo "scripts/include/common/load_persistence.sh not found"; exit 1; }
3838
source "scripts/include/restore/completion_stats.sh" || { echo "scripts/include/restore/completion_stats.sh not found"; exit 1; }
39+
source "scripts/include/restore/process_volume.sh" || { echo "scripts/include/restore/process_volume.sh not found"; exit 1; }
3940

4041
BCS_TMPFILE=$(mktemp -u /tmp/baccus-XXXXXX)
4142
trap Cleanup EXIT
4243

4344
if [ "$BCS_COMPRESS" == "off" ] && [ -z "$BCS_PASSWORD" ]; then
4445
BCS_TARDIR="$BCS_DEST"
4546
else
47+
# Determine size for ramdisk based on the starting archive processed size
4648
if [ "$BCS_RAMDISK" == "on" ]; then
47-
source="$BCS_SOURCE"/"$BCS_BASENAME".tar
4849
ramdisk_size_tmpdir="$BCS_TMPFILE".ramdisk_size
4950
mkdir "$ramdisk_size_tmpdir"
5051

51-
if [ "$BCS_COMPRESS" == "on" ]; then
52-
source="$source".gz
53-
fi
54-
55-
if [ -n "$BCS_PASSWORD" ]; then
56-
if [ "$BCS_COMPRESS" == "on" ]; then
57-
destination="$ramdisk_size_tmpdir"/"$BCS_BASENAME".tar.gz
58-
else
59-
destination="$ramdisk_size_tmpdir"/"$BCS_BASENAME".tar
60-
fi
61-
echo "$BCS_PASSWORD" | gpg -qd --batch --cipher-algo AES256 --compress-algo none --passphrase-fd 0 --no-mdc-warning -o "$destination" "$source".gpg
62-
source="$destination"
63-
fi
64-
65-
if [ "$BCS_COMPRESS" == "on" ]; then
66-
destination="$ramdisk_size_tmpdir"/"$BCS_BASENAME".tar
67-
pigz -9cd "$source" > "$destination"
68-
#gzip -9cd "$source" > "$destination"
69-
source="$destination"
70-
fi
52+
source="$BCS_SOURCE"/"$BCS_BASENAME".tar
53+
Process_Volume "$BCS_BASENAME".tar "$ramdisk_size_tmpdir" "$ramdisk_size_tmpdir"
7154

72-
BCS_VOLUMESIZE=$(stat -c %s "$source")
73-
BCS_VOLUMESIZE=$(( BCS_VOLUMESIZE / 1024 ))
55+
BCS_VOLUMESIZE=$dest_actual_size
7456
rm -rf "$ramdisk_size_tmpdir"
7557

7658
ramdisk_size=0
@@ -90,59 +72,20 @@ else
9072
fi
9173
fi
9274

93-
# process first (possibly only) backup volume
75+
# Process first (possibly only) backup volume
9476
echo "$BCS_BASENAME".tar
95-
96-
source="$BCS_SOURCE"/"$BCS_BASENAME".tar
9777
timestamp="$(date +%s)"
9878

99-
if [ "$BCS_COMPRESS" == "on" ]; then
100-
source="$source".gz
101-
fi
102-
103-
if [ -n "$BCS_PASSWORD" ]; then
104-
if [ "$BCS_COMPRESS" == "on" ]; then
105-
destination="$BCS_DECRYPTDIR"/"$BCS_BASENAME".tar.gz
106-
else
107-
destination="$BCS_DECRYPTDIR"/"$BCS_BASENAME".tar
108-
fi
109-
if [ -z "$source_actual" ]; then
110-
source_actual=$(stat -c %s "$source".gpg)
111-
source_actual=$(( source_actual / 1024 ))
112-
fi
113-
echo "$BCS_PASSWORD" | gpg -qd --batch --cipher-algo AES256 --compress-algo none --passphrase-fd 0 --no-mdc-warning -o "$destination" "$source".gpg
114-
source="$destination"
115-
fi
116-
117-
if [ "$BCS_COMPRESS" == "on" ]; then
118-
destination="$BCS_COMPRESDIR"/"$BCS_BASENAME".tar
119-
pigz -9cd "$source" > "$destination"
120-
#gzip -9cd "$source" > "$destination"
121-
if [ -z "$source_actual" ]; then
122-
source_actual=$(stat -c %s "$source")
123-
source_actual=$(( source_actual / 1024 ))
124-
fi
125-
if [ -n "$BCS_PASSWORD" ]; then
126-
rm -f "$source"
127-
fi
128-
source="$destination"
129-
fi
130-
131-
if [ -z "$source_actual" ]; then
132-
source_actual=$(stat -c %s "$source")
133-
source_actual=$(( source_actual / 1024 ))
134-
fi
135-
136-
dest_actual=$(stat -c %s "$source")
137-
dest_actual=$(( dest_actual / 1024 ))
79+
source="$BCS_SOURCE"/"$BCS_BASENAME".tar
80+
Process_Volume "$BCS_BASENAME".tar "$BCS_DECRYPTDIR" "$BCS_COMPRESDIR"
13881

13982
# Populate external data structure with starting values
14083
export BCS_DATAFILE="$BCS_TMPFILE".runtime
14184
runtime_data=$(jo bcs_source="$BCS_SOURCE" \
14285
start_timestamp="$timestamp" \
14386
last_timestamp="$timestamp" \
144-
source_size_running=$source_actual \
145-
dest_size_running=$dest_actual \
87+
source_size_running=$source_actual_size \
88+
dest_size_running=$dest_actual_size \
14689
archive_volumes=1)
14790
echo "$runtime_data" > "$BCS_DATAFILE"
14891

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
function Process_Volume()
2+
{
3+
# Process a restore on a single archive volume
4+
#
5+
# Make sure these global variable have values before calling this function
6+
# BCS_BASENAME
7+
# BCS_COMPRESS
8+
# BCS_PASSWORD
9+
# source
10+
#
11+
# Call this function with these arguements
12+
# $1 - current archive filename
13+
# $2 - decryption temporary directory
14+
# (was ramdisk_size_tmpdir and BCS_DECRYPTDIR)
15+
# $3 - compression temporary directory
16+
# (was ramdisk_size_tmpdir and BCS_COMPRESDIR)
17+
#
18+
# These variables are set in this function as globals and can
19+
# be accessed by the caller after completion
20+
# source_actual_size
21+
# dest_actual_size
22+
23+
unset source_actual_size
24+
unset dest_actual_size
25+
26+
local destination
27+
28+
if [ "$BCS_COMPRESS" == "on" ]; then
29+
source="$source".gz
30+
fi
31+
32+
if [ -n "$BCS_PASSWORD" ]; then
33+
if [ "$BCS_COMPRESS" == "on" ]; then
34+
destination="$2"/"$1".gz
35+
else
36+
destination="$2"/"$1"
37+
fi
38+
39+
if [ -z "$source_actual_size" ]; then
40+
source_actual_size=$(stat -c %s "$source".gpg)
41+
fi
42+
43+
echo "$BCS_PASSWORD" | gpg -qd --batch --cipher-algo AES256 --compress-algo none --passphrase-fd 0 --no-mdc-warning -o "$destination" "$source".gpg
44+
source="$destination"
45+
fi
46+
47+
if [ "$BCS_COMPRESS" == "on" ]; then
48+
destination="$3"/"$1"
49+
pigz -9cd "$source" > "$destination"
50+
#gzip -9cd "$source" > "$destination"
51+
52+
if [ -z "$source_actual_size" ]; then
53+
source_actual_size=$(stat -c %s "$source")
54+
fi
55+
56+
if [ -n "$BCS_PASSWORD" ]; then
57+
rm -f "$source"
58+
fi
59+
source="$destination"
60+
fi
61+
62+
if [ -z "$source_actual_size" ]; then
63+
source_actual_size=$(stat -c %s "$source")
64+
fi
65+
source_actual_size=$(( source_actual_size / 1024 ))
66+
67+
dest_actual_size=$(stat -c %s "$source")
68+
dest_actual_size=$(( dest_actual_size / 1024 ))
69+
}

0 commit comments

Comments
 (0)