aboutsummaryrefslogtreecommitdiff
path: root/borger
diff options
context:
space:
mode:
Diffstat (limited to 'borger')
-rwxr-xr-xborger82
1 files changed, 47 insertions, 35 deletions
diff --git a/borger b/borger
index 0b1ac29..76ad9dc 100755
--- a/borger
+++ b/borger
@@ -27,16 +27,10 @@ function fatal {
}
function borger_usage {
- # Ensure we have our base config folder
- mkdir -p $BASE_CONFIG
-
- # List available targets
- if [ -z "$DESTINATION" ]; then
- echo "usage: $BASENAME <destination> [--check]"
- echo -n "available destinations from $BASE_CONFIG: "
- ls $BASE_CONFIG
- exit 1
- fi
+ echo "usage: $BASENAME <destination> [--continuous|--check]"
+ echo -n "available destinations from $BASE_CONFIG: "
+ ls $BASE_CONFIG
+ exit 1
}
# Config
@@ -54,11 +48,12 @@ function borger_config {
fi
# Default backup config
- keepdaily="7"
- keepweekly="4"
- keepmonth="6"
- encryption="keyfile"
- placeholder="{user}"
+ KEEPDAILY="7"
+ KEEPWEEKLY="4"
+ KEEPMONTHLY="6"
+ ENCRYPTION="keyfile"
+ PLACEHOLDER="{user}"
+ INTERVAL="1h"
if [ -e "$CONFIG" ] ; then
source $CONFIG
@@ -75,10 +70,8 @@ function borger_config {
# Check
function borger_check {
- if [ "$OPTION" == "--check" ]; then
- borg list
- exit $?
- fi
+ borg list
+ exit $?
}
# Our trap
@@ -92,7 +85,7 @@ function borger_init {
# Remote backup over SSH
if ! ssh $SSH_SERVER -p $SSH_PORT test -f $BORG_REPO_DIR/config; then
info "Initializing borg repository at $BORG_REPO..."
- borg init --encryption=$encryption $BORG_REPO
+ borg init --encryption=$ENCRYPTION $BORG_REPO
init_exit=$?
@@ -104,7 +97,7 @@ function borger_init {
# Local backup
if [ ! -f "$BORG_REPO/config" ]; then
info "Initializing borg repository at $BORG_REPO..."
- borg init --encryption=$encryption $BORG_REPO
+ borg init --encryption=$ENCRYPTION $BORG_REPO
init_exit=$?
@@ -128,7 +121,7 @@ function borger_create {
--show-rc \
--compression lz4 \
--exclude-caches \
- ::"${placeholder}-{now}" \
+ ::"${PLACEHOLDER}-{now}" \
$ORIG
backup_exit=$?
@@ -139,17 +132,17 @@ function borger_create {
}
# Use the `prune` subcommand to maintain daily, weekly and monthly archives.
-# The '${placeholder}-' prefix is very important to limit prune's operation to
+# The '${PLACEHOLDER}-' prefix is very important to limit prune's operation to
# one specific archive and not apply to archives also.
function borger_prune {
info "Pruning repository..."
borg prune \
--list \
- --prefix "${placeholder}-" \
+ --prefix "${PLACEHOLDER}-" \
--show-rc \
- --keep-daily $keepdaily \
- --keep-weekly $keepweekly \
- --keep-monthly $keepmonthly \
+ --keep-daily $KEEPDAILY \
+ --keep-weekly $KEEPWEEKLY \
+ --keep-monthly $KEEPMONTHLY \
prune_exit=$?
@@ -158,11 +151,30 @@ function borger_prune {
fi
}
-# Main
-borger_usage
-borger_config
-borger_check
-borger_trap
-borger_init
-borger_create
-borger_prune
+# Main backup procedure
+function borger_run {
+ borger_config
+ borger_trap
+ borger_init
+ borger_create
+ borger_prune
+}
+
+# Ensure we have our base config folder
+mkdir -p $BASE_CONFIG
+
+# Dispatch
+if [ -z "$DESTINATION" ]; then
+ borger_usage
+elif [ -z "$OPTION" ]; then
+ borger_run
+elif [ "$OPTION" == "--check" ]; then
+ borger_config
+ borger_check
+elif [ "$OPTION" == "--continuous" ]; then
+ while true; do
+ borger_run
+ info "Running on continous mode... sleeping $INTERVAL..."
+ sleep $INTERVAL
+ done
+fi