Allow extra args for non-backup commands (#115)
* Allow extra args for non-backup commands * Add example in doc * Include global args in backup command * Fix indent * Restore set * Modified: CHANGELOG.md --------- Co-authored-by: Erik Westrup <erik.westrup@gmail.com>
This commit is contained in:
@@ -5,7 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- Support for extra args for all restic commands with `RESTIC_EXTRA_ARGS`. [115](https://github.com/erikw/restic-automatic-backup-scheduler/pull/115/)
|
||||
### Changed
|
||||
- Warn on certain unset envvars instead of error-exit.
|
||||
- Allow escaped spaces in EXTRA_ARGS.
|
||||
|
||||
@@ -63,7 +63,12 @@ IFS=':' read -ra backup_paths <<< "$RESTIC_BACKUP_PATHS"
|
||||
# Convert to array, an preserve spaces. See #111
|
||||
extra_args=( )
|
||||
while IFS= read -r -d ''; do
|
||||
extra_args+=( "$REPLY" )
|
||||
extra_args+=( "$REPLY" )
|
||||
done < <(xargs printf '%s\0' <<<"$RESTIC_EXTRA_ARGS")
|
||||
|
||||
backup_extra_args=( )
|
||||
while IFS= read -r -d ''; do
|
||||
backup_extra_args+=( "$REPLY" )
|
||||
done < <(xargs printf '%s\0' <<<"$RESTIC_BACKUP_EXTRA_ARGS")
|
||||
|
||||
B2_ARG=
|
||||
@@ -95,7 +100,8 @@ test "$OSTYPE" = msys || FS_ARG=--one-file-system
|
||||
# Reference: https://unix.stackexchange.com/questions/146756/forward-sigterm-to-child-in-bash
|
||||
|
||||
# Remove locks from other stale processes to keep the automated backup running.
|
||||
restic unlock &
|
||||
restic unlock \
|
||||
"${extra_args[@]}" &
|
||||
wait $!
|
||||
|
||||
# Do the backup!
|
||||
@@ -109,6 +115,7 @@ restic backup \
|
||||
"${B2_ARG[@]}" \
|
||||
"${exclusion_args[@]}" \
|
||||
"${extra_args[@]}" \
|
||||
"${backup_extra_args[@]}" \
|
||||
"${backup_paths[@]}" &
|
||||
wait $!
|
||||
|
||||
@@ -119,6 +126,7 @@ restic forget \
|
||||
--verbose="$RESTIC_VERBOSITY_LEVEL" \
|
||||
--tag "$RESTIC_BACKUP_TAG" \
|
||||
"${B2_ARG[@]}" \
|
||||
"${extra_args[@]}" \
|
||||
--prune \
|
||||
--group-by "paths,tags" \
|
||||
--keep-hourly "$RESTIC_RETENTION_HOURS" \
|
||||
@@ -140,13 +148,13 @@ if [ "$RESTIC_NOTIFY_BACKUP_STATS" = true ]; then
|
||||
if [ -w "$RESTIC_BACKUP_NOTIFICATION_FILE" ]; then
|
||||
echo 'Notifications are enabled: Silently computing backup summary stats...'
|
||||
|
||||
snapshot_size=$(restic stats latest --tag "$RESTIC_BACKUP_TAG" | grep -i 'total size:' | cut -d ':' -f2 | xargs) # xargs acts as trim
|
||||
latest_snapshot_diff=$(restic snapshots --tag "$RESTIC_BACKUP_TAG" --latest 2 --compact \
|
||||
snapshot_size=$(restic stats latest --tag "$RESTIC_BACKUP_TAG" "${extra_args[@]}" | grep -i 'total size:' | cut -d ':' -f2 | xargs) # xargs acts as trim
|
||||
latest_snapshot_diff=$(restic snapshots --tag "$RESTIC_BACKUP_TAG" --latest 2 --compact "${extra_args[@]}" \
|
||||
| grep -Ei "^[abcdef0-9]{8} " \
|
||||
| awk '{print $1}' \
|
||||
| tail -2 \
|
||||
| tr '\n' ' ' \
|
||||
| xargs restic diff)
|
||||
| xargs restic diff "${extra_args[@]}")
|
||||
added=$(echo "$latest_snapshot_diff" | grep -i 'added:' | awk '{print $2 " " $3}')
|
||||
removed=$(echo "$latest_snapshot_diff" | grep -i 'removed:' | awk '{print $2 " " $3}')
|
||||
|
||||
|
||||
@@ -43,3 +43,10 @@ export RESTIC_RETENTION_YEARS=3
|
||||
#RESTIC_BACKUP_EXTRA_ARGS="--exclude-file /path/to/extra/exclude/file/a --exclude-file /path/to/extra/exclude/file/b"
|
||||
# Example: exclude all directories that have a .git/ directory inside it.
|
||||
#RESTIC_BACKUP_EXTRA_ARGS="--exclude-if-present .git"
|
||||
|
||||
# Optional extra space-separated arguments to all restic commands, i.e. global arguments.
|
||||
# Example: Limit download speed to a maximum of 1000 KiB/s
|
||||
#RESTIC_EXTRA_ARGS="--limit-download 1000"
|
||||
# Example: Set custom sftp parameters or a custom path.
|
||||
#RESTIC_EXTRA_ARGS="--option sftp.command='ssh\ backup-host\ -s\ sftp'"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user