Skip to content

Commit

Permalink
Merge branch 'master' into feature/progress
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbarnett committed Jan 24, 2021
2 parents 0fdb276 + 6e70f0e commit 0c9c589
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 40 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ have to be sent.

## Installation

### Arch Linux

Install the `snap-sync` package using pacman if using Arch Linux.

Alternatively, download the latest release and signature from the [releases page], verify the download, and then
### Fedora

Install the `snap-sync` package from [this Copr] created by [@brndd].

### Manual

Download the latest release and signature from the [releases page], verify the download, and then
run `make install`. snapper is required.

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


## Documentation

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

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

[this Copr]: https://copr.fedorainfracloud.org/coprs/peoinas/snap-sync/
[@brndd]: https://github.com/brndd
[releases page]: https://github.com/wesbarnett/snap-sync/releases
[public key]: https://barnett.science/public-key.asc
[issues page]: https://github.com/wesbarnett/snap-sync/issues
Expand Down
80 changes: 53 additions & 27 deletions bin/snap-sync
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,6 @@ if [[ $? -ne 0 ]]; then
doprogress=1
fi

notify() {
for u in $(users | tr ' ' '\n' | sort -u); do
sudo -u $u DISPLAY=:0 \
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus \
notify-send -a $name "$1" "$2" --icon="dialog-$3"
done
}

notify_info() {
if [[ $donotify -eq 0 ]]; then
notify "$1" "$2" "information"
else
printf "$1: $2\n"
fi
}

notify_error() {
if [[ $donotify -eq 0 ]]; then
notify "$1" "$2" "error"
else
printf "$1: $2\n"
fi
}

error() {
printf "==> ERROR: %s\n" "$@"
notify_error 'Error' 'Check journal for more information.'
Expand Down Expand Up @@ -114,17 +90,21 @@ 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
--sudo use sudo on the remote machine
-s, --subvolid <subvlid> subvolume id of the mounted BTRFS subvolume to back up to
-u, --UUID <UUID> UUID of the mounted BTRFS subvolume to back up to
See 'man snap-sync' for more details.
EOF
}


ssh=""
sudo=0
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
Expand All @@ -144,13 +124,21 @@ while [[ $# -gt 0 ]]; do
subvolid_cmdline="$2"
shift 2
;;
-k|--keepold)
keep="yes"
shift
;;
-n|--noconfirm)
noconfirm="yes"
shift
;;
-h|--help)
usage
exit 1
;;
-q|--quiet)
donotify=1
shift
;;
-r|--remote)
remote=$2
Expand All @@ -160,12 +148,40 @@ while [[ $# -gt 0 ]]; do
port=$2
shift 2
;;
--sudo)
sudo=1
shift
;;
*)
die "Unknown option: '$key'. Run '$name -h' for valid options."
;;
esac
done

notify() {
for u in $(users | tr ' ' '\n' | sort -u); do
sudo -u $u DISPLAY=:0 \
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus \
notify-send -a $name "$1" "$2" --icon="dialog-$3"
done
}

notify_info() {
if [[ $donotify -eq 0 ]]; then
notify "$1" "$2" "information"
else
printf "$1: $2\n"
fi
}

notify_error() {
if [[ $donotify -eq 0 ]]; then
notify "$1" "$2" "error"
else
printf "$1: $2\n"
fi
}

[[ $EUID -ne 0 ]] && die "Script must be run as root. See '$name -h' for a description of options"
! [[ -f $SNAPPER_CONFIG ]] && die "$SNAPPER_CONFIG does not exist."

Expand Down Expand Up @@ -193,6 +209,9 @@ if [[ -n $remote ]]; then
if [[ -n $port ]]; then
ssh="$ssh -p $port"
fi
if [[ $sudo -eq 1 ]]; then
ssh="$ssh sudo"
fi
fi

if [[ "$($ssh findmnt -n -v --target / -o FSTYPE)" == "btrfs" ]]; then
Expand Down Expand Up @@ -464,8 +483,15 @@ for x in $selected_configs; do
else
btrfs send -c "$old_snap" "$new_snap" | $ssh btrfs receive "$backup_location"
fi
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
57 changes: 46 additions & 11 deletions man8/snap-sync.8
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
snap-sync \- send incremental btrfs snapshots, keeping track of them with snapper

.SH SYNOPSIS
snap-sync [-c <config>] [-d <desc>] [-n] [-r <address>] [-s <subvolid>] [-u UUID]
.B snap-sync
[\fB-c\fR \fIconfig\fR]
[\fB-d\fR \fIdesc\fR]
[\fB-n\fR]
[\fB-r\fR \fIaddress\fR]
[\fB-p\fR \fIport\fR]
[\fB--sudo\fR]
[\fB-s\fR \fIsubvolid\fR]
[\fB-u\fR \fIUUID\fR]
[\fB-k\fR]
[\fB-q\fR]

.SH DESCRIPTION

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

.SH OPTIONS

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

\fB\-d, \-\-description\fR <desc>
\fB\-d, \-\-description\fR \fIdesc\fR
.RS 4
Change the snapper description. Default: "latest incremental backup"
.RE
Expand All @@ -55,27 +65,49 @@ directory name on first backup.
.RE
.PP

\fB\-p, \-\-port\fR <port>
\fB\-k, \-\-keepold\fR
.RS 4
The remote port. Used with '--remote'.
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\-r, \-\-remote\fR <address>
\fB\-p, \-\-port\fR \fIport\fR
.RS 4
The remote port. Used with \fB--remote\fR.
.RE
.PP

\fB\-q, \-\-quiet\fR
.RS 4
Do not send notifications to notify system if it is available. Instead print
notifications to stdout.
.RE
.PP

\fB\-r, \-\-remote\fR \fIaddress\fR
.RS 4
Send the snapshot backup to a remote machine. The snapshot will be sent via ssh. You
should specify the remote machine's hostname or ip address. The 'root' user must be
permitted to login on the remote machine.
.RE
.PP

\fB\-s, \-\-subvolid\fR <subvolid>
\fB\-\-sudo\fR
.RS 4
Use sudo on the remote machine. Only valid when used with the \fB\-\-remote\fR flag.
.RE
.PP

\fB\-s, \-\-subvolid\fR \fIsubvolid\fR
.RS 4
Specify the subvolume id of the mounted BTRFS subvolume to back up to. Defaults to 5.
.RE
.PP

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

.SH EXAMPLES
.PP
snap-sync
\fBsnap-sync\fR
.RS 4
Get prompted interactively on what disks to backup to and what snapshots to send.
.RE

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

.SH AUTHORS
Wes Barnett <[email protected]>
Wes Barnett [email protected]

.SH SEE ALSO
.BR btrfs-send (8),
Expand Down

0 comments on commit 0c9c589

Please sign in to comment.