aboutsummaryrefslogtreecommitdiffstats
path: root/backuper.sh
diff options
context:
space:
mode:
Diffstat (limited to 'backuper.sh')
-rw-r--r--backuper.sh35
1 files changed, 28 insertions, 7 deletions
diff --git a/backuper.sh b/backuper.sh
index d36e436..c988347 100644
--- a/backuper.sh
+++ b/backuper.sh
@@ -13,12 +13,14 @@ PLACES=""
EXCLUDE=""
STORE=""
AFTER=""
+FILE_TYPE=""
## Pipeline variables
PID_GENERATE=""
PID_STORE=""
PID_FILE="pids"
STAGE="0"
+PIPELINE_FILE_TYPE="bz2.gpg"
## Internal variables - program logic
CONFIG_FILE_NAME=".backuper.sh.conf"
@@ -48,10 +50,12 @@ get_home() {
}
result_file() {
+ [ -z "$COMMAND" -a -z "$PLACES" ] && error "Specify type of backup (command or places) before filename query"
+ [ -z "$STORE" ] && error "Specify store mechanism before filename query"
if [ -n "$DST" ]; then
- echo "$DST"/"$FILENAME_ENC"
+ echo "$DST"/"$FILENAME"
else
- echo "$FILENAME_ENC"
+ echo "$FILENAME"
fi
}
@@ -65,7 +69,7 @@ compute_gpg_recipients() {
## Program control
error() {
echo "ERROR: $1" >&2
- exit 1
+ kill -6 "$$"
}
die() {
@@ -93,11 +97,19 @@ generate() {
cmd() {
COMMAND="$@"
+ adjust_file_name
+}
+
+file_type() {
+ [ -n "$PLACES" ] && error "Do not change file type with places type of backup"
+ FILE_TYPE="$1"
+ adjust_file_name
}
places() {
PLACES="$1"
[ "$#" -gt 1 ] && error "Specify places as string"
+ adjust_file_name
}
exclude() {
@@ -124,7 +136,7 @@ run() {
store_file() {
[ -z "$1" ] && error "Specify destination"
- store "sh -c 'cat > ${1}/${FILENAME_ENC}'"
+ store "sh -c 'cat > ${1}/${FILENAME}'"
}
## Internal functions
@@ -139,12 +151,18 @@ test_input() {
compute_variables() {
UTS="$(date +"%s")"
TS="$(date +"%Y-%m-%d_%H-%M-%S")"
- FILENAME="backup_"$NAME"_"$TS".tar"
- FILENAME_ENC="${FILENAME}.bz2.gpg"
+ FILENAME_BASE="backup_"$NAME"_"$TS""
RUNDIR="/tmp/backuper_run_dir_$$_$UTS"
compute_gpg_recipients
}
+adjust_file_name() {
+ FILENAME="$FILENAME_BASE"
+ [ -n "$FILE_TYPE" ] && FILENAME="$FILENAME"."$FILE_TYPE"
+ [ -n "$PLACES" ] && FILENAME="$FILENAME".tar
+ [ -n "$PIPELINE_FILE_TYPE" ] && FILENAME="$FILENAME"."$PIPELINE_FILE_TYPE"
+}
+
prepare() {
trap 'error_handler' EXIT INT QUIT TERM ABRT HUP ILL TRAP BUS FPE SEGV
mkdir -p "$RUNDIR"
@@ -243,14 +261,17 @@ start_pipeline() {
}
backup() {
- prepare
test_input
+ prepare
start_pipeline
backup_done
cleanup
}
main() {
+ # This trap is just to exit 1 in case of pre-run failure
+ # Signal handler will be overwritten before backup
+ trap 'exit 1' ABRT
load_config
}