forked from extern/zfs-auto-snapshot
commit
45edfd3e7c
@ -107,7 +107,7 @@ print_usage ()
|
|||||||
-R, --replication Use zfs's replication (zfs send -R) instead of simple send over newly created snapshots (check man zfs for details).
|
-R, --replication Use zfs's replication (zfs send -R) instead of simple send over newly created snapshots (check man zfs for details).
|
||||||
-f is used automatically.
|
-f is used automatically.
|
||||||
-v, --verbose Print info messages.
|
-v, --verbose Print info messages.
|
||||||
-f, --force Passes -F argument to zfs receive
|
-f, --force Passes -F argument to zfs receive (e.g. makes possible to overwrite remote filesystem during --send-full)
|
||||||
name Filesystem and volume names, or '//' for all ZFS datasets.
|
name Filesystem and volume names, or '//' for all ZFS datasets.
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
@ -281,16 +281,14 @@ do_send ()
|
|||||||
local REMOTEFS="$5"
|
local REMOTEFS="$5"
|
||||||
local list_child=('')
|
local list_child=('')
|
||||||
|
|
||||||
if [ "$SENDFLAGS" = "-R" ]; then
|
if [ "$SENDFLAGS" = "-R" -a "$SENDTYPE" = "full" ]; then
|
||||||
# for full send with -R, target filesystem must be without snapshots including chilren as well
|
# for full send with -R, target filesystem must be with no snapshots (including snapshots on child filesystems)
|
||||||
list_child=($(printf "%s\n" "${SNAPSHOTS_OLD_REM[@]}" | grep ^"$REMOTEFS" | grep @))
|
list_child=( $(printf "%s\n" "${SNAPSHOTS_OLD_REM[@]}" | grep ^"$REMOTEFS/" ) )
|
||||||
if [ "$SENDTYPE" = "full" ]; then
|
|
||||||
list_child=( "${list_child[@]}" $(printf "%s\n" "${ZFS_REMOTE_LIST[@]}" | grep ^"$REMOTEFS" | sort -r ))
|
|
||||||
fi
|
|
||||||
elif [ "$SENDTYPE" = "full" ]; then
|
|
||||||
list_child=( $(printf "%s\n" "${SNAPSHOTS_OLD_REM[@]}" | grep ^"$REMOTEFS@" ) )
|
|
||||||
fi
|
fi
|
||||||
|
if [ "$SENDTYPE" = "full" ]; then
|
||||||
|
list_child=( ${list_child[@]} $(printf "%s\n" "${SNAPSHOTS_OLD_REM[@]}" | grep ^"$REMOTEFS@" ) )
|
||||||
|
fi
|
||||||
|
|
||||||
for ll in ${list_child[@]}; do
|
for ll in ${list_child[@]}; do
|
||||||
if do_delete "remote" "$ll" ""; then
|
if do_delete "remote" "$ll" ""; then
|
||||||
continue
|
continue
|
||||||
@ -341,7 +339,14 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
|
|||||||
|
|
||||||
LAST_REMOTE=$(printf "%s\n" ${SNAPSHOTS_OLD_REM[@]} | grep ^$opt_sendprefix/$ii@ | grep -m1 . | awk -F'@' '{print $2}')
|
LAST_REMOTE=$(printf "%s\n" ${SNAPSHOTS_OLD_REM[@]} | grep ^$opt_sendprefix/$ii@ | grep -m1 . | awk -F'@' '{print $2}')
|
||||||
|
|
||||||
# remote filesystem just created. if -R run
|
# in case of -R and incremental send, receiving side needs to have $LAST_REMOTE snapshot for each replicated filesystem
|
||||||
|
if [ "$FLAGS" = "-r" ]; then
|
||||||
|
snaps_needed=$(( $(printf "%s\n" ${ZFS_LIST_LOC[@]} | grep ^"$ii/") + 1 ))
|
||||||
|
else
|
||||||
|
snaps_needed='1'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# remote filesystem just created. if -R run
|
||||||
if ! is_member "${CREATED_TARGETS[*]}" "$opt_sendprefix/$ii"
|
if ! is_member "${CREATED_TARGETS[*]}" "$opt_sendprefix/$ii"
|
||||||
then
|
then
|
||||||
FALLBACK='2'
|
FALLBACK='2'
|
||||||
@ -349,8 +354,8 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
|
|||||||
then
|
then
|
||||||
# no snapshot on remote
|
# no snapshot on remote
|
||||||
FALLBACK='1'
|
FALLBACK='1'
|
||||||
# last snapshot on remote is no more available on local, this applies both for -r and non -r runs
|
elif [ "$snaps_needed" -ne $(printf "%s\n" ${SNAPSHOTS_OLD_REM[@]} | grep -c -e ^"$opt_sendprefix/$ii$SNexp@$LAST_REMOTE" ) -o \
|
||||||
elif [ $(printf "%s\n" "${SNAPSHOTS_OLD_REM[@]}" | grep -c -e ^$opt_sendprefix/$ii$SNexp@$LAST_REMOTE ) -ne $(printf "%s\n" "${SNAPSHOTS_OLD_LOC[@]}" | grep -c -e ^$ii$SNexp@$LAST_REMOTE ) ]
|
"$snaps_needed" -ne $(printf "%s\n" ${SNAPSHOTS_OLD_LOC[@]} | grep -c -e ^"$ii$SNexp@$LAST_REMOTE" ) ]
|
||||||
then
|
then
|
||||||
FALLBACK='3'
|
FALLBACK='3'
|
||||||
else
|
else
|
||||||
@ -365,10 +370,14 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
|
|||||||
print_log info "Going back to full send, remote filesystem was just created: $ii"
|
print_log info "Going back to full send, remote filesystem was just created: $ii"
|
||||||
;;
|
;;
|
||||||
(3)
|
(3)
|
||||||
print_log info "Going back to full send, last snapshot on remote is not available on local: $opt_sendprefix/$ii@$LAST_REMOTE"
|
if [ "$FLAGS" = "-r" ]; then
|
||||||
;;
|
print_log info "Going back to full send, last snapshot on remote is not the last one for whole recursion: $opt_sendprefix/$ii@$LAST_REMOTE"
|
||||||
|
else
|
||||||
|
print_log info "Going back to full send, last snapshot on remote is not available on local: $opt_sendprefix/$ii@$LAST_REMOTE"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
(0)
|
(0)
|
||||||
do_send "incr" "$ii@$LAST_REMOTE" "$ii@$NAME" "$sFLAGS" "$opt_sendprefix/$ii"
|
do_send "incr" "$ii@$LAST_REMOTE" "$ii@$NAME" "$sFLAGS" "$opt_sendprefix/$ii"
|
||||||
SND_RC="$?"
|
SND_RC="$?"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -412,7 +421,7 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
|
|||||||
continue
|
continue
|
||||||
elif [ "$sFLAGS" = "-R" ]
|
elif [ "$sFLAGS" = "-R" ]
|
||||||
then
|
then
|
||||||
print_log debug "Replication specified, snapshots were removed while sending."
|
print_log debug "Replication specified, remote snapshots were removed while sending."
|
||||||
continue
|
continue
|
||||||
elif [ "$opt_destroy" -eq '1' -a "$FALLBACK" -ne '0' -o "$opt_send" = "full" ]
|
elif [ "$opt_destroy" -eq '1' -a "$FALLBACK" -ne '0' -o "$opt_send" = "full" ]
|
||||||
then
|
then
|
||||||
@ -687,12 +696,12 @@ then
|
|||||||
exit 133
|
exit 133
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f ${tmp_file_prefix%%X*}* ]; then
|
if [ -f "${tmp_file_prefix%%X*}"* ]; then
|
||||||
print_log error "another copy is running ..."
|
print_log error "another copy is running ..."
|
||||||
exit 99
|
exit 99
|
||||||
fi
|
fi
|
||||||
LOCKFILE=`mktemp $tmp_file_prefix`
|
LOCKFILE=$(mktemp $tmp_file_prefix)
|
||||||
trap "rm -f $LOCKFILE; exit $?" INT TERM EXIT
|
trap "rm -f '$LOCKFILE'; exit $?" INT TERM EXIT
|
||||||
|
|
||||||
# Count the number of times '//' appears on the command line.
|
# Count the number of times '//' appears on the command line.
|
||||||
SLASHIES='0'
|
SLASHIES='0'
|
||||||
@ -819,32 +828,30 @@ do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
for jj in $NOAUTO
|
noauto_parent='0'
|
||||||
|
for jj in $NOAUTO
|
||||||
do
|
do
|
||||||
# Ibid regarding iii.
|
# Ibid regarding iii.
|
||||||
jjj="$jj/"
|
jjj="$jj/"
|
||||||
|
|
||||||
# The --recursive switch only matters for non-wild arguments.
|
if [ "$jjj" = "$iii" ]
|
||||||
if [ -z "$opt_recursive" -a "$1" != '//' ]
|
then
|
||||||
then
|
|
||||||
# Snapshot this dataset non-recursively.
|
|
||||||
print_log debug "Including $ii for regular snapshot."
|
|
||||||
TARGETS_DREGULAR=( ${TARGETS_DREGULAR[@]} $( printf "%s\n" $ii))
|
|
||||||
continue 2
|
|
||||||
# Check whether the candidate name is excluded
|
|
||||||
elif [ "$jjj" = "$iii" ]
|
|
||||||
then
|
|
||||||
continue 2
|
continue 2
|
||||||
# Check whether the candidate name is a prefix of any excluded dataset name.
|
# Check whether the candidate name is a prefix of any excluded dataset name.
|
||||||
elif [ "$jjj" != "${jjj#$iii}" ]
|
elif [ "$jjj" != "${jjj#$iii}" ]
|
||||||
then
|
then
|
||||||
# Snapshot this dataset non-recursively.
|
noauto_parent='1' && break
|
||||||
print_log debug "Including $ii for regular snapshot."
|
fi
|
||||||
TARGETS_DREGULAR=( ${TARGETS_DREGULAR[@]} $( printf "%s\n" $ii))
|
|
||||||
continue 2
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# not scrubbing
|
||||||
|
if [ -z "$opt_recursive" -a "$1" != '//' -o "$noauto_parent" = '1' ]
|
||||||
|
then
|
||||||
|
print_log debug "Including $ii for regular snapshot."
|
||||||
|
TARGETS_DREGULAR=( ${TARGETS_DREGULAR[@]} $( printf "%s\n" $ii))
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
for jj in ${TARGETS_TMP_RECURSIVE[@]}
|
for jj in ${TARGETS_TMP_RECURSIVE[@]}
|
||||||
do
|
do
|
||||||
# Ibid regarding iii.
|
# Ibid regarding iii.
|
||||||
@ -901,7 +908,7 @@ test -n "$opt_dry_run" \
|
|||||||
# expand FS list if replication is not used
|
# expand FS list if replication is not used
|
||||||
if [ "$opt_recursive" = ' ' -o "$1" = "//" ]
|
if [ "$opt_recursive" = ' ' -o "$1" = "//" ]
|
||||||
then
|
then
|
||||||
for ii in "${TARGETS_TMP_RECURSIVE[@]}"; do TARGETS_DRECURSIVE=( ${TARGETS_DRECURSIVE[@]} $(printf "%s\n" ${ZFS_LOCAL_LIST[@]} | grep ^$ii) ); done
|
for ii in ${TARGETS_TMP_RECURSIVE[@]}; do TARGETS_DRECURSIVE=( ${TARGETS_DRECURSIVE[@]} $(printf "$ii\n") $(printf "%s\n" ${ZFS_LOCAL_LIST[@]} | grep ^"$ii/") ); done
|
||||||
else
|
else
|
||||||
TARGETS_DRECURSIVE=( ${TARGETS_TMP_RECURSIVE[@]} )
|
TARGETS_DRECURSIVE=( ${TARGETS_TMP_RECURSIVE[@]} )
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user