|
| 1 | +#!/bin/bash |
| 2 | +# info: add backup host |
| 3 | +# options: TYPE HOST USERNAME PASSWORD [PATH] [PORT] |
| 4 | +# |
| 5 | +# example: v-add-backup-host sftp backup.acme.com admin p4$$w@Rd |
| 6 | +# v-add-backup-host b2 bucketName keyID applicationKey |
| 7 | +# |
| 8 | +# Add a new remote backup location. Currently SFTP, FTP and Backblaze are supported |
| 9 | + |
| 10 | +#----------------------------------------------------------# |
| 11 | +# Variables & Functions # |
| 12 | +#----------------------------------------------------------# |
| 13 | + |
| 14 | +# Argument definition |
| 15 | +repo=$1 |
| 16 | +snapshots=$2 |
| 17 | +daily=$3 |
| 18 | +weekly=$4 |
| 19 | +monthly=$5 |
| 20 | +yearly=$6 |
| 21 | + |
| 22 | +# CPU Architecture |
| 23 | +arch=$(arch) |
| 24 | + |
| 25 | +# Includes |
| 26 | +# shellcheck source=/etc/hestiacp/hestia.conf |
| 27 | +source /etc/hestiacp/hestia.conf |
| 28 | +# shellcheck source=/usr/local/hestia/func/main.sh |
| 29 | +source $HESTIA/func/main.sh |
| 30 | +# load config file |
| 31 | +source_conf "$HESTIA/conf/hestia.conf" |
| 32 | +# Fetch current verison B2 CLI tool |
| 33 | +source_conf "$HESTIA/install/upgrade/upgrade.conf" |
| 34 | + |
| 35 | +is_negative_one_or_int() { |
| 36 | + if [[ "$1" != '-1' ]]; then |
| 37 | + is_int_format_valid "$1" "$2" |
| 38 | + fi |
| 39 | +} |
| 40 | + |
| 41 | +#----------------------------------------------------------# |
| 42 | +# Verifications # |
| 43 | +#----------------------------------------------------------# |
| 44 | + |
| 45 | +check_args '6' "$#" "REPO SNAPSHOTS DAILY WEEKLY MONTHLY YEARLY" |
| 46 | + |
| 47 | +format_no_quotes $repo 'Repository host' |
| 48 | +is_negative_one_or_int $snapshots 'Snapshots' |
| 49 | +is_negative_one_or_int $daily 'Daily snapshots' |
| 50 | +is_negative_one_or_int $weekly 'Weekly snapshots' |
| 51 | +is_negative_one_or_int $monthly 'Monthly snapshots' |
| 52 | +is_negative_one_or_int $yearly 'Yearly snapshots' |
| 53 | + |
| 54 | +# Perform verification if read-only mode is enabled |
| 55 | +check_hestia_demo_mode |
| 56 | + |
| 57 | +#----------------------------------------------------------# |
| 58 | +# Action # |
| 59 | +#----------------------------------------------------------# |
| 60 | + |
| 61 | +# Check if Restic is allready installed if not install it ... |
| 62 | +if ! which /usr/bin/restic > /dev/null 2>&1; then |
| 63 | + apt install restic |
| 64 | +fi |
| 65 | +# Update restic to last release |
| 66 | +restic self-update > /dev/null 2>&1 |
| 67 | + |
| 68 | +echo "REPO='$repo'" > /usr/local/hestia/conf/restic.conf |
| 69 | +echo "SNAPSHOTS='$snapshots'" >> /usr/local/hestia/conf/restic.conf |
| 70 | +echo "KEEP_DAILY='$daily'" >> /usr/local/hestia/conf/restic.conf |
| 71 | +echo "KEEP_WEEKLY='$weekly'" >> /usr/local/hestia/conf/restic.conf |
| 72 | +echo "KEEP_MONTHLY='$monthly'" >> /usr/local/hestia/conf/restic.conf |
| 73 | +echo "KEEP_YEARLY='$yearly'" >> /usr/local/hestia/conf/restic.conf |
| 74 | + |
| 75 | +$BIN/v-change-sys-config-value 'BACKUP_INCREMENTAL' 'yes' |
| 76 | + |
| 77 | +#----------------------------------------------------------# |
| 78 | +# Hestia # |
| 79 | +#----------------------------------------------------------# |
| 80 | + |
| 81 | +# Logging |
| 82 | +log_event "$OK" "$ARGUMENTS" |
| 83 | + |
| 84 | +exit |
0 commit comments