Skip to content

Commit

Permalink
Merge pull request #4 from kubrickfr/check_dependencies
Browse files Browse the repository at this point in the history
Check if all required binaries exists before doing anything else
  • Loading branch information
kubrickfr authored Apr 26, 2024
2 parents a362aed + 085fe77 commit 604d2c4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ Rather than dealing with the complexity of custom file formats and metadata file

As such if you want to change the format (compression, encryption, file container, etc.), please start a new backup _epoch_ so as not to mix the two.

# Return value

It is important that you check the return value of the back-up script for proper monitoring and alerting.

* 0: everything went fine
* 1: a "usage" error occured. You used a unrecognised command switch, or referenced a volume or snapshot that does not exist
* 2: an error occurred after the snapshot was created, **you should pay close attention to these**! The script will have tried to delete the newly created snapshot so that subsequent incremental backups can be made from the last good known state
* 3: a required dependency is not installed

# Important security recommendations
This is all rather common sense, but:

Expand Down
30 changes: 30 additions & 0 deletions check_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

if ! command -v age &> /dev/null; then
echo "command not found: age"
exit 3
fi
if ! command -v aws &> /dev/null; then
echo "command not found: aws"
exit 3
fi
if ! command -v lz4 &> /dev/null; then
echo "command not found: lz4"
exit 3
fi
if ! command -v mbuffer &> /dev/null; then
echo "command not found: mbuffer"
exit 3
fi
if ! command -v split &> /dev/null; then
echo "command not found: split"
exit 3
fi
if ! command -v sed &> /dev/null; then
echo "command not found: sed"
exit 3
fi
if ! command -v btrfs &> /dev/null; then
echo "command not found: btrfs"
exit 3
fi
4 changes: 3 additions & 1 deletion restore_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
exit 1
fi

$(dirname "$0")/check_deps.sh || exit 3

DELETE_PREVIOUS=false

OPTSTRING="b:p:e:i:s:d"
Expand Down
6 changes: 4 additions & 2 deletions stream_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
exit 1
fi

$(dirname "$0")/check_deps.sh || exit 3

DELETE_PREVIOUS=false
CHUNK_SIZE="512M"
SOURCE_EPOCH=""
Expand Down Expand Up @@ -91,7 +93,7 @@ function cleanup () {
exit 2
}

aws s3 ls s3://${BUCKET}/${PREFIX} >> /dev/null \
aws s3 ls s3://${BUCKET}/${PREFIX} >/dev/null 2>&1 \
&& echo "SECURITY WARNING: current AWS IAM entity is allowed to list bucket contents! This can allow an attacker using the same identity to overwrite files and ruin your backups!" >&2

SEQ=$(date +%s)
Expand Down

0 comments on commit 604d2c4

Please sign in to comment.