├── .github
├── FUNDING.yml
└── workflows
│ └── shellcheck.yml
├── LICENSE
├── README.md
├── backup
├── easybackup.sh
├── tarbackup2-conf.sh
└── tarbackup2.sh
├── monitoring
├── domainwatch.sh
├── portswatch.sh
├── serviceswatch.sh
├── syswatch.sh
└── webwatch.sh
└── photo
├── pimport.sh
├── prename.sh
└── presize.sh
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: jonaski
2 | patreon: jonaskvinge
3 | custom: https://paypal.me/jonaskvinge
4 |
--------------------------------------------------------------------------------
/.github/workflows/shellcheck.yml:
--------------------------------------------------------------------------------
1 | name: shellcheck
2 | on: [push, pull_request]
3 |
4 | jobs:
5 | shellcheck:
6 | name: Shell Check
7 | runs-on: ubuntu-latest
8 | container:
9 | image: opensuse/leap:15.3
10 | steps:
11 | - uses: actions/checkout@v1.2.0
12 | - name: Update packages
13 | run: zypper --non-interactive --gpg-auto-import-keys ref
14 | - name: Install openSUSE dependencies
15 | run: zypper --non-interactive --gpg-auto-import-keys install ShellCheck
16 |
17 | - name: shellcheck
18 | run: |
19 | set -x
20 | for i in $(find . -type f -name '*.sh'); do
21 | shellcheck -s bash --exclude=SC2181 \
22 | --exclude=SC1090 \
23 | --exclude=SC2006 \
24 | --exclude=SC2086 \
25 | --exclude=SC2044 \
26 | --exclude=SC2045 \
27 | --exclude=SC2001 \
28 | --exclude=SC2162 \
29 | --exclude=SC2035 \
30 | --exclude=SC2034 \
31 | --exclude=SC2029 \
32 | --exclude=SC2062 \
33 | --exclude=SC2153 \
34 | $i
35 | done
36 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | :shell: Unix Shell Scripts [](https://github.com/jonaski/shellscripts/actions)
2 | ==========================
3 |
4 | These are some of the various unix shell scripts I've made over the years.
5 |
6 | The rsyncbackup3.sh script has moved to its own repository at https://github.com/jonaski/rsyncbackup
7 |
--------------------------------------------------------------------------------
/backup/easybackup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # easybackup.sh - EASY RSYNC BACKUP SCRIPT
4 | # Copyright (C) 2011-2012 Jonas Kvinge
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 3 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
17 | # along with this program. If not, see .
18 | #
19 | #
20 | # This is a very BASIC terminal rsync backup script.
21 | # You must understand basic shell scripts and rsync.
22 | # Modify it as you wish. USE AT YOUR OWN RISK!!!
23 | #
24 | # rsync options:
25 | #
26 | # Verbose: -v
27 | # Archive: -a (Same as -rlptgoD)
28 | # Recursive: -r
29 | # Checksum: -c
30 | # Time: -t
31 | # Dry run: -n
32 | # Delete: --delete
33 | # Relative path names: -R
34 | #
35 |
36 | version="0.2.5"
37 |
38 | rsyncargs="-va --delete --delete-excluded --itemize-changes"
39 | rsyncargsdry="-van --delete --delete-excluded --itemize-changes"
40 | logfile="/tmp/easybackup-${RANDOM}.log"
41 | backupexclude="\
42 | /tmp
43 | /dev
44 | /proc
45 | /run
46 | /sys
47 | /media
48 | /lost+found
49 | /var/cache
50 | /var/tmp
51 | /var/run
52 | /var/spool/postfix/private
53 | /var/spool/postfix/public
54 | /var/lib/named/lib
55 | /var/lib/named/proc
56 | /var/lib/named/var
57 | /var/lib/named/dev
58 | /var/lib/mysql/mysql.sock
59 | /var/lib/ntp/proc
60 | /var/lib/ntp/dev
61 | /var/lib/dhcp/dev
62 | /var/lib/dhcp/proc
63 | /var/lib/dhcp6/dev
64 | /var/lib/dhcp6/proc
65 | /home/*/.xsession-errors
66 | /home/*/.local/share/Trash
67 | /home/*/.local/share/akonadi
68 | /home/*/.config/google-chrome/Default/Local Storage/*
69 | /home/*/.config/google-chrome/Cookies*
70 | /home/*/.config/google-chrome/History*
71 | /home/*/.config/google-chrome/Default/Application Cache
72 | /home/*/.cache
73 | /home/*/.thumbnails
74 | /home/*/.qt
75 | /home/*/.gvfs
76 | /home/*/.dbus
77 | /home/*/.netx
78 | /home/*/.kde/cache-*
79 | /home/*/.kde/tmp-*
80 | /home/*/.kde/socket-*
81 | /home/*/.kde4/cache-*
82 | /home/*/.kde4/tmp-*
83 | /home/*/.kde4/socket-*
84 | /home/*/.beagle
85 | /home/*/.pulse-cookie
86 | /home/*/.pulse
87 | /home/*/.xine
88 | /home/*/.mcop
89 | /home/*/.java
90 | /home/*/.adobe
91 | /home/*/.macromedia
92 | /home/*/.mozilla/firefox/*/Cache*
93 | /home/*/.opera/cache
94 | /home/*/.mythtv/*cache
95 | /home/*/.xmltv/cache
96 | /home/*/.googleearth
97 | /home/*/.wine
98 | /home/*/.wine_*
99 | /home/*/.kde4/share/apps/nepomuk
100 | /home/*/.kde/share/apps/amarok/albumcovers/cache
101 | /home/*/VirtualBox
102 | /mnt/data/Images
103 | /mnt/data/Backup
104 | /mnt/data/Xerox
105 | "
106 |
107 | ##################### DONT CHANGE ANYTHING BELOW HERE #####################
108 |
109 | backup_logo() {
110 |
111 | tput bold
112 | tput setaf 7
113 |
114 | echo "
115 | ▓█████ ▄▄▄ ██████▓██ ██▓ ▄▄▄▄ ▄▄▄ ▄████▄ ██ ▄█▀ █ ██ ██▓███
116 | ▓█ ▀▒████▄ ▒██ ▒ ▒██ ██▒▓█████▄ ▒████▄ ▒██▀ ▀█ ██▄█▒ ██ ▓██▒▓██░ ██▒
117 | ▒███ ▒██ ▀█▄ ░ ▓██▄ ▒██ ██░▒██▒ ▄██▒██ ▀█▄ ▒▓█ ▄ ▓███▄░ ▓██ ▒██░▓██░ ██▓▒
118 | ▒▓█ ▄░██▄▄▄▄██ ▒ ██▒ ░ ▐██▓░▒██░█▀ ░██▄▄▄▄██ ▒▓▓▄ ▄██▒▓██ █▄ ▓▓█ ░██░▒██▄█▓▒ ▒
119 | ░▒████▒▓█ ▓██▒▒██████▒▒ ░ ██▒▓░░▓█ ▀█▓ ▓█ ▓██▒▒ ▓███▀ ░▒██▒ █▄▒▒█████▓ ▒██▒ ░ ░
120 | ░░ ▒░ ░▒▒ ▓▒█░▒ ▒▓▒ ▒ ░ ██▒▒▒ ░▒▓███▀▒ ▒▒ ▓▒█░░ ░▒ ▒ ░▒ ▒▒ ▓▒░▒▓▒ ▒ ▒ ▒▓▒░ ░ ░
121 | ░ ░ ░ ▒ ▒▒ ░░ ░▒ ░ ░▓██ ░▒░ ▒░▒ ░ ▒ ▒▒ ░ ░ ▒ ░ ░▒ ▒░░░▒░ ░ ░ ░▒ ░
122 | ░ ░ ▒ ░ ░ ░ ▒ ▒ ░░ ░ ░ ░ ▒ ░ ░ ░░ ░ ░░░ ░ ░ ░░
123 | ░ ░ ░ ░ ░ ░ ░ ░ ░ ░░ ░ ░ ░ ░ v${version}
124 | ░ ░ ░ ░
125 |
126 | "
127 |
128 | #echo "
129 | #███████╗ █████╗ ███████╗██╗ ██╗██████╗ █████╗ ██████╗██╗ ██╗██╗ ██╗██████╗
130 | #██╔════╝██╔══██╗██╔════╝╚██╗ ██╔╝██╔══██╗██╔══██╗██╔════╝██║ ██╔╝██║ ██║██╔══██╗
131 | #█████╗ ███████║███████╗ ╚████╔╝ ██████╔╝███████║██║ █████╔╝ ██║ ██║██████╔╝
132 | #██╔══╝ ██╔══██║╚════██║ ╚██╔╝ ██╔══██╗██╔══██║██║ ██╔═██╗ ██║ ██║██╔═══╝
133 | #███████╗██║ ██║███████║ ██║ ██████╔╝██║ ██║╚██████╗██║ ██╗╚██████╔╝██║
134 | #╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝
135 | #"
136 |
137 | tput sgr0
138 |
139 | }
140 |
141 | backup_init() {
142 |
143 | # Find out how to echo without newline
144 |
145 | c=''
146 | n=''
147 | if [ "$(eval echo -n 'a')" = "-n a" ] ; then
148 | c='\c'
149 | else
150 | n='-n'
151 | fi
152 |
153 | # See if the system has the needed commands to continue.
154 |
155 | for cmd in "which" "ls" "mkdir" "mv" "cp" "rm" "sed" "awk" "bc" "tr" "date" "md5sum" "udisksctl" "mount" "blkid"
156 | do
157 | which $cmd >/dev/null 2>&1
158 | if [ $? != 0 ] ; then
159 | echo "ERROR: Missing the \"${cmd}\" command!"
160 | backup_exit
161 | exit 1
162 | fi
163 | done
164 |
165 | # Parse parameters
166 |
167 | script=$(echo "$0" | sed 's/.*\///g')
168 |
169 | while getopts hvRcp:l: o
170 | do case "$o" in
171 | h) echo "Usage: $script -hvdpl "
172 | echo ""
173 | echo "-h Display this help and exit"
174 | echo "-v Display script version and exit"
175 | echo "-p Backup directory on backup disk, ie.: /Backup"
176 | echo "-l Logfile"
177 | echo "-R Relative names (rsync -R)"
178 | echo "-c Checksum (rsync -c)"
179 | echo ""
180 | echo "Examples:"
181 | echo "Source directories = /mnt/data /home/jonas"
182 | echo "Backupdisk labels = backupdisk1 backupdisk2"
183 | echo "The script will pick the first disk in the system that matches one of the disklabels."
184 | echo ""
185 | exit 0;;
186 | v) echo "$script v$version"; backup_exit; exit 0;;
187 | p) backupdir="$OPTARG";;
188 | l) logfile="$OPTARG";;
189 | c) rsyncargs="$rsyncargs -c"; rsyncargsdry="$rsyncargsdry -c";;
190 | R) rsyncargs="$rsyncargs -R"; rsyncargsdry="$rsyncargsdry -R";;
191 | \?) echo "ERROR: Unknown option: $script -h for help."; backup_exit; exit 1;;
192 | esac
193 | done
194 | # Reset $@
195 | shift "$(echo "$OPTIND" - 1 | bc)"
196 |
197 | params="$*"
198 | for param in $params ; do
199 | echo "$param" | grep '/' >/dev/null 2>&1
200 | if [ $? = 0 ]; then
201 | if ! [ "$backupdisks" = "" ]; then
202 | echo "ERROR: You need to specify backup source directory before backup disk labels."
203 | backup_exit
204 | exit 1
205 | fi
206 | ls "$param" >/dev/null 2>&1
207 | if ! [ $? -eq 0 ] ; then
208 | echo "ERROR: File $param does not exist!."
209 | backup_exit
210 | exit 1
211 | fi
212 | if [ "$backupsource" = "" ]; then
213 | backupsource=$param
214 | else
215 | backupsource="$backupsource $param"
216 | fi
217 | else
218 | if [ "$backupdisks" = "" ]; then
219 | backupdisks=$param
220 | else
221 | backupdisks="$backupdisks $param"
222 | fi
223 | fi
224 | done
225 |
226 | if [ "$backupsource" = "" ]; then
227 | echo "ERROR: Missing backupsource."
228 | backup_exit
229 | exit 1
230 | fi
231 | if [ "$backupdisks" = "" ]; then
232 | echo "ERROR: Missing backupdisks."
233 | backup_exit
234 | exit 1
235 | fi
236 | backupsource="$backupsource /dev/null"
237 |
238 | echo "Source: $backupsource"
239 | echo "Backupdisks: $backupdisks"
240 |
241 | rm -f "$backupexcludestmpfile"
242 |
243 | backupexcludestmpfile="/tmp/easybackup-excludes-${RANDOM}.txt"
244 | echo "$backupexclude" >$backupexcludestmpfile || { backup_exit; }
245 |
246 | }
247 |
248 | backup_device() {
249 |
250 | found=0
251 |
252 | while true; do
253 | for i in $backupdisks
254 | do
255 | IFS=$'\n'
256 | for x in $(blkid)
257 | do
258 | device=$(echo "$x" | awk '{print $1}' | sed 's/://g')
259 | label=$(echo "$x" | awk '{print $2}')
260 | echo "$label" | grep '^LABEL=".*"$' >/dev/null 2>&1
261 | if ! [ $? = 0 ]; then
262 | continue
263 | fi
264 | label=$(echo "$label" | sed 's/LABEL=//g' | sed 's/"//g')
265 | if [ "$label" = "$i" ]; then
266 | found=1
267 | break
268 | fi
269 | done
270 | IFS=$' \t\n'
271 | if [ "$found" = "1" ]; then
272 | break
273 | fi
274 | done
275 | if ! [ "$found" = "1" ]; then
276 | read -e -n 1 -p "Insert backupdisk with labels \"$backupdisks\" and press any key to try again."
277 | continue
278 | fi
279 | break
280 | done
281 |
282 | echo "Using backupdisk \"$label\": \"$device\"."
283 |
284 | }
285 |
286 | backup_mount() {
287 |
288 | mountpoint=
289 | mounted=
290 | automounted=
291 | mount=$(mount | grep "^${device}")
292 | if [ "$mount" = "" ]; then
293 | echo $n "Mounting \"$device\". $c"
294 | udisksctl mount -b "$device" || {
295 | echo "ERROR: Unable to mount \"$device\"."
296 | backup_exit
297 | exit 1
298 | }
299 | # udisks may return 0 even when it's not mounted.
300 | mount=$(mount | grep ^${device}.*)
301 | if [ "$mount" = "" ]; then
302 | echo "Failed."
303 | backup_exit
304 | exit 1
305 | fi
306 | mountpoint=$(echo "$mount" | awk '{print $3}')
307 | if [ "$mountpoint" = "" ]; then
308 | echo "Failed to find mountpoint."
309 | echo "ERROR: Unable to find mountpoint for \"$device\"."
310 | backup_exit
311 | exit 1
312 | fi
313 | automounted=1
314 | #echo "$mountpoint."
315 | else
316 | echo $n "Probing \"$device\". $c"
317 | mountpoint=$(echo "$mount" | awk '{print $3}')
318 | if [ "$mountpoint" = "" ]; then
319 | echo "Failed to find mountpoint."
320 | echo "ERROR: Unable to find mountpoint for \"$device\"."
321 | backup_exit
322 | exit 1
323 | fi
324 | echo "$mountpoint."
325 | automounted=0
326 | fi
327 |
328 | echo "Device \"$device\" mounted on \"$mountpoint\"."
329 | mounted=1
330 |
331 | if [ "$backupdir" = "" ]; then
332 | backupdst=$mountpoint
333 | else
334 | echo "$backupdir" | grep '^/.*$' >/dev/null 2>&1
335 | if [ $? = 0 ]; then
336 | backupdst=${mountpoint}${backupdir}
337 | else
338 | backupdst=$mountpoint/$backupdir
339 | fi
340 | if ! [ -d "$backupdst" ]; then
341 | echo "Device \"$device\" missing directory \"$backupdir\"."
342 | backup_exit
343 | exit 1
344 | fi
345 | fi
346 |
347 | while true; do
348 | read -e -n 1 -p "Use $device (Y/N) " answer
349 | case $answer in
350 | [Yy]* ) answer=1;break;;
351 | [Nn]* ) answer=0;break;;
352 | * ) echo "Invalid answer. Press Y or N.";;
353 | esac
354 | if [ "$answer" = "0" ]; then
355 | backup_exit
356 | exit 1
357 | fi
358 | break
359 | done
360 |
361 | }
362 |
363 | backup_dryrun() {
364 |
365 | while true; do
366 | read -e -n 1 -p "DRY RUN first? (Y/N) " answer
367 | case $answer in
368 | [Yy]* ) break;;
369 | [Nn]* ) return 0;;
370 | * ) echo "Invalid answer. Press Y or N.";;
371 | esac
372 | done
373 |
374 | while true; do
375 | read -e -n 1 -p "Running rsync -n $rsyncargsdry --exclude-from=$backupexcludestmpfile $backupsource $backupdst (DRY RUN), continue? (Y/N) " answer
376 | case $answer in
377 | [Yy]* ) break;;
378 | [Nn]* ) backup_exit; exit 1;;
379 | * ) echo "Invalid answer. Press Y or N.";;
380 | esac
381 | done
382 |
383 | echo "BACKUPSOURCE: $backupsource"
384 | echo "BACKUPDST: $backupdst"
385 |
386 | echo "COMMAND: rsync -n $rsyncargsdry --exclude-from=$backupexcludestmpfile $backupsource $backupdst" >>"$logfile"
387 | rsync -n $rsyncargsdry --exclude-from="$backupexcludestmpfile" "$backupsource" "$backupdst" 2>&1 | tee -a "$logfile"
388 |
389 | while true; do
390 | read -e -n 1 -p "Dry run complete, view logfile ($logfile). (Y/N) " answer
391 | case $answer in
392 | [Yy]* )
393 | kate "$logfile" >/dev/null 2>&1 &
394 | break;;
395 | [Nn]* ) break;;
396 | * ) echo "Invalid answer. Press Y or N.";;
397 | esac
398 | done
399 |
400 | while true; do
401 | read -e -n 1 -p "Dry run complete, continue with these changes?. (Y/N) " answer
402 | case $answer in
403 | [Yy]* ) break;;
404 | [Nn]* ) backup_exit; exit 1;;
405 | * ) echo "Invalid answer. Press Y or N.";;
406 | esac
407 | done
408 |
409 | return 0
410 |
411 | }
412 |
413 | backup_run() {
414 |
415 | while true; do
416 | read -e -n 1 -p "Run rsync $rsyncargs --exclude-from=$backupexcludestmpfile $backupsource $backupdst, continue? (Y/N) " answer
417 | case $answer in
418 | [Yy]* ) break;;
419 | [Nn]* ) backup_exit; exit 1;;
420 | * ) echo "Invalid answer. Press Y or N.";;
421 | esac
422 | done
423 |
424 | echo "COMMAND: rsync $rsyncargs --exclude-from=$backupexcludestmpfile $backupsource $backupdst" >>"$logfile"
425 | rsync "$rsyncargs" --exclude-from="$backupexcludestmpfile" "$backupsource" "$backupdst" 2>&1 | tee -a "$logfile"
426 |
427 | return 0
428 |
429 | }
430 |
431 | backup_confirm() {
432 |
433 | while true; do
434 | read -e -n 1 -p "Using backup destination $backupdst, EVERYTHING IN THERE MIGHT BE DELETED OR OVERWRITTEN. ARE YOU SURE? (Y/N) " answer
435 | case $answer in
436 | [Yy]* ) break;;
437 | [Nn]* ) backup_exit; exit 1;;
438 | * ) echo "Invalid answer. Press Y or N.";;
439 | esac
440 | done
441 |
442 | return 0
443 |
444 | }
445 |
446 | backup_exit() {
447 |
448 | rm -f $backupexcludestmpfile
449 | if [ "$automounted" = "1" ]; then
450 | umount "$device"
451 | fi
452 | read -e -n 1 -p "Press any key to exit..."
453 | exit 0
454 |
455 | }
456 |
457 | backup_logo || exit 1
458 | backup_init "$@" || exit 1
459 | backup_device || exit 1
460 | backup_mount || exit 1
461 | backup_confirm || exit 1
462 | backup_dryrun || exit 1
463 | backup_run || exit 1
464 | backup_exit || exit 1
465 |
--------------------------------------------------------------------------------
/backup/tarbackup2-conf.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # tarbackup2-conf.sh - Configuration file for tarbackup2.sh
4 | # Copyright (C) 2011-2012 Jonas Kvinge
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 3 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
17 | # along with this program. If not, see .
18 | #
19 | #
20 | # tarbackup.sh creates a backup specified by backupfileprefix and
21 | # backupfilerevision in b2zipped tar archives.
22 | #
23 | # Files to include in the backups are specified by backupfiles
24 | # the list of files in backupexclude are files to exclude from the
25 | # backup, such as temp files, sockets and cache.
26 | #
27 | # New in version 2: "backuplocations" allows you to specify unlimited
28 | # number of locations and also supports mounting smb and ftp.
29 | # With new success/failure reporting.
30 | #
31 |
32 | backupid="$(hostname -s)" # <--- An unique ID for the backup filename --->
33 | backupdate="$(date '+%Y%m%d-%H%M%S')" # <--- Datestamp in reverse used as the revision for the backup filename --->
34 |
35 | backupfileprefix="abackup-$backupid" # <--- A prefix for the backup filename --->
36 | backupfilerevision=$backupdate # <--- A revision that will increase on each run --->
37 |
38 | backupemailsuccess="root" # <--- Where to send backup success report, set to "0" for no report --->
39 | backupemailfailure="root" # <--- Where to send backup failure report, set to "0" for no report --->
40 | backupemailfailureall="root" # <--- Where to send backup report, set to "0" for no report --->
41 |
42 | backupold2keep=3 # <--- Number of OLD backups to keep after new backup is done, 0 will only keep the NEW backup file and erase all previous backups! --->
43 |
44 | backupmysql=1 # <--- Enable backup of local mysql databases 0/1 --->
45 | backupmysqlfileprefix="abackup-$backupid-mysql" # <--- File prefix for the mysql dump file --->
46 | backupmysqlfilerevision=$backupdate # <--- File revision for the mysql dump file --->
47 | backupmysqlcmd="/usr/bin/mysqldump --all-databases -u root" # <--- Command to dump database --->
48 |
49 | backuppgsql=1 # <--- Enable backup of local postgres databases 0/1 */ --->
50 | backuppgsqlfileprefix="abackup-$backupid-pgsql" # <--- File prefix for the postgres dump file --.>
51 | backuppgsqlfilerevision=$backupdate # <--- File revision for the postgres dump file -.->
52 | backuppgsqlcmd="/usr/local/pgsql/bin/pg_dumpall -U postgres" # <--- Command to dump database --->
53 |
54 | backupsshfsargs=
55 | backupsshargs=
56 |
57 | # Locations is where you store backups, the first one listed will be used to store the actual files, the next ones are secondary
58 | # locations where you want to copy the backups to.
59 | # The backups can be storted locally, via ssh/sftp, via smb, or via ftp.
60 | # Syntax are, Local: /mnt/backup, SSH(SFTP): host:/mnt/backup, SMB: smb://user:pass@host/dir, FTP: ftp://user:pass@host/dir
61 | # If the directory starts with /mnt or /media, it will be automatically mounted and umounted if it is not mounted already.
62 | # The FIRST listed location should not be FTP.
63 |
64 | backuplocations="\
65 | host1:/mnt/datadisk/backup/abackup/$backupid
66 | host2:/mnt/backup/abackup/$backupid
67 | host3:/mnt/store/abackup/$backupid
68 | "
69 |
70 | # Enter files to backup here
71 |
72 | backupfiles="\
73 | etc
74 | var/spool/mail
75 | var/spool/cron
76 | var/lib/samba
77 | var/lib/named
78 | var/lib/mysql
79 | var/lib/pgsql
80 | lib/firmware/dvb-fe-*
81 | srv
82 | home
83 | usr/local
84 | home/jonas/temp
85 | "
86 |
87 | # Enter files to exclude here, like temp files and sockets
88 |
89 | backupexclude="\
90 | home/*/temp
91 | home/*/Temp
92 | home/*/backup
93 | home/*/Backup
94 | home/*/build
95 | home/*/.xsession-errors
96 | home/*/.local/share/Trash
97 | home/*/.cache
98 | home/*/.thumbnails
99 | home/*/.qt
100 | home/*/.gvfs
101 | home/*/.dbus
102 | home/*/.netx
103 | home/*/.kde/cache-*
104 | home/*/.kde/tmp-*
105 | home/*/.kde/socket-*
106 | home/*/.kde4/cache-*
107 | home/*/.kde4/tmp-*
108 | home/*/.kde4/socket-*
109 | home/*/.beagle
110 | home/*/.pulse-cookie
111 | home/*/.pulse
112 | home/*/.xine
113 | home/*/.mcop
114 | home/*/.java
115 | home/*/.adobe
116 | home/*/.macromedia
117 | home/*/.mozilla/firefox/*/Cache*
118 | home/*/.opera/cache
119 | home/*/.mythtv/*cache
120 | home/*/.xmltv/cache
121 | home/*/.googleearth
122 | home/*/.wine
123 | home/*/.wine_*
124 | home/*/.kde4/share/apps/nepomuk
125 | home/*/.kde/share/apps/amarok/albumcovers/cache
126 | var/cache
127 | var/tmp
128 | var/run
129 | var/spool/postfix/private
130 | var/spool/postfix/public
131 | var/lib/named/lib
132 | var/lib/named/proc
133 | var/lib/named/var
134 | var/lib/named/dev
135 | var/lib/mysql/mysql.sock
136 | var/lib/ntp/proc
137 | var/lib/samba/unexpected
138 | home/jonas/photos
139 | "
140 |
--------------------------------------------------------------------------------
/backup/tarbackup2.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # tarbackup2.sh - TAR BACKUP SCRIPT
4 | # Copyright (C) 2011-2012 Jonas Kvinge
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 3 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
17 | # along with this program. If not, see .
18 | #
19 |
20 | backupversion="2.1.1"
21 |
22 | backupid=$(hostname -s)
23 | backupdate=$(date '+%Y%m%d-%H%M%S')
24 |
25 | backupsshfsargs=
26 | filelocation=
27 | backupexclude=
28 | backupmountpoint=
29 | backupmysqlcmd=
30 | backuppgsqlcmd=
31 | backupfileprefix=
32 | backupold2keep=
33 | backupmysqlfileprefix=
34 | backuppgsqlfileprefix=
35 | backupemailsuccess=
36 | backupemailfailure=
37 | backupemailfailureall=
38 | backupfilerevision=
39 | backupmysqlfilerevision=
40 | backuppgsqlfilerevision=
41 |
42 | # Functions below here
43 |
44 | backup_local() {
45 |
46 | backupdir=$backuplocation
47 | mountpoint=$backuplocation
48 | mountpointdir=$backuplocation
49 | mounted=
50 |
51 | topdir=$(echo "$backupdir" | cut -d'/' -f2)
52 | if [ "$topdir" = "mnt" ] || [ "$topdir" = "media" ] ; then
53 | mountpoint=$(echo "$backupdir" | cut -d'/' -f-3)
54 | mountpoint -q "$mountpoint"
55 | if [ $? != 0 ] ; then
56 | mount "$mountpoint" || {
57 | if [ "$count" = "1" ]; then
58 | exit_failure
59 | fi
60 | return 1
61 | }
62 | mounted=1
63 | if [ "$count" = "1" ]; then
64 | mounted1=1
65 | mountpoint1=$mountpoint
66 | fi
67 | fi
68 | fi
69 | mkdir -p "$backupdir" || exit_failure
70 |
71 | if [ "$count" = "1" ]; then
72 | backup_create
73 | else
74 | backup_copy || {
75 | if [ "$mounted" = "1" ] ; then
76 | umount "$mountpoint"
77 | fi
78 | return 1
79 | }
80 | fi
81 |
82 | backup_delete
83 |
84 | if ! [ "$count" = "1" ] && [ "$mounted" = "1" ] ; then
85 | umount "$mountpoint"
86 | fi
87 |
88 | return 0
89 |
90 | }
91 |
92 | backup_ssh() {
93 |
94 | backuphost=$(echo "$backuplocation" | cut -d':' -f1)
95 | backupdir=$(echo "$backuplocation" | cut -d':' -f2-)
96 |
97 | if [ "$backuphost" = "$backupid" ] ; then
98 | backuplocation=$backupdir
99 | backup_local
100 | return $?
101 | fi
102 |
103 | mountpoint="/tmp/ssh-$backupid-$backuphost-$backupdate-$RANDOM"
104 | mountpointdir=$mountpoint
105 |
106 | if [ "$count" = "1" ]; then
107 | backup_ssh_mount || { rmdir "$mountpoint" >/dev/null 2>&1; exit_failure; }
108 | mounted1=1
109 | mountpoint1=$mountpoint
110 | backup_create
111 | else
112 | #ssh $backupsshargs $backuphost mkdir -p $backupdir || return 1
113 | backup_ssh_copy || return 1
114 | backup_ssh_mount || { rmdir "$mountpoint" >/dev/null 2>&1; return 1; }
115 | fi
116 |
117 | backup_delete
118 |
119 | if ! [ "$count" = "1" ]; then
120 | fusermount -u "$mountpoint" && rmdir "$mountpoint"
121 | fi
122 |
123 | return 0
124 |
125 | }
126 |
127 | backup_ssh_copy() {
128 |
129 | echo "$n" "Copying tar backup \"$backuplocationsrc/$backupfile.bz2\" to location \"$backuplocation\". $c"
130 | scp -qp "$backupfileorig" "$backuplocation"/ || return 1
131 | echo "Done."
132 | scp -qp "$backupfileorigmd5" "$backuplocation"/ || return 1
133 | if [ "$backupmysql" = "1" ] ; then
134 | echo "$n" "Copying mysql backup \"$backuplocationsrc/$backupmysqlfile.bz2\" to location \"$backuplocation\". $c"
135 | scp -qp "$backupmysqlfileorig" "$backuplocation" || return 1
136 | echo "Done."
137 | scp -qp "$backupmysqlfileorigmd5" "$backuplocation" || return 1
138 | fi
139 | if [ "$backuppgsql" = "1" ] ; then
140 | echo "$n" "Copying pgsql backup \"$backuplocationsrc/$backuppgsqlfile.bz2\" to location \"$backuplocation\". $c"
141 | scp -qp "$backuppgsqlfileorig" "$backuplocation" || return 1
142 | echo "Done."
143 | scp -qp "$backuppgsqlfileorigmd5" "$backuplocation" || return 1
144 | fi
145 |
146 | return 0
147 |
148 | }
149 |
150 | backup_ssh_mount() {
151 |
152 | mkdir -p "$mountpoint" || return 1
153 | #ssh $backupsshargs $backuphost mkdir -p $backupdir || return 1
154 | sshfs "$backupsshfsargs" "$backuplocation" "$mountpoint" || return 1
155 |
156 | return 0
157 |
158 | }
159 |
160 | backup_smb() {
161 |
162 | backupproto="$(echo "$backuplocation" | grep '://' | sed -e 's,^\(.*://\).*,\1,g')"
163 | backupurl=$(echo "$backuplocation" | sed -e s,${backupproto},,g)
164 | backupuser="$(echo "$backupurl" | grep '@' | cut -d'@' -f1 | cut -d':' -f1)"
165 | backuppass="$(echo "$backupurl" | grep '@' | cut -d'@' -f1 | cut -d':' -f2)"
166 | backuphost="$(echo "$backupurl" | sed -e s,${backupuser}.*@,,g | cut -d/ -f1)"
167 | backupshare="$(echo "$backupurl" | cut -d'/' -f2)"
168 | backupdir="$(echo "$backupurl" | grep '/' | cut -d'/' -f3-)"
169 | backupdir="/$backupdir"
170 |
171 | mountpoint="/tmp/smb-$backupid-$backuphost-$backupdate-$RANDOM"
172 | mountpointdir="$mountpoint$backupdir"
173 |
174 | mkdir -p "$mountpoint" || return 1
175 |
176 | if ! [ "$backupuser" = "" ] && ! [ "$backuppass" = "" ] ; then
177 | backupoptions="-o username=$backupuser,password=$backuppass"
178 | elif ! [ "$backupuser" = "" ] ; then
179 | backupoptions="-o username=$backupuser"
180 | else
181 | backupoptions=
182 | fi
183 |
184 | mount -t cifs "//$backuphost/$backupshare" "$backupoptions" "$mountpoint" || { rmdir "$mountpoint"; return 1; }
185 |
186 | if [ "$count" = "1" ]; then
187 | mounted1=1
188 | mountpoint1=$mountpoint
189 | backup_create
190 | else
191 | backup_copy || { umount "$mountpoint" && rmdir "$mountpoint"; return 1; }
192 | fi
193 |
194 | backup_delete
195 |
196 | if ! [ "$count" = "1" ]; then
197 | umount "$mountpoint" && rmdir "$mountpoint"
198 | fi
199 |
200 | return 0
201 |
202 | }
203 |
204 | backup_ftp() {
205 |
206 | if [ "$count" = "1" ]; then
207 | echo "ERROR: Can't use FTP as the first backup location!" >&2
208 | exit_failure
209 | fi
210 |
211 | backuplocation2=$(echo "$backuplocation" | sed -e 's/ftp:\/\///g')
212 | if [ "$backuplocation2" = "" ]; then
213 | echo "ERROR: Cant figure out URL for \"$backuplocation\"." >&2
214 | return 1
215 | fi
216 |
217 | mountpoint="/tmp/ftp-$backupid-$backuphost-$backupdate-$RANDOM"
218 | mountpointdir=$mountpoint
219 | mkdir -p "$mountpoint" || return 1
220 |
221 | curlftpfs "$backuplocation2" "$mountpoint" || { rmdir "$mountpoint"; return 1; }
222 |
223 | if [ "$count" = "1" ]; then
224 | mounted1=1
225 | mountpoint1=$mountpoint
226 | backup_create
227 | else
228 | backup_copy || { umount "$mountpoint" && rmdir "$mountpoint"; return 1; }
229 | fi
230 |
231 | backup_delete
232 |
233 | if ! [ "$count" = "1" ]; then
234 | umount "$mountpoint" && rmdir "$mountpoint"
235 | fi
236 |
237 | return 0
238 |
239 | }
240 |
241 | backup_create() {
242 |
243 | backuplocationsrc=$backuplocation
244 | backupfileorig="$mountpointdir/$backupfile"
245 |
246 | for i in "$backupfileorig" "$backupfileorig.bz2"
247 | do
248 | if [ -f "$i" ] ; then
249 | echo "ERROR: File $i already exist on \"$filelocation\"!" >&2
250 | exit_failure
251 | fi
252 | done
253 |
254 | echo "tar -cvf $backupfileorig -C / --ignore-failed-read -X $backupexcludestmpfile $backupfiles"
255 |
256 | echo "$n" "Creating tar archive as \"$backuplocationsrc/$backupfile\". $c"
257 | echo "$backupexclude" >"$backupexcludestmpfile" || exit_failure
258 | echo "$backupmountpoint" >>"$backupexcludestmpfile" || exit_failure
259 | tar -cvf "$backupfileorig" -C / --ignore-failed-read -X "$backupexcludestmpfile" "$backupfiles" >"$backupfilestmpfile" || { rm -f "$backupfileorig"; exit_failure; return 1; }
260 | echo "Done."
261 | echo "$n" "Compressing tar archive as \"$backuplocationsrc/$backupfile.bz2\". $c"
262 | bzip2 "$backupfileorig" || { rm -f "$backupfileorig"; rm -f "${backupfileorig}.bz2"; exit_failure; return 1; }
263 | echo "Done."
264 | backupfileorig="$backupfileorig.bz2"
265 | backupfileorigmd5="$backupfileorig.md5"
266 | echo "$n" "Creating MD5 checksum file \"$backuplocationsrc/$backupfile.bz2.md5\". $c"
267 | md5sum "$backupfileorig" >"$backupfileorigmd5" && echo "Done."
268 |
269 | # MYSQL
270 |
271 | if [ "$backupmysql" = "1" ] ; then
272 |
273 | backupmysqlfileorig="$mountpointdir/$backupmysqlfile"
274 |
275 | for i in "$backupmysqlfileorig" "$backupmysqlfileorig.bz2"
276 | do
277 | if [ -f "$i" ] ; then
278 | echo "ERROR: File $i already exist on \"$filelocation\"!" >&2
279 | return
280 | fi
281 | done
282 |
283 | echo "$n" "Dumping mysql database to \"$backuplocationsrc/$backupmysqlfile\". $c"
284 | "$backupmysqlcmd" > "$backupmysqlfileorig"
285 | if [ $? != 0 ] ; then
286 | backupmysql=0
287 | else
288 | echo "Done."
289 | echo "$n" "Compressing mysql database as \"$backuplocationsrc/$backupmysqlfile.bz2\". $c"
290 | bzip2 "$backupmysqlfileorig"
291 | if [ $? != 0 ] ; then
292 | backupmysql=0
293 | else
294 | echo "Done."
295 | backupmysqlfileorig="$backupmysqlfileorig.bz2"
296 | backupmysqlfileorigmd5="$backupmysqlfileorig.md5"
297 | echo "$n" "Creating mysql database MD5 checksum file \"$backuplocationsrc/$backupmysqlfile.bz2.md5\". $c"
298 | md5sum "$backupmysqlfileorig" >"$backupmysqlfileorigmd5" && echo "Done."
299 | fi
300 | fi
301 | fi
302 |
303 | # POSTGRESQL
304 |
305 | if [ "$backuppgsql" = "1" ] ; then
306 |
307 | backuppgsqlfileorig="$mountpointdir/$backuppgsqlfile"
308 |
309 | for i in "$backuppgsqlfileorig" "$backuppgsqlfileorig.bz2"
310 | do
311 | if [ -f "$i" ] ; then
312 | echo "ERROR: File $i already exist on \"$filelocation\"!" >&2
313 | return
314 | fi
315 | done
316 |
317 | echo "$n" "Dumping pgsql database to \"$backuplocationsrc/$backuppgsqlfile\". $c"
318 | $backuppgsqlcmd > "$backuppgsqlfileorig"
319 | if [ $? != 0 ] ; then
320 | backuppgsql=0
321 | else
322 | echo "Done."
323 | echo "$n" "Compressing pgsql database as \"$backuplocationsrc/$backuppgsqlfile.bz2\". $c"
324 | bzip2 "$backuppgsqlfileorig"
325 | if [ $? != 0 ] ; then
326 | backuppgsql=0
327 | else
328 | echo "Done."
329 | backuppgsqlfileorig="$backuppgsqlfileorig.bz2"
330 | backuppgsqlfileorigmd5="$backuppgsqlfileorig.md5"
331 | echo "$n" "Creating pgsql database MD5 checksum file \"$backuplocationsrc/$backuppgsqlfile.bz2.md5\". $c"
332 | md5sum "$backuppgsqlfileorig" >"$backuppgsqlfileorigmd5" && echo "Done."
333 | fi
334 | fi
335 | fi
336 |
337 | return 0
338 |
339 | }
340 |
341 | backup_copy() {
342 |
343 | echo "$n" "Copying tar backup \"$backuplocationsrc/$backupfile.bz2\" to location \"$backuplocation\". $c"
344 | cp --preserve=timestamps "$backupfileorig" "$mountpointdir" || return 1
345 | echo "Done."
346 | cp --preserve=timestamps "$backupfileorigmd5" "$mountpointdir" || return 1
347 | if [ "$backupmysql" = "1" ] ; then
348 | echo "$n" "Copying mysql backup \"$backuplocationsrc/$backupmysqlfile.bz2\" to location \"$backuplocation\". $c"
349 | cp --preserve=timestamps "$backupmysqlfileorig" "$mountpointdir" || return 1
350 | echo "Done."
351 | cp --preserve=timestamps "$backupmysqlfileorigmd5" "$mountpointdir" || return 1
352 | fi
353 | if [ "$backuppgsql" = "1" ] ; then
354 | echo "$n" "Copying pgsql backup \"$backuplocationsrc/$backuppgsqlfile.bz2\" to location \"$backuplocation\". $c"
355 | cp --preserve=timestamps "$backuppgsqlfileorig" "$mountpointdir" || return 1
356 | echo "Done."
357 | cp --preserve=timestamps "$backuppgsqlfileorigmd5" "$mountpointdir" || return 1
358 | fi
359 |
360 | return 0
361 |
362 | }
363 |
364 | backup_delete() {
365 |
366 | backups=0
367 | for i in $(ls -1 -r "$mountpointdir")
368 | do
369 | if ! echo "$i" | grep "^$backupfileprefix-.*\.tar\.bz2$" >/dev/null 2>&1 ; then
370 | continue
371 | fi
372 | if [ "$i" = "$backupfile.bz2" ] ; then
373 | continue
374 | fi
375 | backups=$(echo "$backups" + 1 | bc)
376 | if [ "$backups" -gt "$backupold2keep" ] ; then
377 | echo "$n" "Deleting old backup \"$backuplocation/$i\". $c"
378 | rm "$mountpointdir/$i" && echo "Done."
379 | rm -f "$mountpointdir/$i.md5"
380 | fi
381 | done
382 |
383 | # Delete old myql backups
384 |
385 | if [ "$backupmysql" = "1" ] ; then
386 | backups=0
387 | for i in $(ls -1 -r "$mountpointdir")
388 | do
389 | if ! echo "$i" | grep "$backupmysqlfileprefix-.*\.sql\.bz2$" >/dev/null 2>&1 ; then
390 | continue
391 | fi
392 | if [ "$i" = "$backupmysqlfile.bz2" ] ; then
393 | continue
394 | fi
395 | backups=$(echo "$backups" + 1 | bc)
396 | if [ "$backups" -gt "$backupold2keep" ] ; then
397 | echo "$n" "Deleting old mysql backup \"$backuplocation/$i\". $c"
398 | rm "$mountpointdir/$i" && echo "Done."
399 | rm -f "$mountpointdir/$i.md5"
400 | fi
401 | done
402 | fi
403 |
404 | # Delete old pgsql backups
405 |
406 | if [ "$backuppgsql" = "1" ] ; then
407 | backups=0
408 | for i in $(ls -1 -r "$mountpointdir")
409 | do
410 | if ! echo "$i" | grep "$backuppgsqlfileprefix-.*\.sql\.bz2$" >/dev/null 2>&1 ; then
411 | continue
412 | fi
413 | if [ "$i" = "$backuppgsqlfile.bz2" ] ; then
414 | continue
415 | fi
416 | backups=$(echo "$backups" + 1 | bc)
417 | if [ "$backups" -gt "$backupold2keep" ] ; then
418 | echo "$n" "Deleting old pgsql backup \"$backuplocation/$i\". $c"
419 | rm "$mountpointdir/$i" && echo "Done."
420 | rm -f "$mountpointdir/$i.md5"
421 | fi
422 | done
423 | fi
424 |
425 | }
426 |
427 | exit_cleanup() {
428 |
429 | rm -f "$backupexcludestmpfile"
430 | rm -f "$backupfilestmpfile"
431 |
432 | # Umount drives
433 |
434 | if [ "$mounted1" = "1" ] ; then
435 | echo "$mountpoint1" | grep '^\/tmp\/ssh-' >/dev/null 2>&1
436 | if [ $? -eq 0 ] ; then
437 | fusermount -u "$mountpoint1" && rmdir "$mountpoint1"
438 | else
439 | echo "$mountpoint1" | grep '^\/tmp\/smb-' >/dev/null 2>&1
440 | if [ $? -eq 0 ] ; then
441 | umount "$mountpoint1" && rmdir "$mountpoint1"
442 | else
443 | echo "$mountpoint1" | grep '^\/tmp\/ftp-' >/dev/null 2>&1
444 | if [ $? -eq 0 ] ; then
445 | umount "$mountpoint1" && rmdir "$mountpoint1"
446 | else
447 | umount "$mountpoint1"
448 | fi
449 | fi
450 | fi
451 | fi
452 |
453 | }
454 |
455 | report_success() {
456 |
457 | LANG="en_GB"
458 | mail -s "Tar backup for $(hostname) on $(date) to location $backuplocation was successful" -a "$backupfilestmpfile" "$backupemailsuccess" <"; exit 0;;
582 | v) echo "$script v$backupversion"; exit 0;;
583 | \?) echo "Usage: $script -hv -c "; exit 1;;
584 | esac
585 | done
586 |
587 | # Reset $@
588 | shift "$(echo "$OPTIND" - 1 | bc)"
589 |
590 | # Locate configuration file
591 |
592 | if [ "$backupconfig" = "" ] ; then
593 | backupconfig="tarbackup2-conf.sh"
594 | fi
595 |
596 | if ! [ -f "$backupconfig" ]; then
597 | if [ -f "./$backupconfig" ]; then
598 | backupconfig="./$backupconfig"
599 | else
600 | if [ -f "$runpath/$backupconfig" ]; then
601 | backupconfig="$runpath/$backupconfig"
602 | fi
603 | fi
604 | fi
605 |
606 | # Check for existence of needed config file and read it
607 |
608 | if ! [ -f "$backupconfig" ]; then
609 | echo "ERROR: Backup configuration file \"$backupconfig\" does not exist!" >&2
610 | exit 1
611 | fi
612 |
613 | if ! [ -r "$backupconfig" ]; then
614 | echo "ERROR: Can't read configuration file \"$backupconfig\"." >&2
615 | exit 1;
616 | fi
617 |
618 | . $backupconfig
619 |
620 | # Check that we got the configuration needed
621 |
622 | for i in \
623 | "backupid" \
624 | "backupdate" \
625 | "backupfileprefix" \
626 | "backupfilerevision" \
627 | "backupemailsuccess" \
628 | "backupemailfailure" \
629 | "backupemailfailureall" \
630 | "backupold2keep" \
631 | "backupmysql" \
632 | "backupmysqlfileprefix" \
633 | "backupmysqlfilerevision" \
634 | "backupmysqlcmd" \
635 | "backuppgsql" \
636 | "backuppgsqlfileprefix" \
637 | "backuppgsqlfilerevision" \
638 | "backuppgsqlcmd" \
639 | "backuplocations" \
640 | "backupfiles" \
641 | "backupexclude"
642 | do
643 | if [ "${!i}" = "" ] ; then
644 | echo "ERROR: Missing configuration variable \"$i\" in \"$backupconfig\"!" >&2
645 | exit 1
646 | fi
647 | done
648 |
649 | # Check that we got all the needed commands
650 |
651 | cmds="which cp scp mv rm mkdir rmdir cat tr bc cut sed grep mail tar bzip2 md5sum date hostname mount umount mountpoint fusermount"
652 | for backuplocation in $backuplocations
653 | do
654 | echo "$backuplocation" | grep -i '.*:\/\/.*\/' >/dev/null 2>&1
655 | if [ $? -eq 0 ] ; then
656 | echo "$backuplocation" | grep -i '^ftp:\/\/.*\/' >/dev/null 2>&1
657 | if [ $? -eq 0 ] ; then
658 | cmds="$cmds curlftpfs"
659 | continue
660 | fi
661 | else
662 | echo "$backuplocation" | grep '.*:\/' >/dev/null 2>&1
663 | if [ $? -eq 0 ] ; then
664 | cmds="$cmds sshfs"
665 | continue
666 | fi
667 | fi
668 | done
669 |
670 | for cmd in $cmds
671 | do
672 | which "$cmd" >/dev/null 2>&1
673 | if [ $? != 0 ] ; then
674 | echo "ERROR: Missing \"${cmd}\" command!" >&2
675 | exit_failure
676 | fi
677 | done
678 |
679 | # Set variables
680 |
681 | backupfile="$backupfileprefix-$backupfilerevision.tar"
682 | backupmysqlfile="$backupmysqlfileprefix-$backupmysqlfilerevision.sql"
683 | backuppgsqlfile="$backuppgsqlfileprefix-$backuppgsqlfilerevision.sql"
684 |
685 | backupfilestmpfile="/tmp/tarbackupfiles-$backupdate-$RANDOM.txt"
686 | backupexcludestmpfile="/tmp/tarbackupexcludes-$backupdate-$RANDOM.txt"
687 |
688 | backuplocations=$(echo "$backuplocations" | tr '\n' ' ' | sed -e 's/^ //g' | sed -e 's/ / /g')
689 |
690 | # Create backupfiles
691 | # Only include files that actually exist to avoid tar error report
692 |
693 | backupfilesX=$(echo "$backupfiles" | tr '\n' ' ' | sed -e 's/^ //g' | sed -e 's/ / /g')
694 | backupfiles=
695 | for ((i=1; ; i++))
696 | do
697 | s=$(echo "$backupfilesX" | cut -d' ' -f"$i")
698 | if [ "$s" = "" ]; then
699 | break
700 | fi
701 | s2=$s
702 | echo "$s" | grep -i '^\/.*' >/dev/null 2>&1
703 | if ! [ $? -eq 0 ] ; then
704 | s2="/$s"
705 | fi
706 | ls "$s2" >/dev/null 2>&1
707 | if [ $? -eq 0 ] ; then
708 | backupfiles="$backupfiles $s"
709 | else
710 | echo "Excluding \"$s\" from backup, can't access!"
711 | fi
712 | done
713 | backupfiles=$(echo "$backupfiles" | sed -e 's/^ //g')
714 |
715 | if [ "$backupfiles" = "" ] ; then
716 | echo "ERROR: No backupfiles exist!" >&2
717 | exit_failure
718 | fi
719 |
720 | # Loop locations, create tar, transfer new backups and delete old backups
721 |
722 | count=0
723 | locationssuccess=0
724 | locationsfailure=0
725 | for backuplocation in $backuplocations
726 | do
727 |
728 | count=$(echo "$count" + 1 | bc)
729 | echo "Performing backup to \"$backuplocation\""
730 |
731 | backuphost=
732 | backupdir=
733 | mounted=
734 | mountpoint=
735 | mountpointdir=
736 | ret=
737 |
738 | echo "$backuplocation" | grep -i '.*:\/\/.*\/' >/dev/null 2>&1
739 | if [ $? -eq 0 ] ; then
740 | echo "$backuplocation" | grep -i '^smb:\/\/.*\/' >/dev/null 2>&1
741 | if [ $? -eq 0 ] ; then # SMB
742 | backup_smb
743 | ret=$?
744 | fi
745 | echo "$backuplocation" | grep -i '^ftp:\/\/.*\/' >/dev/null 2>&1
746 | if [ $? -eq 0 ] ; then # FTP
747 | backup_ftp
748 | ret=$?
749 | fi
750 | else
751 | echo "$backuplocation" | grep '^\/' >/dev/null 2>&1
752 | if [ $? -eq 0 ] ; then # Local
753 | backup_local
754 | ret=$?
755 | fi
756 | echo "$backuplocation" | grep '.*:\/' >/dev/null 2>&1
757 | if [ $? -eq 0 ] ; then # SSH
758 | backup_ssh
759 | ret=$?
760 | fi
761 | fi
762 |
763 | if [ "$ret" = "" ] ; then
764 | echo "ERROR: Unknown backup location: \"$backuplocation\"" >&2
765 | if [ "$count" -lt 2 ] ; then
766 | if ! [ "$backupemailfailureall" = "0" ]; then
767 | report_failure_all
768 | fi
769 | exit_failure
770 | fi
771 | elif [ "$ret" -eq "0" ] ; then
772 | locationssuccess=$(echo "$locationssuccess" + 1 | bc)
773 | if ! [ "$backupemailsuccess" = "0" ]; then
774 | report_success
775 | fi
776 | else
777 | locationsfailure=$(echo "$locationsfailure" + 1 | bc)
778 | if ! [ "$backupemailfailure" = "0" ]; then
779 | report_failure
780 | fi
781 | fi
782 |
783 | done
784 |
785 | if [ "$locationssuccess" -gt "0" ] ; then
786 | exit_success
787 | else
788 | if ! [ "$backupemailfailureall" = "0" ]; then
789 | report_failure_all
790 | fi
791 | exit_failure
792 | fi
793 |
--------------------------------------------------------------------------------
/monitoring/domainwatch.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # domainwatch.sh - Monitor Domain Watch
4 | # Copyright (C) 2017 Jonas Kvinge
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 3 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
17 | # along with this program. If not, see .
18 | #
19 |
20 | configfile="/etc/sysconfig/domainwatch"
21 | lockfile="/tmp/domainwatch.lock"
22 | lockfilettl=3600
23 | tmpfile="/tmp/domainwatch.tmp"
24 | logfile="/tmp/domainwatch.log"
25 | #log=1
26 | debug=1
27 | inettesthosts="8.8.8.8 8.8.4.4" # Test all of these, only if 1 fails internet is reported to be down.
28 | pingtimeout=2
29 | #maxfailtime=1
30 | reportfreq=3600
31 | emailfrom="nobody"
32 | emailto="root"
33 |
34 | domains="test1.com test2.com test3.com"
35 |
36 | timestamp() { TS=$(date '+%d/%m-%Y %H:%M:%S'); }
37 |
38 | print() {
39 | timestamp
40 | if [ -t 1 ] && ! [ "$color" = "" ]; then
41 | tput bold
42 | tput setaf "$color"
43 | fi
44 | echo "[$TS] $*"
45 | if [ -t 1 ]; then
46 | tput sgr0
47 | fi
48 | color=0
49 | }
50 | log() {
51 | timestamp
52 | echo "[$TS] $*" >>"${logfile}"
53 | }
54 | statusprint() { color=8; print "$@"; }
55 | statuslog() { log "$@"; }
56 | errorprint() {
57 | timestamp
58 | if [ -t 1 ]; then
59 | tput bold
60 | tput setaf 1
61 | fi
62 | echo "[$TS] ERROR: $*" >&2
63 | if [ -t 1 ]; then
64 | tput sgr0
65 | fi
66 | color=0
67 | }
68 | errorlog() { log "ERROR: $*"; }
69 | status() { statusprint "$@"; statuslog "$@"; }
70 | error() { errorprint "$@"; errorlog "$@"; }
71 | debug() {
72 | if [ "$debug" = "1" ]; then
73 | color=3
74 | print "$@"
75 | log "$@"
76 | fi
77 | }
78 |
79 | isnum() {
80 | echo "$1" | grep -E '^\-?[0-9]+$' >/dev/null 2>&1
81 | return $?
82 | }
83 |
84 | loadconfig() {
85 |
86 | if [ -f "$configfile" ]; then
87 | . $configfile || {
88 | error "Failed to load configuration file \"$configfile\"."
89 | exit_safe 1
90 | }
91 | else
92 | status "Configuration file not found: \"$configfile\" - Using defaults."
93 | fi
94 |
95 | }
96 |
97 | main() {
98 |
99 | init "$@"
100 |
101 | cmdcheck
102 | inetstatus
103 | domainwatch
104 |
105 | if [ "$sendreport" = "1" ]; then
106 | sendreport
107 | fi
108 |
109 | scriptend=$(date +%s)
110 | scripttime=$(echo "$scriptend" - "$scriptstart" | bc)
111 | status "Script finished in $(date -u -d @${scripttime} +"%T")"
112 |
113 | exit_safe 0
114 |
115 | }
116 |
117 | init() {
118 |
119 | scriptstart=$(date +%s)
120 | havelockfile=0
121 |
122 | status "Monitor Domain Watch - Starting - $0"
123 |
124 | loadconfig
125 |
126 | if [ -f "$lockfile" ]; then
127 | error "Script is already running. If this is incorrect, remove: $lockfile."
128 | exit_safe
129 | fi
130 | which lockfile >/dev/null 2>&1
131 | if [ $? -eq 0 ] ; then
132 | lockfile -r 0 -l "$lockfilettl" "$lockfile" || { exit_safe 1; }
133 | else
134 | touch "$lockfile" || { exit_safe 1; }
135 | fi
136 | havelockfile=1
137 |
138 | touch "$tmpfile" || exit_safe 1
139 | touch "$logfile" || exit_safe 1
140 |
141 | }
142 |
143 | exit_safe() {
144 |
145 | debug "exit_safe()"
146 |
147 | if [ "$havelockfile" -eq 1 ]; then
148 | rm -f "$lockfile"
149 | fi
150 |
151 | exit $?
152 | }
153 |
154 | # Check that we got all the needed commands
155 |
156 | cmdcheck() {
157 |
158 | debug "cmdcheck()"
159 |
160 | cmds="which cat cut tr sed grep bc cp mv rm mkdir date hostname mail ssh tput ping whois mutt"
161 | for cmd in $cmds
162 | do
163 | which "$cmd" >/dev/null 2>&1
164 | if [ $? != 0 ] ; then
165 | echo "ERROR: Missing \"${cmd}\" command!"
166 | exit_safe 1
167 | fi
168 | done
169 |
170 | debug "cmdcheck() finished"
171 |
172 | }
173 |
174 | inetstatus() {
175 |
176 | debug "inetstatus()"
177 |
178 | #inetwasdown=
179 | inetwasdowntext=
180 |
181 | inetup=0
182 | for inettesthost in $inettesthosts
183 | do
184 | pingtext=$(ping -c 1 -W "${pingtimeout}" "${inettesthost}")
185 | r=$?
186 | if [ $r = 0 ] ; then
187 | inetup=1
188 | break
189 | fi
190 | done
191 |
192 | if [ "$inetup" -eq 1 ]; then
193 | status "Internet connection found to be up."
194 | entry=$(grep -i "INETDOWN Time=.*" ${tmpfile})
195 | if ! [ "$entry" = "" ]; then
196 | #inetwasdown=1
197 | #rm -f ${tmpfile} || exit_safe 1
198 | #touch ${tmpfile} || exit_safe 1
199 | sed -i "/^INETDOWN .*$/d" ${tmpfile}
200 | timenow=$(date +%s)
201 | entrytime=$(echo "$entry" | sed -e 's/.* Time=\(.*\).*/\1/g' | cut -d' ' -f1)
202 | if isnum "$entrytime" ; then
203 | time=$(echo "$timenow" - "$entrytime" | bc)
204 | timetext=$(date -u -d @${time} +"%T")
205 | inetwasdowntext="Internet was down $timetext"
206 | status "$inetwasdowntext"
207 | else
208 | inetwasdowntext="Internet was down - Failed to calculate downtime."
209 | status "$inetwasdowntext"
210 | entrytime=0
211 | fi
212 | fi
213 | return $r
214 | else
215 | status "Internet connection was found to be down."
216 | entry=$(grep -i "INETDOWN Time=.*" ${tmpfile})
217 | if [ "$entry" = "" ]; then
218 | timenow=$(date +%s)
219 | echo "INETDOWN Time=${timenow}" >${tmpfile}
220 | debug "Internet was found to be down - Writing to ${tmpfile}"
221 | else
222 | debug "Internet was found to be down - Existing info found in ${tmpfile}"
223 | fi
224 | exit_safe $r
225 | fi
226 | return $r
227 |
228 | debug "inetstatus() finished"
229 |
230 | }
231 |
232 | domainwatch() {
233 |
234 | debug "domainwatch()"
235 |
236 | for domain in ${domains}
237 | do
238 | readfile
239 | status=
240 | available=0
241 | result_html=
242 | output=$(whois "$domain" 2>&1)
243 | if [ $? -eq 0 ]; then
244 | IFS_DEFAULT=$IFS
245 | IFS=$'\n'
246 | for line in $output
247 | do
248 | IFS=$IFS_DEFAULT
249 | echo "$line" | grep '^% No match$' >/dev/null 2>&1
250 | if [ $? -eq 0 ]; then
251 | status="available"
252 | result_html="Available"
253 | available=1
254 | fi
255 | done
256 | if [ "$status" = "" ]; then
257 | status="taken"
258 | result_html="Taken"
259 | available=0
260 | fi
261 | elif [ $? -eq 1 ]; then
262 | status="available"
263 | result_html="Available"
264 | available=1
265 | else
266 | status="error"
267 | result_html="Error"
268 | available=0
269 | fi
270 |
271 | status "Domain: $domain Status: $status"
272 |
273 | writefile
274 |
275 | maildata="$maildata
276 | Domain: $domain - ${result_html} "
277 |
278 | done
279 |
280 | debug "domainwatch() finished"
281 |
282 | }
283 |
284 | readfile() {
285 |
286 | debug "readfile()"
287 |
288 | #entryfail=0
289 | #failtime=0
290 | reporttime=0
291 | entrytime=0
292 | entrystatus=
293 | #entryresult=
294 |
295 | entry=$(grep -i "^${domain} .*" ${tmpfile})
296 | if [ "$entry" = "" ]; then
297 | return
298 | fi
299 | entrystatus=$(echo "$entry" | cut -d' ' -f2)
300 | if [ "$entrystatus" = "" ]; then
301 | entry=
302 | return
303 | fi
304 |
305 | reporttime=$(echo "$entry" | cut -d' ' -f3)
306 | if [ "$reporttime" = "" ] || ! isnum "$reporttime"; then
307 | entry=
308 | entrystatus=
309 | reporttime=0
310 | return
311 | fi
312 | entrytime=$(echo "$entry" | cut -d' ' -f4)
313 | if [ "$entrytime" = "" ] || ! isnum "$entrytime"; then
314 | entry=
315 | entrystatus=
316 | reporttime=0
317 | entrytime=0
318 | return
319 | fi
320 |
321 | timenow=$(date +%s)
322 | time=$(echo "$timenow" - "$entrytime" | bc)
323 | debug "Entry with timestamp \"${entrytime}\" ($(date -u -d @${time} +"%T") ago) found for domain \"$domain\". Status: $entrystatus ReportTime: $reporttime"
324 |
325 | debug "readfile() finished"
326 |
327 | }
328 |
329 | writefile() {
330 |
331 | debug "writefile()"
332 |
333 | echo "$entry" | grep -i "^${domain} ${status} .*" >/dev/null 2>&1
334 | if [ $? -eq 0 ]; then
335 | changed=0
336 | else
337 | changed=1
338 | fi
339 | debug "domain: ${domain} - Changed=$changed"
340 |
341 | timenow=$(date +%s)
342 | reporttime_bc=$(echo "$timenow" - "$reporttime" | bc)
343 |
344 | if [ "$entry" = "" ]; then
345 | entrytime=$(date +%s)
346 | summary_add "This is the first domain watch for \"$domain\"."
347 | sendreport=1
348 | reporttime=$(date +%s)
349 | elif [ "$available" -eq 1 ]; then
350 | summary_add "Domain \"$domain\" is available."
351 | if [ "$reporttime_bc" -ge "$reportfreq" ]; then
352 | sendreport=1
353 | reporttime=$(date +%s)
354 | fi
355 | fi
356 |
357 | if [ "$entrytime" -le 0 ]; then
358 | entrytime=$(date +%s)
359 | fi
360 |
361 | sed -i "/^${domain} .*$/d" $tmpfile
362 | echo "${domain} ${status} ${reporttime} ${entrytime}" >>${tmpfile}
363 |
364 | debug "writefile() finished"
365 |
366 | }
367 |
368 | summary_add() {
369 |
370 | if [ "$summary" = "" ]; then
371 | summary="$1 "
372 | else
373 | summary="$summary
374 | $1 "
375 | fi
376 |
377 | }
378 |
379 | report_add() {
380 |
381 | if [ "$reportdata" = "" ]; then
382 | reportdata="$1"
383 | else
384 | reportdata="$reportdata
385 | $1"
386 | fi
387 |
388 | }
389 |
390 | sendreport() {
391 |
392 | debug "sendreport()"
393 |
394 | status "Sending monitor domain watch report..."
395 |
396 | scriptend=$(date +%s)
397 | scripttime=$(echo "$scriptend" - "$scriptstart" | bc)
398 | reporttime=$(date +%s)
399 |
400 | report_add ""
401 | report_add ""
402 | report_add "
Monitor domain Watch
"
403 | if ! [ "$inetwasdowntext" = "" ]; then
404 | report_add "
$inetwasdowntext
"
405 | fi
406 | if ! [ "$summary" = "" ]; then
407 | report_add "
"
1015 | report_add "Script finished in $(date -u -d @${scripttime} +"%T") "
1016 | report_add "New report is sent if status has changed or every $(date -u -d @${reportfreq} +"%T") if there is an error. "
1017 | report_add "
"
1018 | report_add ""
1019 | report_add ""
1020 |
1021 | LANG=en_GB
1022 | EMAIL=$emailfrom mutt -e 'set content_type=text/html' -s "Monitor System Watch" $emailto <.
18 | #
19 |
20 | configfile="/etc/sysconfig/webwatch"
21 | lockfile="/tmp/webwatch.lock"
22 | lockfilettl=3600
23 | tmpfile="/tmp/webwatch.tmp"
24 | logfile="/tmp/webwatch.log"
25 | #log=1
26 | debug=1
27 | inettesthosts="8.8.8.8 8.8.4.4" # Test all of these, only if 1 fails internet is reported to be down.
28 | pingtimeout=2
29 | maxfailtime=1
30 | reportfreq=120
31 | emailfrom="nobody"
32 | emailto="root"
33 |
34 | websites="
35 | http://www.jkvinge.net/ Apache Server at www.jkvinge.net Port 80
36 | https://secure.jkvinge.net/ secure.jkvinge.net
37 | https://mail.jkvinge.net/src/login.php