Skip to content

Commit 6e70f0e

Browse files
authored
Merge pull request #92 from wesbarnett/feature/deleteold
Delete old snapshots by default, but have option to keep them
2 parents a28f90e + 71ca8d2 commit 6e70f0e

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

bin/snap-sync

+15-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ Options:
8484
-d, --description <desc> snapper description
8585
-h, --help print this message
8686
-n, --noconfirm do not ask for confirmation
87+
-k, --keepold keep old incremental snapshots instead of deleting them
88+
after backup is performed
8789
-p, --port <port> remote port; wsed with '--remote'.
8890
-q, --quiet do not send notifications; instead print them.
8991
-r, --remote <address> ip address of a remote machine to backup to
@@ -116,6 +118,10 @@ while [[ $# -gt 0 ]]; do
116118
subvolid_cmdline="$2"
117119
shift 2
118120
;;
121+
-k|--keepold)
122+
keep="yes"
123+
shift
124+
;;
119125
-n|--noconfirm)
120126
noconfirm="yes"
121127
shift
@@ -464,8 +470,15 @@ for x in $selected_configs; do
464470
# location where it can get its data. This helps speed up the transfer.
465471

466472
btrfs send -c "$old_snap" "$new_snap" | $ssh btrfs receive "$backup_location"
467-
printf "Modifying data for old local snapshot for '%s' configuration...\n" "$x" | tee $PIPE
468-
snapper -v -c "$x" modify -d "old snap-sync snapshot (you may remove)" -u "backupdir=,subvolid=,uuid=" -c "number" "$old_num"
473+
474+
if [[ $keep == "yes" ]]; then
475+
printf "Modifying data for old local snapshot for '%s' configuration...\n" "$x" | tee $PIPE
476+
snapper -v -c "$x" modify -d "old snap-sync snapshot (you may remove)" -u "backupdir=,subvolid=,uuid=" -c "number" "$old_num"
477+
else
478+
printf "Deleting old snapshot for %s...\n" "$x" | tee $PIPE
479+
snapper -c "$x" delete "$old_num"
480+
fi
481+
469482
fi
470483

471484
if [[ -z $remote ]]; then

man8/snap-sync.8

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ snap-sync \- send incremental btrfs snapshots, keeping track of them with snappe
1313
[\fB--sudo\fR]
1414
[\fB-s\fR \fIsubvolid\fR]
1515
[\fB-u\fR \fIUUID\fR]
16+
[\fB-k\fR]
1617
[\fB-q\fR]
1718

1819
.SH DESCRIPTION
@@ -64,6 +65,15 @@ directory name on first backup.
6465
.RE
6566
.PP
6667

68+
\fB\-k, \-\-keepold\fR
69+
.RS 4
70+
Keep the most recent local snapshot which is no longer needed. By default, after a
71+
backup is performed for a snapper configuration, the previous local snapshot is deleted
72+
since a new local snapshot is created. It's not necessary to keep all of those
73+
snapshots, but if you pass this flag, it will be kept.
74+
.RE
75+
.PP
76+
6777
\fB\-p, \-\-port\fR \fIport\fR
6878
.RS 4
6979
The remote port. Used with \fB--remote\fR.

0 commit comments

Comments
 (0)