-
-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added prune based on backup count to tar/rsync #194
Conversation
note: as a side effect, the prune section can ignore day counts at 0 or less
simplify time sort Co-authored-by: Geoff Bourne <[email protected]>
scripts/opt/backup-loop.sh
Outdated
|
||
if [ -n "${PRUNE_BACKUPS_COUNT}" ] && [ "${PRUNE_BACKUPS_COUNT}" -gt 0 ]; then | ||
log INFO "Pruning backup files to keep only the latest ${PRUNE_BACKUPS_COUNT} backups" | ||
_find_extra_backups | xargs -0 -I {} sh -c 'rm -v "{}"' | log INFO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part
xargs -0 -I {} sh -c 'rm -v "{}"'
seems overly complicated. Maybe it could just be
_find_extra_backups | xargs -0 -I {} sh -c 'rm -v "{}"' | log INFO | |
_find_extra_backups | xargs -n 1 rm -v | log INFO |
scripts/opt/backup-loop.sh
Outdated
find "${DEST_DIR}" -maxdepth 1 -type d ! -path "${DEST_DIR}" -print0 | \ | ||
xargs -0 stat --format '%Y %n' | \ | ||
sort -n | \ | ||
awk '{print $2}' | \ | ||
tail -n +$((PRUNE_BACKUPS_COUNT + 1)) | \ | ||
tr '\n' '\0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please apply similar change here
scripts/opt/backup-loop.sh
Outdated
|
||
if [ -n "${PRUNE_BACKUPS_COUNT}" ] && [ "${PRUNE_BACKUPS_COUNT}" -gt 0 ]; then | ||
log INFO "Pruning backup files to keep only the latest ${PRUNE_BACKUPS_COUNT} backups" | ||
_find_extra_backups | xargs -0 -I {} sh -c 'rm -rv "{}"' | awk -v dest_dir="${DEST_DIR}" ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and here, if you're good with the suggestion above
Co-authored-by: Geoff Bourne <[email protected]>
scripts/opt/backup-loop.sh
Outdated
@@ -25,6 +25,7 @@ fi | |||
: "${TAR_COMPRESS_METHOD:=gzip}" # bzip2 gzip zstd | |||
: "${ZSTD_PARAMETERS:=-3 --long=25 --single-thread}" | |||
: "${PRUNE_BACKUPS_DAYS:=7}" | |||
"${PRUNE_BACKUPS_COUNT:=}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, missing the colon at the start of the line. It's an obscure bash syntax to perform a no-op.
ive got a test script, and im getting issues with the changes
output:
|
turns out xargs seems to behave slightly differently when inputs are directories?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these latest changes ready to go? Thank you again for the extra testing with the suggested changes.
should be |
based on local tests of the functions it works ok, but if someone else can verify it that would be great, I don't often work in bash so im not 100% on things
also, I only did tar/rsync since I have even less of an idea of how rustic and rclone are doing stuff