Skip to content

Commit 5f49ed3

Browse files
basic low disk storage swap code
1 parent bc69ac8 commit 5f49ed3

7 files changed

Lines changed: 67 additions & 15 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Allows for creating smaller backups with privacy while allowing
55
for partial recovery should any individual incremental archive
66
file be damaged.
77

8-
Other similar solutions using encryption result in total data
9-
loss past failed incremental archive file.
8+
Other similar solutions using incremental files, compression, and
9+
encryption result in total data loss past failed incremental archive file.
1010

1111
## Help
1212

bacchus.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export BCS_COMPRESS="$_arg_compress"
1919
export BCS_DECRYPTDIR="$_arg_decryptdir"
2020
export BCS_VERBOSETAR="$_arg_verbosetar"
2121
export BCS_PASSWORD="$password"
22+
# export BCS_LOWDISKSPACE=5230
23+
export BCS_LOWDISKSPACE=1385
2224

2325
PrintOptions()
2426
{

scripts/bacchus-backup-new-volume.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,27 @@
1414
# NOTE: If no password is supplied (as BCS_PASSWORD environment var),
1515
# bacchus does not encrypt backup
1616

17+
BCS_DEST=$(<"$BCS_PATHFILE")
18+
while true; do
19+
availablespace=$(df -kP "$BCS_DEST" | awk '{print $4}' | tail -1)
20+
lowspace="$(( BCS_VOLUMESIZE * BCS_LOWDISKSPACE ))"
21+
printf "availablespace %s\n" "$availablespace"
22+
printf "lowspace %s\n" "$lowspace"
23+
if [ "$availablespace" -lt "$lowspace" ]; then
24+
printf "LOW AVAILABLE SPACE on %s (%s < %s)\n" "$BCS_DEST" "$availablespace" "$lowspace"
25+
printf "Either free-up space or swap out storage device and press enter\n"
26+
printf "Or enter a new destination path and press enter\n"
27+
read newpath
28+
printf "\n"
29+
if [ -n "$newpath" ]; then
30+
BCS_DEST="$newpath"
31+
echo "$BCS_DEST" > "$BCS_PATHFILE"
32+
fi
33+
else
34+
break
35+
fi
36+
done
37+
1738
tararchivedir=$(dirname "$TAR_ARCHIVE")
1839
TAR_ARCHIVE=$(basename "$TAR_ARCHIVE")
1940
name=$(expr "$TAR_ARCHIVE" : '\(.*\)-.*')

scripts/bacchus-backup.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
# for partial recovery should any individual incremental archive
88
# file be damaged.
99
#
10-
# Other similar solutions using encryption result in total data
11-
# loss past failed incremental archive file.
10+
# Other similar solutions using incremental files, compression, and
11+
# encryption result in total data loss past failed incremental archive file.
1212
#
1313
# Usage:
1414
# bacchus-backup.sh
@@ -39,10 +39,13 @@ Cleanup()
3939
fi
4040
if [[ "$BCS_TMPFILE" == *"tmp"* ]]; then
4141
rm -rf "$BCS_TMPFILE"
42+
rm -rf "$BCS_PATHFILE"
4243
fi
4344
}
4445

4546
BCS_TMPFILE=$(mktemp -u /tmp/baccus-XXXXXX)
47+
export BCS_PATHFILE="$BCS_TMPFILE".dest
48+
echo "$BCS_DEST" > "$BCS_PATHFILE"
4649
trap Cleanup EXIT
4750

4851
if [ "$BCS_COMPRESS" == "off" ] && [ -z "$BCS_PASSWORD" ]; then
@@ -74,6 +77,9 @@ fi
7477
tar "$tarargs" --format=posix --sort=name --new-volume-script "$scriptdir/bacchus-backup-new-volume.sh" -L "$BCS_VOLUMESIZE" --volno-file "$BCS_TMPFILE" -f "$BCS_TARDIR"/"$BCS_BASENAME".tar $BCS_SOURCE
7578

7679
# Setup tar variables to call new-volume script for handling last (or possibly only) archive volume
80+
if [ "$BCS_COMPRESS" == "off" ] && [ -z "$BCS_PASSWORD" ]; then
81+
BCS_TARDIR=$(<"$BCS_PATHFILE")
82+
fi
7783
vol=$(cat "$BCS_TMPFILE")
7884
case "$vol" in
7985
1) export TAR_ARCHIVE="$BCS_TARDIR"/"$BCS_BASENAME".tar

scripts/bacchus-restore-new-volume.sh

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,32 @@ oldname="${TAR_ARCHIVE##*/}"
2525

2626
echo "$filename"
2727

28-
source="$BCS_SOURCE"/"$filename"
29-
if [ "$BCS_COMPRESS" == "on" ]; then
30-
source="$source".gz
31-
rm -f "$BCS_COMPRESDIR"/"$oldname"
32-
fi
33-
if [ -n "$BCS_PASSWORD" ]; then
34-
source="$source".gpg
35-
rm -f "$BCS_DECRYPTDIR"/"$oldname"
36-
fi
28+
BCS_SOURCE=$(<"$BCS_PATHFILE")
29+
while true; do
30+
source="$BCS_SOURCE"/"$filename"
31+
if [ "$BCS_COMPRESS" == "on" ]; then
32+
source="$source".gz
33+
rm -f "$BCS_COMPRESDIR"/"$oldname"
34+
fi
35+
if [ -n "$BCS_PASSWORD" ]; then
36+
source="$source".gpg
37+
rm -f "$BCS_DECRYPTDIR"/"$oldname"
38+
fi
39+
40+
if [ ! -f "$source" ]; then
41+
printf "Archive volume %s NOT FOUND in %s\n" $(basename "$source") "$BCS_SOURCE"
42+
printf "Either place this file in the source directory and press enter\n"
43+
printf "Or enter a new source path and press enter\n"
44+
read newpath
45+
printf "\n"
46+
if [ -n "$newpath" ]; then
47+
BCS_SOURCE="$newpath"
48+
echo "$BCS_SOURCE" > "$BCS_PATHFILE"
49+
fi
50+
else
51+
break
52+
fi
53+
done
3754

3855
case "$TAR_SUBCOMMAND" in
3956
-x) test -r "$source" || exit 1

scripts/bacchus-restore.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
# for partial recovery should any individual incremental archive
88
# file be damaged.
99
#
10-
# Other similar solutions using encryption result in total data
11-
# loss of past failed incremental archive file.
10+
# Other similar solutions using incremental files, compression, and
11+
# encryption result in total data loss past failed incremental archive file.
1212
#
1313
# Usage:
1414
# bacchus-restore.sh
@@ -19,6 +19,7 @@
1919
# BCS_BASENAME - Base filename for backup archive
2020
# BCS_VOLUMESIZE - Used LOCALLY here, not from environment
2121
# BCS_RAMDISK - Boolean enabling ramdisk
22+
# BCS_TARDIR - Intermediate area for tar
2223
# BCS_DECRYPTDIR - Intermediate area to store unencrypted volume
2324
# BCS_COMPRESDIR - Intermediate area to store uncompressed volume
2425
# BCS_COMPRESS - Boolean enabling compression
@@ -40,10 +41,13 @@ Cleanup()
4041
fi
4142
if [[ "$BCS_TMPFILE" == *"tmp"* ]]; then
4243
rm -rf "$BCS_TMPFILE"
44+
rm -rf "$BCS_PATHFILE"
4345
fi
4446
}
4547

4648
BCS_TMPFILE=$(mktemp -u /tmp/baccus-XXXXXX)
49+
export BCS_PATHFILE="$BCS_TMPFILE".dest
50+
echo "$BCS_SOURCE" > "$BCS_PATHFILE"
4751
trap Cleanup EXIT
4852

4953
if [ "$BCS_COMPRESS" == "off" ] && [ -z "$BCS_PASSWORD" ]; then

source/bacchus.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export BCS_COMPRESS="$_arg_compress"
1919
export BCS_DECRYPTDIR="$_arg_decryptdir"
2020
export BCS_VERBOSETAR="$_arg_verbosetar"
2121
export BCS_PASSWORD="$password"
22+
# export BCS_LOWDISKSPACE=5230
23+
export BCS_LOWDISKSPACE=1385
2224

2325
PrintOptions()
2426
{

0 commit comments

Comments
 (0)