diff options
-rw-r--r-- | README.md | 37 | ||||
-rwxr-xr-x | borger | 82 |
2 files changed, 70 insertions, 49 deletions
@@ -24,13 +24,6 @@ Create a config for your `servername` destination at `~/.config/borger/servernam #export BORG_PASSPHRASE='HACKME' #export BORG_PASSCOMMAND='pass show backup' #export BORG_PASSCOMMAND='keyringer default decrypt borg 2> /dev/null' - - # Backup config - keepdaily="7" - keepweekly="4" - keepmonth="6" - encryption="keyfile" - placeholder="{user}" Then run borger: @@ -47,17 +40,33 @@ following config at `~/.config/borger/my-disk`: #export BORG_PASSCOMMAND='pass show backup' #export BORG_PASSCOMMAND='keyringer default decrypt borg 2> /dev/null' - # Backup config - keepdaily="7" - keepweekly="4" - keepmonth="6" - encryption="keyfile" - placeholder="{user}" - Then run borger normally: borger my-disk +# Optional config + +These include: + + # Optional backup config + export KEEPDAILY="7" # how many days to keep + export KEEPWEEKLY="4" # how many weeks to keep + export KEEPMONTHLY="6" # how many months to keep + export ENCRYPTION="keyfile" # encryption strategy, PAY ATTENTION TO THIS + export PLACEHOLDER="{user}" # placeholder to tag archives + export INTERVAL="1h" # interval between backups in the continuous mode + +# Continuous backups + +If you want to run your backups continuously, use + + borger servername --continuous + +By default `borger` waits `1h` before starting the new backup procedure which +can be adjusted using the `INTERVAL` config variable. See [this +issue](https://github.com/borgbackup/borg/issues/325) for a discussion on +continous backups. + # Checking your backups As simply as @@ -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 |