33Lightweight and reliable Bash script that automates the backup of local directories and securely
44uploads them to a remote storage service.
55
6- Tool combines the power of ` rsync ` for fast , incremental local backups with ` rclone ` for seamless remote syncing across
6+ This tool combines the power of ` restic ` for secure , incremental local backups with ` rclone ` for seamless remote syncing across
77cloud providers, SFTP, WebDAV, or even custom remote endpoints.
88
99#### 🔧 Features
1010
11- - 📁 Backup selected local directories with ` rsync `
12- - ☁️ Upload archives or snapshots to remote storage using ` rclone `
11+ - 📁 Backup selected local directories with ` restic `
12+ - ☁️ Upload backups to remote storage using ` rclone `
13+ - 🔒 Strong encryption with ` restic ` for secure backups
14+ - 🔄 Easy restoration from any snapshot
15+ - 📊 Backup statistics and verification
1316- 🕒 Supports scheduled (cron) execution for automated daily backups
14- - 🔐 Optional encryption via ` rclone ` 's crypt backend
15- - 🧾 Log-friendly output for easy monitoring
16- - 🧰 Minimal dependencies: only ` bash ` , ` rsync ` , and ` rclone `
17+ - 📋 Comprehensive logging system with log rotation
18+ - 🔃 Profile support for multiple backup configurations
19+ - 🚫 Lock mechanism to prevent concurrent executions
20+ - 🧪 Dry-run capability to preview actions
21+ - 🧰 Minimal dependencies: only ` bash ` , ` restic ` , and ` rclone `
1722
1823#### 💼 Use Cases
1924
2025- Personal or professional workstation backups
2126- Offsite backups for servers or VPS
2227- Archiving dev environments, config files, or databases
28+ - Multi-system backup management with profiles
2329
2430#### Installation
2531
@@ -33,6 +39,7 @@ cloud providers, SFTP, WebDAV, or even custom remote endpoints.
3339
3440 ``` bash
3541 echo ' export PATH="$HOME/.rearden-backup/bin:$PATH"' >> ~ /.bash_profile
42+ ```
3643
3744#### Commands
3845
@@ -41,81 +48,164 @@ cloud providers, SFTP, WebDAV, or even custom remote endpoints.
4148| ` init ` | Initialize the restic repository |
4249| ` backup ` | Create a new backup |
4350| ` restore [path] [snapshot] ` | Restore from backup (defaults to latest snapshot and / path) |
44- | ` push` | Upload backup to remote storage |
45- | ` pull` | Download backup from remote storage |
51+ | ` push ` | Upload entire CONFIG_DIR to remote storage |
52+ | ` pull ` | Download entire CONFIG_DIR from remote storage |
4653| ` list ` | List available snapshots |
4754| ` stats ` | Show backup statistics |
4855| ` verify ` | Verify the integrity of the backup repository |
4956| ` export ` | Export backup information to a file |
5057| ` template ` | Display a template for init.sh file |
5158
52- # # Options
59+ #### Options
5360
5461| Option | Description |
5562| -------------------------| ---------------------------------------------------|
5663| ` -p, --profile PROFILE ` | Use specific profile configuration |
5764| ` -d, --dry-run ` | Show what would be done without actually doing it |
58- | ` -v, --verbose` | Increase verbosity |
65+ | ` -v, --verbose ` | Enable basic verbosity (level 1) |
66+ | ` -vv ` | Enable more detailed verbosity (level 2) |
67+ | ` -vvv ` | Enable maximum verbosity (level 3) |
5968| ` -h, --help ` | Show help message |
6069
61- # # Environment Variables
62-
63- | Variable | Description | Default |
64- | -----------------| -------------------------------------| -----------|
65- | ` INIT_SCRIPT` | Path to initialization script | ` init.sh` |
66- | ` PROFILE` | Default profile name | ` default` |
67- | ` DRY_RUN` | Set to 1 for dry-run mode | ` 0` |
68- | ` VERBOSE` | Set to 1 for verbose output | ` 0` |
69- | ` MAX_LOG_FILES` | Maximum number of log files to keep | ` 10` |
70-
71- # # Configuration Variables (in init.sh)
72-
73- | Variable | Description | Required |
74- | ------------------------| --------------------------------------------------| ------------------|
75- | ` CONFIG_DIR` | Directory for all configuration and backup files | Yes |
76- | ` BACKUP_DIRECTORIES` | Space-separated list of directories to backup | Yes |
77- | ` RCLONE_REMOTE` | Remote storage path for rclone | No |
78- | ` RETENTION_DAYS` | Number of days to keep backups | No (default: 30) |
79- | ` RESTIC_PASSWORD` | Password for restic repository | No* |
80- | ` RESTIC_PASSWORD_FILE` | Path to file containing restic password | No* |
81- | ` ENABLE_BACKUP` | Enable/disable backup functionality | No (default: 1) |
82- | ` ENABLE_RESTORE` | Enable/disable restore functionality | No (default: 1) |
83- | ` ENABLE_PUSH` | Enable/disable push functionality | No (default: 1) |
84- | ` ENABLE_PULL` | Enable/disable pull functionality | No (default: 1) |
70+ #### Environment Variables
71+
72+ | Variable | Description | Default |
73+ | ---------------------| --------------------------------------------------------------------| -----------|
74+ | ` INIT_SCRIPT ` | Path to initialization script | ` init.sh ` |
75+ | ` PROFILE ` | Default profile name | ` default ` |
76+ | ` DRY_RUN ` | Set to 1 for dry-run mode | ` 0 ` |
77+ | ` VERBOSE ` | Set verbosity level: 0=none, 1=basic, 2=detailed, 3=maximum | ` 1 ` |
78+ | ` MAX_LOG_FILES ` | Maximum number of log files to keep | ` 10 ` |
79+ | ` RESTIC_REPOSITORY ` | Optional: Use a remote repository directly instead of local+rclone | ` ` |
80+
81+ #### Configuration Variables (in init.sh)
82+
83+ | Variable | Description | Required |
84+ | ------------------------| --------------------------------------------------------------------------------| -----------------|
85+ | ` CONFIG_DIR ` | Directory for all configuration and backup files | Yes |
86+ | ` BACKUP_DIRECTORIES ` | Space-separated list of directories to backup | Yes |
87+ | ` LOCAL_BACKUP_REPO ` | Local repository path for restic (default: ` ${CONFIG_DIR}/backups/${PROFILE} ` ) | No |
88+ | ` RCLONE_REMOTE ` | Remote storage path for rclone | No |
89+ | ` RETENTION_DAYS ` | Number of days to keep backups | No (default: 0) |
90+ | ` VERIFY_BACKUP ` | Verify backup after creation (1=yes, 0=no) | No (default: 1) |
91+ | ` RESTIC_PASSWORD ` | Password for restic repository | No* |
92+ | ` RESTIC_PASSWORD_FILE ` | Path to file containing restic password | No* |
93+ | ` ENABLE_BACKUP ` | Enable/disable backup functionality | No (default: 1) |
94+ | ` ENABLE_RESTORE ` | Enable/disable restore functionality | No (default: 1) |
95+ | ` ENABLE_PUSH ` | Enable/disable push functionality | No (default: 1) |
96+ | ` ENABLE_PULL ` | Enable/disable pull functionality | No (default: 1) |
8597
8698* Either ` RESTIC_PASSWORD ` or ` RESTIC_PASSWORD_FILE ` must be set
8799
88- # # Example files
100+ #### Backup Repository Modes
89101
90- Example ` init.sh `
102+ The script supports two modes for managing the backup repository:
91103
92- ```
104+ 1 . ** Local + Remote Sync mode** (default)
105+ - Backups are created locally in ` LOCAL_BACKUP_REPO `
106+ - The entire ` CONFIG_DIR ` (including the repository) is synced to/from remote with rclone
107+ - Good for frequent backups with occasional remote synchronization
108+
109+ 2 . ** Direct Remote Repository mode**
110+ - Set by defining ` RESTIC_REPOSITORY ` with a remote URL (s3, sftp, rest, etc.)
111+ - Backup operations work directly with the remote repository
112+ - Push/Pull operations are disabled in this mode
113+ - Good for direct cloud backups without local copies
114+
115+ #### Verbosity Levels
116+
117+ The script supports multiple verbosity levels to control the amount of information displayed:
118+
119+ - Level 0: Minimal output (only basic logs)
120+ - Level 1 (` -v ` ): Basic progress and information
121+ - Level 2 (` -vv ` ): Detailed progress and debug information
122+ - Level 3 (` -vvv ` ): Maximum verbosity for troubleshooting
123+
124+ #### Profiles
125+
126+ Multiple backup profiles can be defined to manage different backup scenarios:
127+
128+ 1 . Create a profile file at ` ${CONFIG_DIR}/profiles/<profile_name>.sh `
129+ 2 . Add specific configuration variables for that profile
130+ 3 . Use the profile with ` -p ` or ` --profile ` option when running commands
131+
132+ #### Example Files
133+
134+ Example ` init.sh ` :
135+
136+ ``` bash
137+ #! /bin/bash
138+ # Basic configuration for backup script
139+
140+ # Required: Set the configuration directory
93141export CONFIG_DIR=$( pwd) /local
94- export BACKUP_DIRECTORIES=/projects
95- export RESTIC_PASSWORD_FILE=$(pwd)/creds.txt
142+
143+ # Directories to backup (space-separated)
144+ export BACKUP_DIRECTORIES=" /projects /home/user/documents"
145+
146+ # Remote repository configuration
96147export RCLONE_REMOTE=" remote:backup/projects-$( hostname) "
148+
149+ # Backup retention (days)
150+ export RETENTION_DAYS=30
151+
152+ # Password file for restic repository
153+ export RESTIC_PASSWORD_FILE=" ${CONFIG_DIR} /restic-password.txt"
154+
155+ # Optional: Configure verbosity (0=none, 1=basic, 2=detailed, 3=maximum)
156+ export VERBOSE=1
97157```
98158
99- Example `local/rclone.conf` file for sftp uploads:
159+ Example profile for server backups (` local/profiles/server.sh ` ):
160+
161+ ``` bash
162+ #! /bin/bash
163+ # Server-specific backup settings
100164
165+ export BACKUP_DIRECTORIES=" /etc /var/www /opt/application/data"
166+ export RETENTION_DAYS=60
167+ export VERBOSE=1
101168```
169+
170+ Example ` local/rclone.conf ` file for SFTP uploads:
171+
172+ ``` ini
102173[remote]
103174type = sftp
104- host = xyz
105- user = abc
175+ host = example.com
176+ user = backup-user
106177port = 22
107178```
108179
109180Example ` local/rclone.conf ` file for Hetzner storage box:
110- ```
181+
182+ ``` ini
111183[remote]
112184type = sftp
113- host = xyz .your-storagebox.de
114- user = abc
185+ host = u123456 .your-storagebox.de
186+ user = u123456
115187port = 23
116188```
117189
118- ## License
190+ Example ` local/exclude.txt ` for excluding specific patterns:
119191
120- This code is released under the MIT License. See [LICENSE](LICENSE).
192+ ```
193+ # Patterns to exclude from backup
194+ **/.DS_Store
195+ **/node_modules
196+ **/.git
197+ **/*.log
198+ **/tmp
199+ **/temp
200+ **/.cache
201+ ```
202+
203+ #### Compatibility Notes
121204
205+ - The script is compatible with both newer and older versions of restic
206+ - Some advanced features (like the ` stats ` command) may not be available in older restic versions
207+ - For best results, using restic 0.12.0 or later is recommended
208+
209+ #### License
210+
211+ This code is released under the MIT License. See [ LICENSE] ( LICENSE ) .
0 commit comments