Add --exclude option to the backup script
This commit is contained in:
@@ -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.**
|
**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.:
|
For the integrity check (note it may take a long time to run for large repos), e.g.:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ OPTIONS:
|
|||||||
--keep-yearly N Keep N yearly snapshots (default: 2)
|
--keep-yearly N Keep N yearly snapshots (default: 2)
|
||||||
|
|
||||||
BACKUP OPTIONS:
|
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-exclude-caches Don't exclude cache directories
|
||||||
--no-one-file-system Allow crossing filesystem boundaries
|
--no-one-file-system Allow crossing filesystem boundaries
|
||||||
--compression LEVEL Compression level: auto|max|off|fastest|better (default: auto)
|
--compression LEVEL Compression level: auto|max|off|fastest|better (default: auto)
|
||||||
@@ -67,6 +69,10 @@ EXAMPLES:
|
|||||||
--log-file /var/log/backup.log \\
|
--log-file /var/log/backup.log \\
|
||||||
/var/lib/mysql sftp:user@host:/backups/mysql
|
/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:
|
ENVIRONMENT VARIABLES:
|
||||||
RESTIC_PASSWORD_FILE Alternative to --password-file
|
RESTIC_PASSWORD_FILE Alternative to --password-file
|
||||||
RESTIC_PASSWORD Direct password (not recommended)
|
RESTIC_PASSWORD Direct password (not recommended)
|
||||||
@@ -115,6 +121,7 @@ send_healthcheck() {
|
|||||||
|
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
CUSTOM_TAGS=()
|
CUSTOM_TAGS=()
|
||||||
|
EXCLUDE_PATTERNS=()
|
||||||
POSITIONAL_ARGS=()
|
POSITIONAL_ARGS=()
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
@@ -155,6 +162,10 @@ while [[ $# -gt 0 ]]; do
|
|||||||
KEEP_YEARLY="$2"
|
KEEP_YEARLY="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
-e|--exclude)
|
||||||
|
EXCLUDE_PATTERNS+=("$2")
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
--no-exclude-caches)
|
--no-exclude-caches)
|
||||||
EXCLUDE_CACHES=false
|
EXCLUDE_CACHES=false
|
||||||
shift
|
shift
|
||||||
@@ -273,6 +284,9 @@ fi
|
|||||||
if [ "$ONE_FILE_SYSTEM" = true ]; then
|
if [ "$ONE_FILE_SYSTEM" = true ]; then
|
||||||
BACKUP_ARGS+=("--one-file-system")
|
BACKUP_ARGS+=("--one-file-system")
|
||||||
fi
|
fi
|
||||||
|
for pattern in "${EXCLUDE_PATTERNS[@]}"; do
|
||||||
|
BACKUP_ARGS+=("--exclude" "$(printf '%q' "$pattern")")
|
||||||
|
done
|
||||||
|
|
||||||
log_message "Starting backup of $SOURCE_PATH to $REPOSITORY"
|
log_message "Starting backup of $SOURCE_PATH to $REPOSITORY"
|
||||||
send_healthcheck "START" "Starting backup of $BACKUP_NAME"
|
send_healthcheck "START" "Starting backup of $BACKUP_NAME"
|
||||||
|
|||||||
Reference in New Issue
Block a user