Add --exclude option to the backup script

This commit is contained in:
2026-09-22 16:21:44 +00:00
parent e9b80eaa50
commit 9c26a0c48e
2 changed files with 20 additions and 0 deletions
+6
View File
@@ -20,6 +20,12 @@ Run the first backup manually in the shell, e.g.:
**NOTE: unfortunately there's something wrong with the script and it does not output anything to the log unless the `--verbose` flag is passed so I just always pass the flag.**
To leave parts of the source folder out of the snapshot, pass `--exclude` one or more times (same pattern syntax as restic's own `--exclude`), e.g. to skip a live database directory that is dumped separately:
```
./backup.sh --exclude /home/user/app/data/postgres --exclude /home/user/app/data/tmp ... /home/user/app sftp:storage-server:/backups/app --verbose
```
For the integrity check (note it may take a long time to run for large repos), e.g.:
```
+14
View File
@@ -45,6 +45,8 @@ OPTIONS:
--keep-yearly N Keep N yearly snapshots (default: 2)
BACKUP OPTIONS:
-e, --exclude PATTERN Exclude files/dirs matching PATTERN (can be used multiple times,
same syntax as restic --exclude)
--no-exclude-caches Don't exclude cache directories
--no-one-file-system Allow crossing filesystem boundaries
--compression LEVEL Compression level: auto|max|off|fastest|better (default: auto)
@@ -67,6 +69,10 @@ EXAMPLES:
--log-file /var/log/backup.log \\
/var/lib/mysql sftp:user@host:/backups/mysql
# Exclude subdirectories from the backup
$0 --exclude /srv/app/data/postgres --exclude "/srv/app/data/app/tmp" \\
/srv/app sftp:user@host:/backups/app
ENVIRONMENT VARIABLES:
RESTIC_PASSWORD_FILE Alternative to --password-file
RESTIC_PASSWORD Direct password (not recommended)
@@ -115,6 +121,7 @@ send_healthcheck() {
# Parse command line arguments
CUSTOM_TAGS=()
EXCLUDE_PATTERNS=()
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
@@ -155,6 +162,10 @@ while [[ $# -gt 0 ]]; do
KEEP_YEARLY="$2"
shift 2
;;
-e|--exclude)
EXCLUDE_PATTERNS+=("$2")
shift 2
;;
--no-exclude-caches)
EXCLUDE_CACHES=false
shift
@@ -273,6 +284,9 @@ fi
if [ "$ONE_FILE_SYSTEM" = true ]; then
BACKUP_ARGS+=("--one-file-system")
fi
for pattern in "${EXCLUDE_PATTERNS[@]}"; do
BACKUP_ARGS+=("--exclude" "$(printf '%q' "$pattern")")
done
log_message "Starting backup of $SOURCE_PATH to $REPOSITORY"
send_healthcheck "START" "Starting backup of $BACKUP_NAME"