Skip to content
45 changes: 45 additions & 0 deletions .github/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# About restic-backup-script

## Project Overview
This repository provides a Bash script (`restic-backup.sh`) and configuration (`restic-backup.conf`) for automated, encrypted backups using [restic](https://restic.net/). It targets VPS environments, backing up local directories to remote SFTP storage (e.g., Hetzner Storage Box) with client-side encryption, deduplication, and snapshot management.

## Key Files & Structure
- `restic-backup.sh`: Main script. Handles backup, restore, integrity checks, scheduling, notifications, and self-updating.
- `restic-backup.conf`: Central config. All operational parameters (sources, retention, logging, notifications, etc.) are set here.
- `restic-excludes.txt`: Patterns for files/directories to exclude from backups.
- `how-to/`: Step-by-step guides for restoring, migrating, troubleshooting, and best practices.

## Essential Workflows
- **Run Modes**: Script supports multiple flags (`--restore`, `--check`, `--install-scheduler`, etc.). See `README.md` for full list and usage examples.
- **Configuration**: All settings (sources, repository, retention, notifications) are managed in `restic-backup.conf`. Use Bash array syntax for `BACKUP_SOURCES`.
- **Exclusions**: Update `restic-excludes.txt` or `EXCLUDE_PATTERNS` in config for custom exclusions.
- **Scheduling**: Use `--install-scheduler` to set up systemd/cron jobs interactively.
- **Self-Update**: Script can auto-update itself and restic binary if run interactively.
- **Notifications**: Integrates with ntfy and Discord for backup status alerts.
- **Healthchecks**: Optional integration for cron job monitoring via Healthchecks.io.

## Patterns & Conventions
- **Root Privileges**: Script enforces root execution (auto re-invokes with sudo).
- **Locking**: Prevents concurrent runs via `/tmp/restic-backup.lock`.
- **Logging**: Rotates logs at `/var/log/restic-backup.log` based on config.
- **Error Handling**: Uses `set -euo pipefail` for strict error management.
- **Color Output**: Uses ANSI colors for interactive output, disables for non-TTY.
- **Repository URL**: Uses SSH config alias for SFTP (e.g., `sftp:storagebox:/home/vps`).
- **Restore Safety**: Guides recommend restoring to temp directories before overwriting live data.

## Integration Points
- **restic**: Main dependency. Script checks, installs, and verifies restic binary.
- **SFTP/SSH**: Repository access via SSH config alias. Ensure `/root/.ssh/config` is set up.
- **ntfy/Discord**: Notification endpoints configured in `restic-backup.conf`.
- **Healthchecks.io**: Optional dead man's switch for scheduled jobs.

## Examples
- To run a backup: `sudo ./restic-backup.sh`
- To restore: `sudo ./restic-backup.sh --restore` (interactive wizard)
- To check integrity: `sudo ./restic-backup.sh --check`
- To install scheduler: `sudo ./restic-backup.sh --install-scheduler`

## References
- See `README.md` for feature overview and usage.
- See `how-to/` for guides on restore, migration, troubleshooting, and best practices.
- See `restic-backup.conf` for all config options and conventions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ This script automates encrypted, deduplicated backups of local directories to a
- `sudo ./restic-backup.sh --check` - Verify repository integrity by checking a subset of data.
- `sudo ./restic-backup.sh --check-full` - Run a full check verifying all repository data.
- `sudo ./restic-backup.sh --test` - Validate configuration, permissions, and SSH connectivity.
- `sudo ./restic-backup.sh --install-scheduler` - Run the interactive wizard to set up an automated backup schedule (systemd/cron).
- `sudo ./restic-backup.sh --uninstall-scheduler` - Remove a schedule created by the wizard.
- `sudo ./restic-backup.sh --restore` - Start the interactive restore wizard.
- `sudo ./restic-backup.sh --forget` - Manually apply the retention policy and prune old data.
- `sudo ./restic-backup.sh --diff` - Show a summary of changes between the last two snapshots.
Expand Down Expand Up @@ -238,7 +240,25 @@ Before the first backup, you need to create the repository password file and ini
sudo ./restic-backup.sh --init
```

### 5. Set up a Cron Job
### 5. Set up an Automated Schedule (Recommended)

The easiest and most reliable way to schedule your backups is to use the script's built-in interactive wizard. It will guide you through creating and enabling either a modern `systemd timer` (recommended) or a traditional `cron job`.

1. Navigate to your script directory:
```sh
cd /root/scripts/backup
```

2. Run the scheduler installation wizard:
```sh
sudo ./restic-backup.sh --install-scheduler
```

Follow the on-screen prompts to choose your preferred scheduling system and frequency. The script will handle creating all the necessary files and enabling the service for you.

#### Manual Cron Job Setup

If you prefer to manage the schedule manually instead of using the wizard, you can edit the root crontab directly.

To run the backup automatically, edit the root crontab.

Expand Down
Loading