├── LICENSE
├── Makefile
├── README.md
├── bin
└── snap-sync
├── find_snapper_config
└── man8
└── snap-sync.8
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # snap-sync
2 | # https://github.com/wesbarnett/snap-sync
3 | # Copyright (C) 2016-2018 Wes Barnett
4 |
5 | # This program is free software; you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation; either version 2 of the License, or
8 | # (at your option) any later version.
9 |
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 |
15 | # You should have received a copy of the GNU General Public License along
16 | # with this program; if not, write to the Free Software Foundation, Inc.,
17 |
18 | PKGNAME = snap-sync
19 | PREFIX ?= /usr
20 | SNAPPER_CONFIG ?= /etc/sysconfig/snapper
21 |
22 | BIN_DIR = $(DESTDIR)$(PREFIX)/bin
23 | SYSTEMD_DIR = $(DESTDIR)$(PREFIX)/lib/systemd/system
24 | SHARE_DIR = $(DESTDIR)$(PREFIX)/share
25 |
26 | .PHONY: install
27 |
28 | install:
29 | @./find_snapper_config || sed -i 's@^SNAPPER_CONFIG.*@SNAPPER_CONFIG='$(SNAPPER_CONFIG)'@g' bin/$(PKGNAME)
30 | @install -Dm644 LICENSE -t $(SHARE_DIR)/licenses/$(PKGNAME)/
31 | @install -Dm644 README.md -t $(SHARE_DIR)/doc/$(PKGNAME)/
32 | @install -Dm644 man8/* -t $(SHARE_DIR)/man/man8/
33 | @install -Dm755 bin/* -t $(BIN_DIR)/
34 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # snap-sync
2 |
3 | This bash script sends incremental snapshots to another drive for backing up
4 | data. Plug in and mount any btrfs-formatted device you want your system to be
5 | backed up to (like a USB drive). When you run the script you will be prompted
6 | to select a mounted btrfs device, or you can optionally select the disk using
7 | its UUID on the command line.
8 |
9 | The script iterates through all snapper configurations by default (this can be
10 | changed using the `-c` flag). For each configuration it creates a new local
11 | snapshot. If you have never synced to the specified device you will be prompted
12 | to enter a directory on the device where the backup snapshots will go.
13 | Additionally you are shown the location of the backed up snapshot. If you have
14 | performed a backup to this device before, only the changes since the last backup
15 | have to be sent.
16 |
17 | ## Installation
18 |
19 | ### Arch Linux
20 |
21 | Install the `snap-sync` package using pacman if using Arch Linux.
22 |
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
30 | run `make install`. snapper is required.
31 |
32 | If your system uses a non-default location for the snapper
33 | configuration file, specify it on the command line with
34 | `SNAPPER_CONFIG`. For example, for Arch Linux use
35 |
36 | make SNAPPER_CONFIG=/etc/conf.d/snapper install
37 |
38 | Starting with release 0.6, the tarballs are signed with my key with fingerprint
39 | `F7B28C61944FE30DABEEB0B01070BCC98C18BD66` ([public key]). Previous tarballs and commits
40 | used a different key with fingerprint `8535CEF3F3C38EE69555BF67E4B5E45AA3B8C5C3`.
41 |
42 | ## Documentation
43 |
44 | See `snap-sync(8)` after installation.
45 |
46 | ## Troubleshooting
47 |
48 | After reviewing the man page, check the [issues page] and file a new issue if your
49 | problem is not covered.
50 |
51 | ## Contributing
52 |
53 | Help wanted! Feel free to fork and issue a pull request to add features or
54 | tackle an open issue.
55 |
56 | ## Related projects
57 |
58 | See [@rzerres's fork] which has several enhancments.
59 |
60 | [this Copr]: https://copr.fedorainfracloud.org/coprs/peoinas/snap-sync/
61 | [@brndd]: https://github.com/brndd
62 | [releases page]: https://github.com/wesbarnett/snap-sync/releases
63 | [public key]: https://barnett.science/public-key.asc
64 | [issues page]: https://github.com/wesbarnett/snap-sync/issues
65 | [@rzerres's fork]: https://github.com/rzerres/snap-sync
66 |
--------------------------------------------------------------------------------
/bin/snap-sync:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # snap-sync
3 | # https://github.com/wesbarnett/snap-sync
4 | # Copyright (C) 2016-2021 Wes Barnett
5 |
6 | # This program is free software; you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation; either version 2 of the License, or
9 | # (at your option) any later version.
10 |
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 |
16 | # You should have received a copy of the GNU General Public License along
17 | # with this program; if not, write to the Free Software Foundation, Inc.,
18 |
19 | # -------------------------------------------------------------------------
20 |
21 | # Takes snapshots of each snapper configuration. It then sends the snapshot to
22 | # a location on an external drive. After the initial transfer, it does
23 | # incremental snapshots on later calls. It's important not to delete the
24 | # snapshot created on your system since that will be used to determine the
25 | # difference for the next incremental snapshot.
26 |
27 | set -o errtrace
28 |
29 | version="0.7"
30 | name="snap-sync"
31 |
32 | printf "\nsnap-sync version %s, Copyright (C) 2016-2021 Wes Barnett\n" "$version"
33 | printf "snap-sync comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the license for more information. \n\n"
34 |
35 | # The following line is modified by the Makefile or
36 | # find_snapper_config script
37 | SNAPPER_CONFIG=/etc/conf.d/snapper
38 |
39 | TMPDIR=$(mktemp -d)
40 | PIPE=$TMPDIR/$name.out
41 | mkfifo $PIPE
42 | systemd-cat -t "$name" < $PIPE &
43 | exec 3>$PIPE
44 |
45 | donotify=0
46 | which notify-send &> /dev/null
47 | if [[ $? -ne 0 ]]; then
48 | donotify=1
49 | fi
50 |
51 | doprogress=0
52 | which pv &> /dev/null
53 | if [[ $? -ne 0 ]]; then
54 | doprogress=1
55 | fi
56 |
57 | error() {
58 | printf "==> ERROR: %s\n" "$@"
59 | notify_error 'Error' 'Check journal for more information.'
60 | } >&2
61 |
62 | die() {
63 | error "$@"
64 | exit 1
65 | }
66 |
67 | traperror() {
68 | printf "Exited due to error on line %s.\n" $1
69 | printf "exit status: %s\n" "$2"
70 | printf "command: %s\n" "$3"
71 | printf "bash line: %s\n" "$4"
72 | printf "function name: %s\n" "$5"
73 | exit 1
74 | }
75 |
76 | trapkill() {
77 | die "Exited due to user intervention."
78 | }
79 |
80 | trap 'traperror ${LINENO} $? "$BASH_COMMAND" $BASH_LINENO "${FUNCNAME[@]}"' ERR
81 | trap trapkill SIGTERM SIGINT
82 |
83 | usage() {
84 | cat < snapper configuration to backup
90 | -d, --description snapper description
91 | -h, --help print this message
92 | -n, --noconfirm do not ask for confirmation
93 | -k, --keepold keep old incremental snapshots instead of deleting them
94 | after backup is performed
95 | -p, --port remote port; wsed with '--remote'.
96 | -q, --quiet do not send notifications; instead print them.
97 | -r, --remote ip address of a remote machine to backup to
98 | --sudo use sudo on the remote machine
99 | -s, --subvolid subvolume id of the mounted BTRFS subvolume to back up to
100 | -u, --UUID UUID of the mounted BTRFS subvolume to back up to
101 |
102 | See 'man snap-sync' for more details.
103 | EOF
104 | }
105 |
106 | ssh=""
107 | sudo=0
108 | while [[ $# -gt 0 ]]; do
109 | key="$1"
110 | case $key in
111 | -d|--description)
112 | description="$2"
113 | shift 2
114 | ;;
115 | -c|--config)
116 | selected_configs="$2"
117 | shift 2
118 | ;;
119 | -u|--UUID)
120 | uuid_cmdline="$2"
121 | shift 2
122 | ;;
123 | -s|--subvolid)
124 | subvolid_cmdline="$2"
125 | shift 2
126 | ;;
127 | -k|--keepold)
128 | keep="yes"
129 | shift
130 | ;;
131 | -n|--noconfirm)
132 | noconfirm="yes"
133 | shift
134 | ;;
135 | -h|--help)
136 | usage
137 | exit 1
138 | ;;
139 | -q|--quiet)
140 | donotify=1
141 | shift
142 | ;;
143 | -r|--remote)
144 | remote=$2
145 | shift 2
146 | ;;
147 | -p|--port)
148 | port=$2
149 | shift 2
150 | ;;
151 | --sudo)
152 | sudo=1
153 | shift
154 | ;;
155 | *)
156 | die "Unknown option: '$key'. Run '$name -h' for valid options."
157 | ;;
158 | esac
159 | done
160 |
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 |
185 | [[ $EUID -ne 0 ]] && die "Script must be run as root. See '$name -h' for a description of options"
186 | ! [[ -f $SNAPPER_CONFIG ]] && die "$SNAPPER_CONFIG does not exist."
187 |
188 | description=${description:-"latest incremental backup"}
189 | uuid_cmdline=${uuid_cmdline:-"none"}
190 | subvolid_cmdline=${subvolid_cmdline:-"5"}
191 | noconfirm=${noconfirm:-"no"}
192 |
193 | if [[ "$uuid_cmdline" != "none" ]]; then
194 | if [[ -z $remote ]]; then
195 | notify_info "Backup started" "Starting backups to $uuid_cmdline subvolid=$subvolid_cmdline..."
196 | else
197 | notify_info "Backup started" "Starting backups to $uuid_cmdline subvolid $subvolid_cmdline at $remote..."
198 | fi
199 | else
200 | if [[ -z $remote ]]; then
201 | notify_info "Backup started" "Starting backups. Use command line menu to select disk."
202 | else
203 | notify_info "Backup started" "Starting backups. Use command line menu to select disk on $remote."
204 | fi
205 | fi
206 |
207 | if [[ -n $remote ]]; then
208 | ssh="ssh $remote"
209 | if [[ -n $port ]]; then
210 | ssh="$ssh -p $port"
211 | fi
212 | if [[ $sudo -eq 1 ]]; then
213 | ssh="$ssh sudo"
214 | fi
215 | fi
216 |
217 | if [[ "$($ssh findmnt -n -v --target / -o FSTYPE)" == "btrfs" ]]; then
218 | EXCLUDE_UUID=$($ssh findmnt -n -v -t btrfs --target / -o UUID)
219 | TARGETS=$($ssh findmnt -n -v -t btrfs -o UUID,TARGET --list | grep -v $EXCLUDE_UUID | awk '{print $2}')
220 | UUIDS=$($ssh findmnt -n -v -t btrfs -o UUID,TARGET --list | grep -v $EXCLUDE_UUID | awk '{print $1}')
221 | else
222 | TARGETS=$($ssh findmnt -n -v -t btrfs -o TARGET --list)
223 | UUIDS=$($ssh findmnt -n -v -t btrfs -o UUID --list)
224 | fi
225 |
226 | declare -a TARGETS_ARRAY
227 | declare -a UUIDS_ARRAY
228 | declare -a SUBVOLIDS_ARRAY
229 |
230 | i=0
231 | for x in $TARGETS; do
232 | SUBVOLIDS_ARRAY[$i]=$($ssh btrfs subvolume show $x | awk '/Subvolume ID:/ { print $3 }')
233 | TARGETS_ARRAY[$i]=$x
234 | i=$((i+1))
235 | done
236 |
237 | i=0
238 | disk=-1
239 | disk_count=0
240 | for x in $UUIDS; do
241 | UUIDS_ARRAY[$i]=$x
242 | if [[ "$x" == "$uuid_cmdline" && ${SUBVOLIDS_ARRAY[$((i))]} == "$subvolid_cmdline" ]]; then
243 | disk=$i
244 | disk_count=$(($disk_count+1))
245 | fi
246 | i=$((i+1))
247 | done
248 |
249 | if [[ "${#UUIDS_ARRAY[$@]}" -eq 0 ]]; then
250 | die "No external btrfs subvolumes found to backup to. Run '$name -h' for more options."
251 | fi
252 |
253 | if [[ "$disk_count" > 1 ]]; then
254 | printf "Multiple mount points were found with UUID %s and subvolid %s.\n" "$uuid_cmdline" "$subvolid_cmdline"
255 | disk="-1"
256 | fi
257 |
258 | if [[ "$disk" == -1 ]]; then
259 | if [[ "$disk_count" == 0 && "$uuid_cmdline" != "none" ]]; then
260 | error "A device with UUID $uuid_cmdline and subvolid $subvolid_cmdline was not found to be mounted, or it is not a BTRFS device."
261 | fi
262 | if [[ -z $ssh ]]; then
263 | printf "Select a mounted BTRFS device on your local machine to backup to.\nFor more options, exit and run '$name -h'.\n"
264 | else
265 | printf "Select a mounted BTRFS device on %s to backup to.\nFor more options, exit and run '$name -h'.\n" "$remote"
266 | fi
267 | while [[ $disk -lt 0 || $disk -gt $i ]]; do
268 | for x in "${!TARGETS_ARRAY[@]}"; do
269 | printf "%4s) %s (uuid=%s, subvolid=%s)\n" "$((x+1))" "${TARGETS_ARRAY[$x]}" "${UUIDS_ARRAY[$x]}" "${SUBVOLIDS_ARRAY[$x]}"
270 | done
271 | printf "%4s) Exit\n" "0"
272 | read -e -r -p "Enter a number: " disk
273 | if ! [[ $disk == ?(-)+([0-9]) ]] || [[ $disk -lt 0 || $disk -gt $i ]]; then
274 | printf "\nNo disk selected. Select a disk to continue.\n"
275 | disk=-1
276 | fi
277 | done
278 | if [[ $disk == 0 ]]; then
279 | exit 0
280 | fi
281 | disk=$(($disk-1))
282 | fi
283 |
284 | selected_subvolid="${SUBVOLIDS_ARRAY[$((disk))]}"
285 | selected_uuid="${UUIDS_ARRAY[$((disk))]}"
286 | selected_mnt="${TARGETS_ARRAY[$((disk))]}"
287 | printf "\nYou selected the disk with uuid=%s, subvolid=%s.\n" "$selected_uuid" "$selected_subvolid" | tee $PIPE
288 | if [[ -z $ssh ]]; then
289 | printf "The disk is mounted at '%s'.\n" "$selected_mnt" | tee $PIPE
290 | else
291 | printf "The disk is mounted at '%s:%s'.\n" "$remote" "$selected_mnt" | tee $PIPE
292 | fi
293 |
294 | source $SNAPPER_CONFIG
295 |
296 | if [[ -z $selected_configs ]]; then
297 | printf "\nInteractively cycling through all snapper configurations...\n"
298 | fi
299 | selected_configs=${selected_configs:-$SNAPPER_CONFIGS}
300 |
301 | declare -a BACKUPDIRS_ARRAY
302 | declare -a MYBACKUPDIR_ARRAY
303 | declare -a OLD_NUM_ARRAY
304 | declare -a OLD_SNAP_ARRAY
305 | declare -a NEW_NUM_ARRAY
306 | declare -a NEW_SNAP_ARRAY
307 | declare -a NEW_INFO_ARRAY
308 | declare -a BACKUPLOC_ARRAY
309 | declare -a CONT_BACKUP_ARRAY
310 |
311 | # Initial configuration of where backup directories are
312 | i=0
313 | for x in $selected_configs; do
314 |
315 | if [[ "$(snapper -c $x list -t single | awk '/'"subvolid=$selected_subvolid, uuid=$selected_uuid"'/ {cnt++} END {print cnt}')" -gt 1 ]]; then
316 | error "More than one snapper entry found with UUID $selected_uuid subvolid $selected_subvolid for configuration $x. Skipping configuration $x."
317 | continue
318 | fi
319 |
320 | if [[ "$(snapper -c $x list -t single | awk '/'$name' backup in progress/ {cnt++} END {print cnt}')" -gt 0 ]]; then
321 | printf "\nNOTE: Previous failed %s backup snapshots found for '%s'.\n" "$name" "$x" | tee $PIPE
322 | if [[ $noconfirm == "yes" ]]; then
323 | printf "'noconfirm' option passed. Failed backups will not be deleted.\n" | tee $PIPE
324 | else
325 | read -e -r -p "Delete failed backup snapshot(s)? (These local snapshots from failed backups are not used.) [y/N]? " delete_failed
326 | while [[ -n "$delete_failed" && "$delete_failed" != [Yy]"es" &&
327 | "$delete_failed" != [Yy] && "$delete_failed" != [Nn]"o" &&
328 | "$delete_failed" != [Nn] ]]; do
329 | read -e -r -p "Delete failed backup snapshot(s)? (These local snapshots from failed backups are not used.) [y/N] " delete_failed
330 | if [[ -n "$delete_failed" && "$delete_failed" != [Yy]"es" &&
331 | "$delete_failed" != [Yy] && "$delete_failed" != [Nn]"o" &&
332 | "$delete_failed" != [Nn] ]]; then
333 | printf "Select 'y' or 'N'.\n"
334 | fi
335 | done
336 | if [[ "$delete_failed" == [Yy]"es" || "$delete_failed" == [Yy] ]]; then
337 | snapper -c $x delete $(snapper -c $x list | awk '/'$name' backup in progress/ {print $1}')
338 | fi
339 | fi
340 | fi
341 |
342 | SNAP_SYNC_EXCLUDE=no
343 |
344 | if [[ -f "/etc/snapper/configs/$x" ]]; then
345 | source /etc/snapper/configs/$x
346 | else
347 | die "Selected snapper configuration $x does not exist."
348 | fi
349 |
350 | if [[ $SNAP_SYNC_EXCLUDE == "yes" ]]; then
351 | continue
352 | fi
353 |
354 | printf "\n"
355 |
356 | old_num=$(snapper -c "$x" list -t single | awk '/'"subvolid=$selected_subvolid, uuid=$selected_uuid"'/ {print $1}')
357 | old_snap=$SUBVOLUME/.snapshots/$old_num/snapshot
358 |
359 | OLD_NUM_ARRAY[$i]=$old_num
360 | OLD_SNAP_ARRAY[$i]=$old_snap
361 |
362 | if [[ -z "$old_num" ]]; then
363 | printf "No backups have been performed for '%s' on this disk.\n" "$x"
364 | read -e -r -p "Enter name of subvolume to store backups, relative to $selected_mnt (to be created if not existing): " mybackupdir
365 | printf "This will be the initial backup for snapper configuration '%s' to this disk. This could take awhile.\n" "$x"
366 | BACKUPDIR="$selected_mnt/$mybackupdir"
367 | $ssh test -d "$BACKUPDIR" || $ssh btrfs subvolume create "$BACKUPDIR"
368 | else
369 | mybackupdir=$(snapper -c "$x" list -t single | awk -F"|" '/'"subvolid=$selected_subvolid, uuid=$selected_uuid"'/ {print $5}' | awk -F "," '/backupdir/ {print $1}' | awk -F"=" '{print $2}')
370 | BACKUPDIR="$selected_mnt/$mybackupdir"
371 | $ssh test -d $BACKUPDIR || die "%s is not a directory on %s.\n" "$BACKUPDIR" "$selected_uuid"
372 | fi
373 | BACKUPDIRS_ARRAY[$i]="$BACKUPDIR"
374 | MYBACKUPDIR_ARRAY[$i]="$mybackupdir"
375 |
376 | printf "Creating new local snapshot for '%s' configuration...\n" "$x" | tee $PIPE
377 | new_num=$(snapper -c "$x" create --print-number -d "$name backup in progress")
378 | new_snap=$SUBVOLUME/.snapshots/$new_num/snapshot
379 | new_info=$SUBVOLUME/.snapshots/$new_num/info.xml
380 | sync
381 | backup_location=$BACKUPDIR/$x/$new_num/
382 | if [[ -z $ssh ]]; then
383 | printf "Will backup %s to %s\n" "$new_snap" "$backup_location/snapshot" | tee $PIPE
384 | else
385 | printf "Will backup %s to %s\n" "$new_snap" "$remote":"$backup_location/snapshot" | tee $PIPE
386 | fi
387 |
388 | if ($ssh test -d "$backup_location/snapshot") ; then
389 | printf "WARNING: Backup directory '%s' already exists. This configuration will be skipped!\n" "$backup_location/snapshot" | tee $PIPE
390 | printf "Move or delete destination directory and try backup again.\n" | tee $PIPE
391 | fi
392 |
393 | NEW_NUM_ARRAY[$i]="$new_num"
394 | NEW_SNAP_ARRAY[$i]="$new_snap"
395 | NEW_INFO_ARRAY[$i]="$new_info"
396 | BACKUPLOC_ARRAY[$i]="$backup_location"
397 |
398 | cont_backup="K"
399 | CONT_BACKUP_ARRAY[$i]="yes"
400 | if [[ $noconfirm == "yes" ]]; then
401 | cont_backup="yes"
402 | else
403 | while [[ -n "$cont_backup" && "$cont_backup" != [Yy]"es" &&
404 | "$cont_backup" != [Yy] && "$cont_backup" != [Nn]"o" &&
405 | "$cont_backup" != [Nn] ]]; do
406 | read -e -r -p "Proceed with backup of '$x' configuration [Y/n]? " cont_backup
407 | if [[ -n "$cont_backup" && "$cont_backup" != [Yy]"es" &&
408 | "$cont_backup" != [Yy] && "$cont_backup" != [Nn]"o" &&
409 | "$cont_backup" != [Nn] ]]; then
410 | printf "Select 'Y' or 'n'.\n"
411 | fi
412 | done
413 | fi
414 |
415 | if [[ "$cont_backup" != [Yy]"es" && "$cont_backup" != [Yy] && -n "$cont_backup" ]]; then
416 | CONT_BACKUP_ARRAY[$i]="no"
417 | printf "Not backing up '%s' configuration.\n" $x
418 | snapper -c $x delete $new_num
419 | fi
420 |
421 | i=$(($i+1))
422 |
423 | done
424 |
425 | # Actual backing up
426 | printf "\nPerforming backups...\n" | tee $PIPE
427 | i=-1
428 | for x in $selected_configs; do
429 |
430 | i=$(($i+1))
431 |
432 | SNAP_SYNC_EXCLUDE=no
433 |
434 | if [[ -f "/etc/snapper/configs/$x" ]]; then
435 | source /etc/snapper/configs/$x
436 | else
437 | die "Selected snapper configuration $x does not exist."
438 | fi
439 |
440 | cont_backup=${CONT_BACKUP_ARRAY[$i]}
441 | if [[ $cont_backup == "no" || $SNAP_SYNC_EXCLUDE == "yes" ]]; then
442 | notify_info "Backup in progress" "NOTE: Skipping $x configuration."
443 | continue
444 | fi
445 |
446 | notify_info "Backup in progress" "Backing up $x configuration."
447 |
448 | printf "\n"
449 |
450 | old_num="${OLD_NUM_ARRAY[$i]}"
451 | old_snap="${OLD_SNAP_ARRAY[$i]}"
452 | BACKUPDIR="${BACKUPDIRS_ARRAY[$i]}"
453 | mybackupdir="${MYBACKUPDIR_ARRAY[$i]}"
454 | new_num="${NEW_NUM_ARRAY[$i]}"
455 | new_snap="${NEW_SNAP_ARRAY[$i]}"
456 | new_info="${NEW_INFO_ARRAY[$i]}"
457 | backup_location="${BACKUPLOC_ARRAY[$i]}"
458 |
459 | if ($ssh test -d "$backup_location/snapshot") ; then
460 | printf "ERROR: Backup directory '%s' already exists. Skipping backup of this configuration!\n" "$backup_location/snapshot" | tee $PIPE
461 | continue
462 | fi
463 |
464 | $ssh mkdir -p $backup_location
465 |
466 | if [[ -z "$old_num" ]]; then
467 | printf "Sending first snapshot for '%s' configuration...\n" "$x" | tee $PIPE
468 | if [[ $doprogress -eq 0 ]]; then
469 | btrfs send "$new_snap" | pv | $ssh btrfs receive "$backup_location" &>/dev/null
470 | else
471 | btrfs send "$new_snap" | $ssh btrfs receive "$backup_location" &>/dev/null
472 | fi
473 | else
474 |
475 | printf "Sending incremental snapshot for '%s' configuration...\n" "$x" | tee $PIPE
476 | # Sends the difference between the new snapshot and old snapshot to the
477 | # backup location. Using the -c flag instead of -p tells it that there
478 | # is an identical subvolume to the old snapshot at the receiving
479 | # location where it can get its data. This helps speed up the transfer.
480 |
481 | if [[ $doprogress -eq 0 ]]; then
482 | btrfs send -c "$old_snap" "$new_snap" | pv | $ssh btrfs receive "$backup_location"
483 | else
484 | btrfs send -c "$old_snap" "$new_snap" | $ssh btrfs receive "$backup_location"
485 | fi
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 |
495 | fi
496 |
497 | if [[ -z $remote ]]; then
498 | cp "$new_info" "$backup_location"
499 | else
500 | if [[ -z $port ]]; then
501 | rsync -avzq "$new_info" "$remote":"$backup_location"
502 | else
503 | rsync -avzqe "ssh -p $port" "$new_info" "$remote":"$backup_location"
504 | fi
505 | fi
506 |
507 | # It's important not to change this userdata in the snapshots, since that's how
508 | # we find the previous one.
509 |
510 | userdata="backupdir=$mybackupdir, subvolid=$selected_subvolid, uuid=$selected_uuid"
511 |
512 | # Tag new snapshot as the latest
513 | printf "Tagging local snapshot as latest backup for '%s' configuration...\n" "$x" | tee $PIPE
514 | snapper -v -c "$x" modify -d "$description" -u "$userdata" "$new_num"
515 |
516 | printf "Backup complete for '%s' configuration.\n" "$x" > $PIPE
517 |
518 | done
519 |
520 | printf "\nDone!\n" | tee $PIPE
521 | exec 3>&-
522 |
523 | if [[ "$uuid_cmdline" != "none" ]]; then
524 | notify_info "Finished" "Backups to $uuid_cmdline complete!"
525 | else
526 | notify_info "Finished" "Backups complete!"
527 | fi
528 |
--------------------------------------------------------------------------------
/find_snapper_config:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | etcdirs="sysconfig default conf.d"
4 |
5 | for x in $etcdirs; do
6 | d=/etc/$x/snapper
7 | if [[ -f $d ]]; then
8 | sed -i 's@^SNAPPER_CONFIG.*@SNAPPER_CONFIG='$d'@g' bin/snap-sync
9 | exit 0
10 | fi
11 | done
12 |
13 | printf "==> Unable to find snapper configuration file in a standard location.\n"
14 | printf "==> Using SNAPPER_CONFIG make variable.\n"
15 | exit 1
16 |
--------------------------------------------------------------------------------
/man8/snap-sync.8:
--------------------------------------------------------------------------------
1 | '\" t
2 | .TH SNAP-SYNC 8 2021-01-24 SNAP-SYNC
3 | .SH NAME
4 | snap-sync \- send incremental btrfs snapshots, keeping track of them with snapper
5 |
6 | .SH SYNOPSIS
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]
18 |
19 | .SH DESCRIPTION
20 |
21 | This program sends incremental snapshots to another drive for backing up data. Plug in
22 | and mount any btrfs-formatted device you want your system to be backed up to (like a
23 | USB drive). When you run the script you will be prompted to select a mounted btrfs
24 | device, or you can optionally select the disk using its UUID on the command line.
25 |
26 | The script iterates through all snapper configurations by default (this can be changed
27 | using the \fI-c\fR flag). For each configuration it creates a new local snapshot. If you
28 | have never synced to the specified device you will be prompted to enter a directory on
29 | the device where the backup snapshots will go. Additionally you are shown the location
30 | of the backed up snapshot. If you have performed a backup to this device before, only
31 | the changes since the last backup have to be sent.
32 |
33 | Use `snapper` to view the snapshots for a subvolume you have backed up. A snapshots with
34 | the description `Latest incremental backup` is kept on our local machine so that the
35 | next time `snap-sync` runs it will only transfer the difference between it and a new
36 | snapshot. Don't manually delete that snapshot unless you want to do an entirely new
37 | backup, transferring all of the data again.
38 |
39 | .SH OPTIONS
40 |
41 | \fB\-c, \-\-config\fR \fIconfig\fR
42 | .RS 4
43 | Specify the snapper configuration to use. Otherwise will perform for each snapper
44 | configuration. Can list multiple configurations within quotes, space-separated (e.g. -c
45 | "root home").
46 | .RE
47 | .PP
48 |
49 | \fB\-d, \-\-description\fR \fIdesc\fR
50 | .RS 4
51 | Change the snapper description. Default: "latest incremental backup"
52 | .RE
53 | .PP
54 |
55 | \fB\-h, \-\-help\fR
56 | .RS 4
57 | Print the help message.
58 | .RE
59 | .PP
60 |
61 | \fB\-n, \-\-noconfirm
62 | .RS 4
63 | Do not ask for confirmation for each configuration. Will still prompt for backup
64 | directory name on first backup.
65 | .RE
66 | .PP
67 |
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 |
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
91 | .RS 4
92 | Send the snapshot backup to a remote machine. The snapshot will be sent via ssh. You
93 | should specify the remote machine's hostname or ip address. The 'root' user must be
94 | permitted to login on the remote machine.
95 | .RE
96 | .PP
97 |
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
105 | .RS 4
106 | Specify the subvolume id of the mounted BTRFS subvolume to back up to. Defaults to 5.
107 | .RE
108 | .PP
109 |
110 | \fB\-u, \-\-UUID\fR \fIUUID\fR
111 | .RS 4
112 | Specify the UUID of the mounted BTRFS subvolume to back up to. Otherwise will prompt.
113 | If multiple mount points are found with the same UUID and subvolid, will prompt user.
114 | .RE
115 | .PP
116 |
117 | .SH EXAMPLES
118 | .PP
119 | \fBsnap-sync\fR
120 | .RS 4
121 | Get prompted interactively on what disks to backup to and what snapshots to send.
122 | .RE
123 |
124 | .PP
125 | .B
126 | snap-sync
127 | \fB--UUID\fR \fI7360922b-c916-4d9f-a670-67fe0b91143c\fR \fB--subvolid\fR \fI5\fR
128 | \fB--noconfirm\fR
129 | .RS 4
130 | Specify the UUID and subvolume of the external disk, backing up all subvolumes with a
131 | snapper configuration without promptin for confirmation.
132 | .RE
133 |
134 | .SH FAQ
135 | .SS How do I run this program on a schedule automatically?
136 | You can create systemd unit and timer. Here is an example service:
137 |
138 | .EX
139 |
140 | [Unit]
141 | Description=Run snap-sync backup
142 |
143 | [Install]
144 | WantedBy=multi-user.target
145 |
146 | [Service]
147 | Type=simple
148 | ExecStart=/usr/bin/snap-sync --UUID 7360922b-c916-4d9f-a670-67fe0b91143c --subvolid 5 --noconfirm
149 |
150 | .EE
151 |
152 | And here is its corresponding timer:
153 |
154 | .EX
155 |
156 | [Unit]
157 | Description=Run snap-sync weekly
158 |
159 | [Timer]
160 | OnCalendar=weekly
161 | AccuracySec=12h
162 | Persistent=true
163 |
164 | [Install]
165 | WantedBy=timers.target
166 |
167 | .EE
168 |
169 |
170 | .SH HOMEPAGE
171 | https://github.com/wesbarnett/snap-sync
172 |
173 | .SH AUTHORS
174 | Wes Barnett wes@wbarnett.us
175 |
176 | .SH SEE ALSO
177 | .BR btrfs-send (8),
178 | .BR snapper (8)
179 |
--------------------------------------------------------------------------------