diff --git a/README.md b/README.md index 99517b6..309e9b1 100644 --- a/README.md +++ b/README.md @@ -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.: ``` diff --git a/backup.sh b/backup.sh index 66c8a47..be349a7 100755 --- a/backup.sh +++ b/backup.sh @@ -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"