You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -9,66 +9,67 @@ This script automates encrypted, deduplicated backups of local directories to a
9
9
10
10
## Features
11
11
12
-
-**Client-Side Encryption**: All data is encrypted on your server *before* being uploaded, ensuring zero-knowledge privacy from the storage provider.
13
-
-**Deduplication & Compression**: Saves significant storage space by only storing unique data blocks and applying compression.
14
-
-**Snapshot-Based Backups**: Creates point-in-time snapshots, allowing you to easily browse and restore files from any backup date.
15
-
-**Advanced Retention Policies**: Sophisticated rules to automatically keep daily, weekly, monthly, and yearly snapshots.
16
-
-**Unified Configuration**: All settings are managed in a single, easy-to-edit `restic-backup.conf` file.
17
-
-**Notification Support**: Sends detailed success, warning, or failure notifications to ntfy and/or Discord.
18
-
-**System Friendly**: Uses `nice` and `ionice` to minimize CPU and I/O impact during backups.
19
-
-**Multiple Operation Modes**: Supports standard backups, dry runs, integrity checks, difference summaries, and a safe, interactive restore mode.
20
-
-**Concurrency Control & Logging**: Prevents multiple instances from running simultaneously and handles its own log rotation.
21
-
-**Pre-run Validation**: Performs checks for required commands and repository connectivity before execution.
22
-
-**Cron Job Monitoring**: Optional integration with [Healthchecks.io](https://healthchecks.io) for alerts if a backup job fails to run on schedule.
12
+
-**Client-Side Encryption**: All data is encrypted on your server *before* being uploaded, ensuring zero-knowledge privacy from the storage provider.
13
+
-**Deduplication & Compression**: Saves significant storage space by only storing unique data blocks and applying compression.
14
+
-**Snapshot-Based Backups**: Creates point-in-time snapshots, allowing you to easily browse and restore files from any backup date.
15
+
-**Advanced Retention Policies**: Sophisticated rules to automatically keep daily, weekly, monthly, and yearly snapshots.
16
+
-**Unified Configuration**: All settings are managed in a single, easy-to-edit `restic-backup.conf` file.
17
+
-**Notification Support**: Sends detailed success, warning, or failure notifications to ntfy, Discord, Slack, and Microsoft Teams.
18
+
-**Flexible File Exclusions**: Exclude files and directories using either a dedicated exclusion file or by listing patterns directly in the configuration.
19
+
-**System Friendly**: Uses `nice` and `ionice` to minimize CPU and I/O impact during backups.
20
+
-**Multiple Operation Modes**: Supports standard backups, dry runs, integrity checks, difference summaries, and a safe, interactive restore mode.
21
+
-**Concurrency Control & Logging**: Prevents multiple instances from running simultaneously and handles its own log rotation.
22
+
-**Pre-run Validation**: Performs checks for required commands and repository connectivity before execution.
23
+
-**Cron Job Monitoring**: Optional integration with [Healthchecks.io](https://healthchecks.io) for alerts if a backup job fails to run on schedule.
23
24
24
25
-----
25
26
26
27
## Usage
27
28
28
-
####Run Modes:
29
-
30
-
-`sudo ./restic-backup.sh` - Run a standard backup silently (suitable for cron).
31
-
-`sudo ./restic-backup.sh --verbose` - Run with live progress and detailed output.
32
-
-`sudo ./restic-backup.sh --dry-run` - Preview changes without creating a new snapshot.
33
-
-`sudo ./restic-backup.sh --check` - Verify repository integrity by checking a subset of data.
34
-
-`sudo ./restic-backup.sh --check-full` - Run a full check verifying all repository data.
35
-
-`sudo ./restic-backup.sh --test` - Validate configuration, permissions, and SSH connectivity.
36
-
-`sudo ./restic-backup.sh --install-scheduler` - Run the interactive wizard to set up an automated backup schedule (systemd/cron).
37
-
-`sudo ./restic-backup.sh --uninstall-scheduler` - Remove a schedule created by the wizard.
38
-
-`sudo ./restic-backup.sh --restore` - Start the interactive restore wizard.
39
-
-`sudo ./restic-backup.sh --forget` - Manually apply the retention policy and prune old data.
40
-
-`sudo ./restic-backup.sh --diff` - Show a summary of changes between the last two snapshots.
You could also download and install the latest version of `restic`.
107
+
You could also download and install the latest version of `restic`.
107
108
108
109
**Note:** While `restic` can be installed from your system's package manager, it is often an older version. It is **recommended** to install it manually or allow the script's built-in auto-updater to fetch the latest [official version](https://github.com/restic/restic/releases) for you.
The most reliable way for the script to connect to a remote server is via an SSH config file.
145
147
146
-
1.**Generate a root SSH key** if one doesn't already exist:
148
+
1.**Generate a root SSH key** if one doesn't already exist:
147
149
148
150
```sh
149
151
sudo ssh-keygen -t ed25519
150
152
```
151
153
152
154
(Press Enter through all prompts).
153
155
154
-
2. **Add your public key** to the remote server's authorized keys. For a Hetzner Storage Box, you can paste the contents of `sudo cat /root/.ssh/id_ed25519.pub` into the control panel.
156
+
2. **Add your public key** to the remote server's authorized keys. For a Hetzner Storage Box, you can paste the contents of `sudo cat /root/.ssh/id_ed25519.pub` into the control panel.
155
157
156
-
3. **Create an SSH config file** to define an alias for your connection:
158
+
3. **Create an SSH config file** to define an alias for your connection:
157
159
158
160
```sh
159
161
# Open the file in an editor
160
162
sudo nano /root/.ssh/config
161
163
```
162
164
163
-
4. **Add the following content**, adjusting the details for your server:
165
+
4. **Add the following content**, adjusting the details for your server:
164
166
165
-
```
167
+
```bash
166
168
Host storagebox
167
169
HostName u123456.your-storagebox.de
168
170
User u123456-sub4
@@ -172,7 +174,7 @@ The most reliable way for the script to connect to a remote server is via an SSH
172
174
ServerAliveCountMax 240
173
175
```
174
176
175
-
5. **Set secure permissions** and test the connection:
177
+
5. **Set secure permissions** and test the connection:
176
178
177
179
```sh
178
180
sudo chmod 600 /root/.ssh/config
@@ -183,13 +185,13 @@ The most reliable way for the script to connect to a remote server is via an SSH
183
185
184
186
### 3. Place and Configure Files
185
187
186
-
1. Create your script directory:
188
+
1. Create your script directory:
187
189
188
190
```sh
189
191
mkdir -p /root/scripts/backup && cd /root/scripts/backup
190
192
```
191
193
192
-
2. Download the script, configuration, and excludes files from the repository:
194
+
2. Download the script, configuration, and excludes files from the repository:
193
195
194
196
```sh
195
197
# Download the main script
@@ -202,25 +204,70 @@ The most reliable way for the script to connect to a remote server is via an SSH
4. **Set secure permissions** for your configuration file:
213
+
4. **Set secure permissions** for your configuration file:
212
214
213
215
```sh
214
216
chmod 600 restic-backup.conf
215
217
```
216
218
217
-
5. **Edit `restic-backup.conf` and `restic-excludes.txt`** to specify your repository path, source directories, notification settings, and exclusion patterns.
219
+
5. **Edit `restic-backup.conf` and `restic-excludes.txt`** to specify your repository path, source directories, notification settings, and exclusion patterns.
220
+
221
+
### Configuration (`restic-backup.conf`)
222
+
223
+
All script behavior is controlled by the `restic-backup.conf` file. Below is an overview of the key settings available.
224
+
225
+
#### Core Settings
226
+
227
+
- `RESTIC_REPOSITORY`: The connection string for your remote storage.
228
+
- `RESTIC_PASSWORD_FILE`: The absolute path to the file containing your repository's encryption password.
229
+
- `BACKUP_SOURCES`: A list of local directories to back up. Use Bash array syntax `("/path/one""/path/two")` to handle spaces correctly.
230
+
231
+
#### Retention Policy
232
+
233
+
You can define how many snapshots to keep for various timeframes. The script will automatically remove older snapshots that fall outside these rules.
234
+
235
+
- `KEEP_LAST`: Number of the most recent snapshots to keep.
236
+
- `KEEP_DAILY`: Number of daily snapshots to keep.
237
+
- `KEEP_WEEKLY`: Number of weekly snapshots to keep.
238
+
- `KEEP_MONTHLY`: Number of monthly snapshots to keep.
239
+
- `KEEP_YEARLY`: Number of yearly snapshots to keep.
240
+
241
+
#### Notifications
242
+
243
+
The script can send detailed status notifications to multiple services. Each can be enabled or disabled individually.
244
+
245
+
- `NTFY_ENABLED`: Set to `true` to enable ntfy notifications.
246
+
- `DISCORD_ENABLED`: Set to `true` to enable Discord notifications.
247
+
- `SLACK_ENABLED`: Set to `true` to enable Slack notifications.
248
+
- `TEAMS_ENABLED`: Set to `true` to enable Microsoft Teams notifications.
249
+
- You must also provide the corresponding `_URL` and `_TOKEN`for each service you enable.
250
+
251
+
#### Exclusions
252
+
253
+
You have two ways to exclude files and directories from your backups:
254
+
255
+
1. **`EXCLUDE_FILE`**: Point this to a text file (like `restic-excludes.txt`) containing one exclusion pattern per line.
256
+
2. **`EXCLUDE_PATTERNS`**: A space-separated list of patterns to exclude directly in the configuration file (e.g., `*.tmp *.log`).
257
+
258
+
#### Performance and Maintenance
259
+
260
+
- `LOW_PRIORITY`: Set to `true` to run the backup with lower CPU (`nice`) and I/O (`ionice`) priority, minimizing impact on other services.
261
+
- `CHECK_AFTER_BACKUP`: Set to `true` to automatically run a repository integrity check after each successful backup.
262
+
- `PRUNE_AFTER_FORGET`: Set to `true` to automatically prune the repository after applying the retention policy, which frees up storage space.
263
+
264
+
-----
218
265
219
266
### 4. Initial Repository Setup
220
267
221
268
Before the first backup, you need to create the repository password file and initialize the remote repository.
222
269
223
-
1. **Create the password file.** This stores the encryption key for your repository. **Guard this file carefully!**
270
+
1. **Create the password file.** This stores the encryption key for your repository. **Guard this file carefully!**
224
271
225
272
```sh
226
273
# Replace 'your-very-secure-password' with a strong, unique password
@@ -230,7 +277,7 @@ Before the first backup, you need to create the repository password file and ini
230
277
sudo chmod 400 /root/.restic-password
231
278
```
232
279
233
-
2. **Initialize the repository.** Run the script with the `--init` flag:
280
+
2. **Initialize the repository.** Run the script with the `--init` flag:
234
281
235
282
```sh
236
283
# Navigate to your script directory
@@ -244,12 +291,14 @@ Before the first backup, you need to create the repository password file and ini
244
291
245
292
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`.
246
293
247
-
1. Navigate to your script directory:
294
+
1. Navigate to your script directory:
295
+
248
296
```sh
249
297
cd /root/scripts/backup
250
298
```
251
299
252
-
2. Run the scheduler installation wizard:
300
+
2. Run the scheduler installation wizard:
301
+
253
302
```sh
254
303
sudo ./restic-backup.sh --install-scheduler
255
304
```
@@ -262,13 +311,13 @@ If you prefer to manage the schedule manually instead of using the wizard, you c
262
311
263
312
To run the backup automatically, edit the root crontab.
264
313
265
-
1. Open the crontab editor:
314
+
1. Open the crontab editor:
266
315
267
316
```sh
268
317
sudo crontab -e
269
318
```
270
319
271
-
2. Add the following lines to schedule your backups and maintenance.
320
+
2. Add the following lines to schedule your backups and maintenance.
272
321
273
322
```crontab
274
323
# Define a safe PATH that includes the location of restic
@@ -284,6 +333,7 @@ To run the backup automatically, edit the root crontab.
*For pune job in your `restic-backup.conf`, set `PRUNE_AFTER_FORGET=true`.*
288
338
*For more details on how forget flag work, see the [official Restic documentation on removing snapshots](https://restic.readthedocs.io/en/stable/060_forget.html).*
289
339
*Redirecting output to `/dev/null` is recommended, as the script handles its own logging and notifications.*
0 commit comments