#!/usr/bin/env bash # backuper installer # # curl -fsSL https://git.arabianq.ru/arabianq/backuper/raw/branch/main/install.sh | bash # BACKUPER_REPO=https://git.arabianq.ru/arabianq/backuper.git ./install.sh # # Env: # BACKUPER_REPO git URL of this repo (required unless edited below) # BACKUPER_DIR install directory (default /opt/backuper) # BACKUPER_TIMER 1 = enable the daily systemd timer (default 1) set -euo pipefail REPO_URL="${BACKUPER_REPO:-https://git.arabianq.ru/arabianq/backuper.git}" DIR="${BACKUPER_DIR:-/opt/backuper}" ENABLE_TIMER="${BACKUPER_TIMER:-1}" log() { printf '\033[32m[INFO]\033[0m %s\n' "$*"; } die() { printf '\033[31m[ERR ]\033[0m %s\n' "$*" >&2; exit 1; } [ "$(id -u)" = 0 ] || die "run as root (sudo)" [ -n "$REPO_URL" ] || die "set the repo URL: BACKUPER_REPO=https://git.arabianq.ru/arabianq/backuper.git" command -v git >/dev/null 2>&1 || die "git is required" if [ ! -d "$DIR/.git" ] && [ -f /etc/systemd/system/backuper.service ]; then detected=$(awk '$1 ~ /^ExecStart=/ {sub(/^ExecStart=/, "", $1); print $1; exit}' /etc/systemd/system/backuper.service) detected=$(dirname "$(dirname "$detected")") if [ -x "$detected/bin/backuper" ]; then DIR=$detected log "existing installation detected: $DIR" fi fi if [ -d "$DIR/.git" ]; then log "updating existing installation in $DIR" git -C "$DIR" pull --ff-only elif [ -d "$DIR" ]; then die "$DIR already exists and is not a git clone (remove it or set BACKUPER_DIR)" else [ -n "$REPO_URL" ] || die "set the repo URL: BACKUPER_REPO=https://git.arabianq.ru/arabianq/backuper.git" log "cloning into $DIR" git clone --depth 1 "$REPO_URL" "$DIR" fi [ -f "$DIR/backup.conf" ] || cp "$DIR/backup.conf.example" "$DIR/backup.conf" mkdir -p "$DIR/conf.d" chmod +x "$DIR/bin/backuper" chown -R root:root "$DIR" log "checking dependencies (installs what is missing)" "$DIR/bin/backuper" check cp "$DIR"/systemd/backuper.service "$DIR"/systemd/backuper@.service "$DIR"/systemd/backuper.timer /etc/systemd/system/ systemctl daemon-reload if [ "$ENABLE_TIMER" = 1 ]; then systemctl enable --now backuper.timer log "daily timer enabled (04:00 + jitter)" fi log "installed into $DIR" log "next steps:" log " 1) edit $DIR/backup.conf # cloud remote, retention, webhook" log " 2) cp $DIR/examples/node.conf.example $DIR/conf.d/.conf && edit it" log " 3) rclone config # create the remote named in backup.conf" log " 4) $DIR/bin/backuper run --dry && $DIR/bin/backuper run"