Skip to content

Commit 0c9c589

Browse files
committed
Merge branch 'master' into feature/progress
2 parents 0fdb276 + 6e70f0e commit 0c9c589

File tree

3 files changed

+110
-40
lines changed

3 files changed

+110
-40
lines changed

README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@ have to be sent.
1616

1717
## Installation
1818

19+
### Arch Linux
20+
1921
Install the `snap-sync` package using pacman if using Arch Linux.
2022

21-
Alternatively, download the latest release and signature from the [releases page], verify the download, and then
23+
### Fedora
24+
25+
Install the `snap-sync` package from [this Copr] created by [@brndd].
26+
27+
### Manual
28+
29+
Download the latest release and signature from the [releases page], verify the download, and then
2230
run `make install`. snapper is required.
2331

2432
If your system uses a non-default location for the snapper
@@ -31,7 +39,6 @@ Starting with release 0.6, the tarballs are signed with my key with fingerprint
3139
`F7B28C61944FE30DABEEB0B01070BCC98C18BD66` ([public key]). Previous tarballs and commits
3240
used a different key with fingerprint `8535CEF3F3C38EE69555BF67E4B5E45AA3B8C5C3`.
3341

34-
3542
## Documentation
3643

3744
See `snap-sync(8)` after installation.
@@ -50,6 +57,8 @@ tackle an open issue.
5057

5158
See [@rzerres's fork] which has several enhancments.
5259

60+
[this Copr]: https://copr.fedorainfracloud.org/coprs/peoinas/snap-sync/
61+
[@brndd]: https://github.com/brndd
5362
[releases page]: https://github.com/wesbarnett/snap-sync/releases
5463
[public key]: https://barnett.science/public-key.asc
5564
[issues page]: https://github.com/wesbarnett/snap-sync/issues

bin/snap-sync

+53-27
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,6 @@ if [[ $? -ne 0 ]]; then
5454
doprogress=1
5555
fi
5656

57-
notify() {
58-
for u in $(users | tr ' ' '\n' | sort -u); do
59-
sudo -u $u DISPLAY=:0 \
60-
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus \
61-
notify-send -a $name "$1" "$2" --icon="dialog-$3"
62-
done
63-
}
64-
65-
notify_info() {
66-
if [[ $donotify -eq 0 ]]; then
67-
notify "$1" "$2" "information"
68-
else
69-
printf "$1: $2\n"
70-
fi
71-
}
72-
73-
notify_error() {
74-
if [[ $donotify -eq 0 ]]; then
75-
notify "$1" "$2" "error"
76-
else
77-
printf "$1: $2\n"
78-
fi
79-
}
80-
8157
error() {
8258
printf "==> ERROR: %s\n" "$@"
8359
notify_error 'Error' 'Check journal for more information.'
@@ -114,17 +90,21 @@ Options:
11490
-d, --description <desc> snapper description
11591
-h, --help print this message
11692
-n, --noconfirm do not ask for confirmation
93+
-k, --keepold keep old incremental snapshots instead of deleting them
94+
after backup is performed
11795
-p, --port <port> remote port; wsed with '--remote'.
96+
-q, --quiet do not send notifications; instead print them.
11897
-r, --remote <address> ip address of a remote machine to backup to
98+
--sudo use sudo on the remote machine
11999
-s, --subvolid <subvlid> subvolume id of the mounted BTRFS subvolume to back up to
120100
-u, --UUID <UUID> UUID of the mounted BTRFS subvolume to back up to
121101
122102
See 'man snap-sync' for more details.
123103
EOF
124104
}
125105

126-
127106
ssh=""
107+
sudo=0
128108
while [[ $# -gt 0 ]]; do
129109
key="$1"
130110
case $key in
@@ -144,13 +124,21 @@ while [[ $# -gt 0 ]]; do
144124
subvolid_cmdline="$2"
145125
shift 2
146126
;;
127+
-k|--keepold)
128+
keep="yes"
129+
shift
130+
;;
147131
-n|--noconfirm)
148132
noconfirm="yes"
149133
shift
150134
;;
151135
-h|--help)
152136
usage
153137
exit 1
138+
;;
139+
-q|--quiet)
140+
donotify=1
141+
shift
154142
;;
155143
-r|--remote)
156144
remote=$2
@@ -160,12 +148,40 @@ while [[ $# -gt 0 ]]; do
160148
port=$2
161149
shift 2
162150
;;
151+
--sudo)
152+
sudo=1
153+
shift
154+
;;
163155
*)
164156
die "Unknown option: '$key'. Run '$name -h' for valid options."
165157
;;
166158
esac
167159
done
168160

161+
notify() {
162+
for u in $(users | tr ' ' '\n' | sort -u); do
163+
sudo -u $u DISPLAY=:0 \
164+
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus \
165+
notify-send -a $name "$1" "$2" --icon="dialog-$3"
166+
done
167+
}
168+
169+
notify_info() {
170+
if [[ $donotify -eq 0 ]]; then
171+
notify "$1" "$2" "information"
172+
else
173+
printf "$1: $2\n"
174+
fi
175+
}
176+
177+
notify_error() {
178+
if [[ $donotify -eq 0 ]]; then
179+
notify "$1" "$2" "error"
180+
else
181+
printf "$1: $2\n"
182+
fi
183+
}
184+
169185
[[ $EUID -ne 0 ]] && die "Script must be run as root. See '$name -h' for a description of options"
170186
! [[ -f $SNAPPER_CONFIG ]] && die "$SNAPPER_CONFIG does not exist."
171187

@@ -193,6 +209,9 @@ if [[ -n $remote ]]; then
193209
if [[ -n $port ]]; then
194210
ssh="$ssh -p $port"
195211
fi
212+
if [[ $sudo -eq 1 ]]; then
213+
ssh="$ssh sudo"
214+
fi
196215
fi
197216

198217
if [[ "$($ssh findmnt -n -v --target / -o FSTYPE)" == "btrfs" ]]; then
@@ -464,8 +483,15 @@ for x in $selected_configs; do
464483
else
465484
btrfs send -c "$old_snap" "$new_snap" | $ssh btrfs receive "$backup_location"
466485
fi
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"
486+
487+
if [[ $keep == "yes" ]]; then
488+
printf "Modifying data for old local snapshot for '%s' configuration...\n" "$x" | tee $PIPE
489+
snapper -v -c "$x" modify -d "old snap-sync snapshot (you may remove)" -u "backupdir=,subvolid=,uuid=" -c "number" "$old_num"
490+
else
491+
printf "Deleting old snapshot for %s...\n" "$x" | tee $PIPE
492+
snapper -c "$x" delete "$old_num"
493+
fi
494+
469495
fi
470496

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

man8/snap-sync.8

+46-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44
snap-sync \- send incremental btrfs snapshots, keeping track of them with snapper
55

66
.SH SYNOPSIS
7-
snap-sync [-c <config>] [-d <desc>] [-n] [-r <address>] [-s <subvolid>] [-u UUID]
7+
.B snap-sync
8+
[\fB-c\fR \fIconfig\fR]
9+
[\fB-d\fR \fIdesc\fR]
10+
[\fB-n\fR]
11+
[\fB-r\fR \fIaddress\fR]
12+
[\fB-p\fR \fIport\fR]
13+
[\fB--sudo\fR]
14+
[\fB-s\fR \fIsubvolid\fR]
15+
[\fB-u\fR \fIUUID\fR]
16+
[\fB-k\fR]
17+
[\fB-q\fR]
818

919
.SH DESCRIPTION
1020

@@ -28,15 +38,15 @@ backup, transferring all of the data again.
2838

2939
.SH OPTIONS
3040

31-
\fB\-c, \-\-config\fR <config>
41+
\fB\-c, \-\-config\fR \fIconfig\fR
3242
.RS 4
3343
Specify the snapper configuration to use. Otherwise will perform for each snapper
3444
configuration. Can list multiple configurations within quotes, space-separated (e.g. -c
3545
"root home").
3646
.RE
3747
.PP
3848

39-
\fB\-d, \-\-description\fR <desc>
49+
\fB\-d, \-\-description\fR \fIdesc\fR
4050
.RS 4
4151
Change the snapper description. Default: "latest incremental backup"
4252
.RE
@@ -55,27 +65,49 @@ directory name on first backup.
5565
.RE
5666
.PP
5767

58-
\fB\-p, \-\-port\fR <port>
68+
\fB\-k, \-\-keepold\fR
5969
.RS 4
60-
The remote port. Used with '--remote'.
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.
6174
.RE
6275
.PP
6376

64-
\fB\-r, \-\-remote\fR <address>
77+
\fB\-p, \-\-port\fR \fIport\fR
78+
.RS 4
79+
The remote port. Used with \fB--remote\fR.
80+
.RE
81+
.PP
82+
83+
\fB\-q, \-\-quiet\fR
84+
.RS 4
85+
Do not send notifications to notify system if it is available. Instead print
86+
notifications to stdout.
87+
.RE
88+
.PP
89+
90+
\fB\-r, \-\-remote\fR \fIaddress\fR
6591
.RS 4
6692
Send the snapshot backup to a remote machine. The snapshot will be sent via ssh. You
6793
should specify the remote machine's hostname or ip address. The 'root' user must be
6894
permitted to login on the remote machine.
6995
.RE
7096
.PP
7197

72-
\fB\-s, \-\-subvolid\fR <subvolid>
98+
\fB\-\-sudo\fR
99+
.RS 4
100+
Use sudo on the remote machine. Only valid when used with the \fB\-\-remote\fR flag.
101+
.RE
102+
.PP
103+
104+
\fB\-s, \-\-subvolid\fR \fIsubvolid\fR
73105
.RS 4
74106
Specify the subvolume id of the mounted BTRFS subvolume to back up to. Defaults to 5.
75107
.RE
76108
.PP
77109

78-
\fB\-u, \-\-UUID\fR <UUID>
110+
\fB\-u, \-\-UUID\fR \fIUUID\fR
79111
.RS 4
80112
Specify the UUID of the mounted BTRFS subvolume to back up to. Otherwise will prompt.
81113
If multiple mount points are found with the same UUID and subvolid, will prompt user.
@@ -84,13 +116,16 @@ If multiple mount points are found with the same UUID and subvolid, will prompt
84116

85117
.SH EXAMPLES
86118
.PP
87-
snap-sync
119+
\fBsnap-sync\fR
88120
.RS 4
89121
Get prompted interactively on what disks to backup to and what snapshots to send.
90122
.RE
91123

92124
.PP
93-
snap-sync --UUID 7360922b-c916-4d9f-a670-67fe0b91143c --subvolid 5 --noconfirm
125+
.B
126+
snap-sync
127+
\fB--UUID\fR \fI7360922b-c916-4d9f-a670-67fe0b91143c\fR \fB--subvolid\fR \fI5\fR
128+
\fB--noconfirm\fR
94129
.RS 4
95130
Specify the UUID and subvolume of the external disk, backing up all subvolumes with a
96131
snapper configuration without promptin for confirmation.
@@ -136,7 +171,7 @@ And here is its corresponding timer:
136171
https://github.com/wesbarnett/snap-sync
137172

138173
.SH AUTHORS
139-
Wes Barnett <[email protected]>
174+
Wes Barnett [email protected]
140175

141176
.SH SEE ALSO
142177
.BR btrfs-send (8),

0 commit comments

Comments
 (0)