-
Notifications
You must be signed in to change notification settings - Fork 244
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
Remove 'label' (eg frequent/hourly/daily etc) from snapshot name and place in snapshot property #22
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,7 +148,8 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...] | |
local GLOB="$4" | ||
local TARGETS="$5" | ||
local KEEP='' | ||
|
||
local LABEL="$6" | ||
|
||
# global DESTRUCTION_COUNT | ||
# global SNAPSHOT_COUNT | ||
# global WARNING_COUNT | ||
|
@@ -168,25 +169,29 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...] | |
# including the one that was just recently created. | ||
test -z "$opt_keep" && continue | ||
KEEP="$opt_keep" | ||
|
||
# ASSERT: The old snapshot list is sorted by increasing age. | ||
for jj in $SNAPSHOTS_OLD | ||
# Match on both $GLOB *and* label. | ||
while IFS=' ' read -ra arrjj | ||
do | ||
# Check whether this is an old snapshot of the filesystem. | ||
if [ -z "${jj#$ii@$GLOB}" ] | ||
if [ -z "${arrjj[1]#$ii@$GLOB}" ] | ||
then | ||
# Check whether the snapshot has the same label property | ||
test "${arrjj[0]}" = "$LABEL" || continue | ||
|
||
KEEP=$(( $KEEP - 1 )) | ||
if [ "$KEEP" -le '0' ] | ||
then | ||
if do_run "zfs destroy $FLAGS '$jj'" | ||
if do_run "zfs destroy $FLAGS '${arrjj[1]}'" | ||
then | ||
DESTRUCTION_COUNT=$(( $DESTRUCTION_COUNT + 1 )) | ||
else | ||
WARNING_COUNT=$(( $WARNING_COUNT + 1 )) | ||
fi | ||
fi | ||
fi | ||
done | ||
done <<< "$SNAPSHOTS_OLD" | ||
done | ||
} | ||
|
||
|
@@ -347,10 +352,10 @@ ZFS_LIST=$(env LC_ALL=C zfs list -H -t filesystem,volume -s name \ | |
|
||
if [ -n "$opt_fast_zfs_list" ] | ||
then | ||
SNAPSHOTS_OLD=$(env LC_ALL=C zfs list -H -t snapshot -o name -s name|grep $opt_prefix |awk '{ print substr( $0, length($0) - 14, length($0) ) " " $0}' |sort -r -k1,1 -k2,2|awk '{ print substr( $0, 17, length($0) )}') \ | ||
SNAPSHOTS_OLD=$(env LC_ALL=C zfs list -H -t snapshot -o com.sun:auto-snapshot-label,name -s name|grep $opt_prefix |awk '{ print substr( $0, length($0) - 14, length($0) ) " " $0}' |sort -r -k1,1 -k3,2|awk '{ print substr( $0, 17, length($0) )}') \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. produce the listing with label first, then name, so the awk/sort stuff works correctly |
||
|| { print_log error "zfs list $?: $SNAPSHOTS_OLD"; exit 137; } | ||
else | ||
SNAPSHOTS_OLD=$(env LC_ALL=C zfs list -H -t snapshot -S creation -o name) \ | ||
SNAPSHOTS_OLD=$(env LC_ALL=C zfs list -H -t snapshot -S creation -o com.sun:auto-snapshot-label,name) \ | ||
|| { print_log error "zfs list $?: $SNAPSHOTS_OLD"; exit 137; } | ||
fi | ||
|
||
|
@@ -500,17 +505,17 @@ done | |
|
||
# Linux lacks SMF and the notion of an FMRI event, but always set this property | ||
# because the SUNW program does. The dash character is the default. | ||
SNAPPROP="-o com.sun:auto-snapshot-desc='$opt_event'" | ||
SNAPPROP="-o com.sun:auto-snapshot-desc='$opt_event' -o com.sun:auto-snapshot-label=$opt_label" | ||
|
||
# ISO style date; fifteen characters: YYYY-MM-DD-HHMM | ||
# On Solaris %H%M expands to 12h34. | ||
DATE=$(date --utc +%F-%H%M) | ||
|
||
# The snapshot name after the @ symbol. | ||
SNAPNAME="$opt_prefix${opt_label:+$opt_sep$opt_label-$DATE}" | ||
SNAPNAME="$opt_prefix$opt_sep$DATE" | ||
|
||
# The expression for matching old snapshots. -YYYY-MM-DD-HHMM | ||
SNAPGLOB="$opt_prefix${opt_label:+?$opt_label}????????????????" | ||
SNAPGLOB="${opt_prefix}????????????????" | ||
|
||
test -n "$TARGETS_REGULAR" \ | ||
&& print_log info "Doing regular snapshots of $TARGETS_REGULAR" | ||
|
@@ -521,8 +526,8 @@ test -n "$TARGETS_RECURSIVE" \ | |
test -n "$opt_dry_run" \ | ||
&& print_log info "Doing a dry run. Not running these commands..." | ||
|
||
do_snapshots "$SNAPPROP" "" "$SNAPNAME" "$SNAPGLOB" "$TARGETS_REGULAR" | ||
do_snapshots "$SNAPPROP" "-r" "$SNAPNAME" "$SNAPGLOB" "$TARGETS_RECURSIVE" | ||
do_snapshots "$SNAPPROP" "" "$SNAPNAME" "$SNAPGLOB" "$TARGETS_REGULAR" "$opt_label" | ||
do_snapshots "$SNAPPROP" "-r" "$SNAPNAME" "$SNAPGLOB" "$TARGETS_RECURSIVE" "$opt_label" | ||
|
||
print_log notice "@$SNAPNAME," \ | ||
"$SNAPSHOT_COUNT created," \ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
On Debian Wheezy this line gives me a
Syntax error: redirection unexpected
. Thedash
shell does not have the<<<
operator: http://stackoverflow.com/a/2462357/2728336There 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.
The quick workaround for me was to define bash as the specific shell:
#!/bin/sh
->#!/bin/bash
. This might affect Ubuntu also.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.
I've merged @leecallen as per instructions on the wiki and I've changed to /bin/bash but now I'm getting echoed the error "The filesystem argument list is empty." (line 350 is the print)
I'm on Debian 8.8. I've installed via "make install" because after the merge with leecallen it fails to build the deb package
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.
Actually, when running zfs-auto-snapshot using bash without arguments, I did get the error that you mention ("The filesystem argument list is empty"). However, when running it with the correct arguments, it worked fine. I used the following arguments: