Skip to content

Commit

Permalink
Merge pull request #92 from wesbarnett/feature/deleteold
Browse files Browse the repository at this point in the history
Delete old snapshots by default, but have option to keep them
  • Loading branch information
wesbarnett authored Jan 24, 2021
2 parents a28f90e + 71ca8d2 commit 6e70f0e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
17 changes: 15 additions & 2 deletions bin/snap-sync
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ Options:
-d, --description <desc> snapper description
-h, --help print this message
-n, --noconfirm do not ask for confirmation
-k, --keepold keep old incremental snapshots instead of deleting them
after backup is performed
-p, --port <port> remote port; wsed with '--remote'.
-q, --quiet do not send notifications; instead print them.
-r, --remote <address> ip address of a remote machine to backup to
Expand Down Expand Up @@ -116,6 +118,10 @@ while [[ $# -gt 0 ]]; do
subvolid_cmdline="$2"
shift 2
;;
-k|--keepold)
keep="yes"
shift
;;
-n|--noconfirm)
noconfirm="yes"
shift
Expand Down Expand Up @@ -464,8 +470,15 @@ for x in $selected_configs; do
# location where it can get its data. This helps speed up the transfer.

btrfs send -c "$old_snap" "$new_snap" | $ssh btrfs receive "$backup_location"
printf "Modifying data for old local snapshot for '%s' configuration...\n" "$x" | tee $PIPE
snapper -v -c "$x" modify -d "old snap-sync snapshot (you may remove)" -u "backupdir=,subvolid=,uuid=" -c "number" "$old_num"

if [[ $keep == "yes" ]]; then
printf "Modifying data for old local snapshot for '%s' configuration...\n" "$x" | tee $PIPE
snapper -v -c "$x" modify -d "old snap-sync snapshot (you may remove)" -u "backupdir=,subvolid=,uuid=" -c "number" "$old_num"
else
printf "Deleting old snapshot for %s...\n" "$x" | tee $PIPE
snapper -c "$x" delete "$old_num"
fi

fi

if [[ -z $remote ]]; then
Expand Down
10 changes: 10 additions & 0 deletions man8/snap-sync.8
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ snap-sync \- send incremental btrfs snapshots, keeping track of them with snappe
[\fB--sudo\fR]
[\fB-s\fR \fIsubvolid\fR]
[\fB-u\fR \fIUUID\fR]
[\fB-k\fR]
[\fB-q\fR]

.SH DESCRIPTION
Expand Down Expand Up @@ -64,6 +65,15 @@ directory name on first backup.
.RE
.PP

\fB\-k, \-\-keepold\fR
.RS 4
Keep the most recent local snapshot which is no longer needed. By default, after a
backup is performed for a snapper configuration, the previous local snapshot is deleted
since a new local snapshot is created. It's not necessary to keep all of those
snapshots, but if you pass this flag, it will be kept.
.RE
.PP

\fB\-p, \-\-port\fR \fIport\fR
.RS 4
The remote port. Used with \fB--remote\fR.
Expand Down

0 comments on commit 6e70f0e

Please sign in to comment.