1616# Utilizes these environment variables:
1717# BCS_SOURCE - directory location of archive files
1818# BCS_DEST - directory location of archive files
19- # BCS_BASENAME - base filename for restore archive, appending
20- # incremental archive volume number
19+ # BCS_BASENAME - Base filename for backup archive
20+ # BCS_VOLUMESIZE - Used LOCALLY here, not from environment
21+ # BCS_RAMDISK - Boolean enabling ramdisk
2122# BCS_DECRYPTDIR - Intermediate area to store unencrypted volume
2223# BCS_COMPRESDIR - Intermediate area to store uncompressed volume
24+ # BCS_COMPRESS - Boolean enabling compression
25+ # BCS_VERBOSETAR - Tar shows target filenames backed up
2326# BCS_PASSWORD - Password to encrypt backup archive volumes
2427#
2528# NOTE: If no password is supplied (as BCS_PASSWORD environment var),
@@ -30,6 +33,11 @@ scriptdir=$(dirname "$_")
3033
3134Cleanup ()
3235{
36+ if [[ " $BCS_RAMDISK " == " on" ]]; then
37+ sync
38+ umount " $BCS_TMPFILE " .ramdisk
39+ rmdir " $BCS_TMPFILE " .ramdisk
40+ fi
3341 if [[ " $BCS_TMPFILE " == * " tmp" * ]]; then
3442 rm -rf " $BCS_TMPFILE "
3543 fi
@@ -38,6 +46,56 @@ Cleanup()
3846BCS_TMPFILE=$( mktemp -u /tmp/baccus-XXXXXX)
3947trap Cleanup EXIT
4048
49+ if [ " $BCS_COMPRESS " == " off" ] && [ -z " $BCS_PASSWORD " ]; then
50+ BCS_TARDIR=" $BCS_DEST "
51+ else
52+ if [ " $BCS_RAMDISK " == " on" ]; then
53+ source=" $BCS_SOURCE " /" $BCS_BASENAME " .tar
54+ ramdisk_size_tmpdir=" $BCS_TMPFILE " .ramdisk_size
55+ mkdir " $ramdisk_size_tmpdir "
56+
57+ if [ " $BCS_COMPRESS " == " on" ]; then
58+ source=" $source " .gz
59+ fi
60+
61+ if [ -n " $BCS_PASSWORD " ]; then
62+ if [ " $BCS_COMPRESS " == " on" ]; then
63+ destination=" $ramdisk_size_tmpdir " /" $BCS_BASENAME " .tar.gz
64+ else
65+ destination=" $ramdisk_size_tmpdir " /" $BCS_BASENAME " .tar
66+ fi
67+ echo " $BCS_PASSWORD " | gpg -qd --batch --cipher-algo AES256 --compress-algo none --passphrase-fd 0 --no-mdc-warning -o " $destination " " $source " .gpg
68+ source=" $destination "
69+ fi
70+
71+ if [ " $BCS_COMPRESS " == " on" ]; then
72+ destination=" $ramdisk_size_tmpdir " /" $BCS_BASENAME " .tar
73+ pigz -9cd " $source " > " $destination "
74+ # gzip -9cd "$source" > "$destination"
75+ source=" $destination "
76+ fi
77+
78+ BCS_VOLUMESIZE=$( stat -c %s " $source " )
79+ BCS_VOLUMESIZE=$(( BCS_VOLUMESIZE / 1024 ))
80+ rm -rf " $ramdisk_size_tmpdir "
81+
82+ ramdisk_size=0
83+ if [ " $BCS_COMPRESS " == " on" ]; then
84+ ramdisk_size=" $(( ramdisk_size + BCS_VOLUMESIZE)) "
85+ fi
86+ if [ -n " $BCS_PASSWORD " ]; then
87+ ramdisk_size=" $(( ramdisk_size + BCS_VOLUMESIZE)) "
88+ fi
89+ ramdisk_dir=" $BCS_TMPFILE " .ramdisk
90+ ramdisk_size=" $(( ((ramdisk_size * 1024 ) + ((BCS_VOLUMESIZE * 1024 ) / 100 )) ))"
91+ mkdir -p " $ramdisk_dir "
92+ mount -t tmpfs -o size=" $ramdisk_size " tmpfs " $ramdisk_dir "
93+ BCS_COMPRESDIR=" $ramdisk_dir "
94+ BCS_DECRYPTDIR=" $ramdisk_dir "
95+ BCS_TARDIR=" $ramdisk_dir "
96+ fi
97+ fi
98+
4199# process first (possibly only) backup volume
42100echo " $BCS_BASENAME " .tar
43101
0 commit comments