From f05ca9da0b0efc1edb3076c219c5776be0126f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Sat, 3 Feb 2024 14:12:14 +0100 Subject: [PATCH] initial commit --- .gitignore | 2 + Cargo.lock | 305 ++++++++++++++++++++++++++++ Cargo.toml | 16 ++ LICENSE.md | 483 +++++++++++++++++++++++++++++++++++++++++++++ README.md | 43 ++++ config.sample.yaml | 17 ++ src/cli.rs | 16 ++ src/config.rs | 23 +++ src/main.rs | 86 ++++++++ 9 files changed, 991 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 config.sample.yaml create mode 100644 src/cli.rs create mode 100644 src/config.rs create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..59b2d02 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +config.yaml diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..2bc227f --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,305 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anstream" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2faccea4cc4ab4a667ce676a30e8ec13922a692c99bb8f5b11f1502c72e04220" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "anyhow" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" + +[[package]] +name = "clap" +version = "4.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "indexmap" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "restic-wrapper" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "serde", + "serde_yaml", +] + +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" + +[[package]] +name = "serde" +version = "1.0.196" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.196" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_yaml" +version = "0.9.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adf8a49373e98a4c5f0ceb5d05aa7c648d75f63774981ed95b7c7443bbd50c6e" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..9e0b6a5 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "restic-wrapper" +version = "0.1.0" +authors = ["Jan Christian Grünhage "] +edition = "2021" +description = "A wrapper around restic backup for multiple sources and repositories" +repository = "https://git.jcg.re/jcgruenhage/restic-wrapper" +license-file = "LICENSE.md" +keywords = ["cli", "backup"] +categories = ["command-line-utilities"] + +[dependencies] +anyhow = "1.0.79" +clap = { version = "4.4.18", features = ["derive"] } +serde = { version = "1.0.196", features = ["derive"] } +serde_yaml = "0.9.31" diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..9d75efb --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,483 @@ +THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS +COOPERATIVE NON-VIOLENT PUBLIC LICENSE (\"LICENSE\"). THE WORK IS +PROTECTED BY COPYRIGHT AND ALL OTHER APPLICABLE LAWS. ANY USE OF THE +WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS +PROHIBITED. BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED IN THIS +LICENSE, YOU AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE +EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR +GRANTS YOU THE RIGHTS CONTAINED HERE IN AS CONSIDERATION FOR ACCEPTING +THE TERMS AND CONDITIONS OF THIS LICENSE AND FOR AGREEING TO BE BOUND BY +THE TERMS AND CONDITIONS OF THIS LICENSE. + +# Definitions + +An Act of War is any action of one country against any group either with +an intention to provoke a conflict or an action that occurs during a +declared war or during armed conflict between military forces of any +origin. This includes but is not limited to enforcing sanctions or +sieges, supplying armed forces, or profiting from the manufacture of +tools or weaponry used in military conflict. + +An Adaptation is a work based upon the Work, or upon the Work and other +pre-existing works, such as a translation, adaptation, derivative work, +arrangement of music or other alterations of a literary or artistic +work, or phonogram or performance and includes cinematographic +adaptations or any other form in which the Work may be recast, +transformed, or adapted including in any form recognizably derived from +the original, except that a work that constitutes a Collection will not +be considered an Adaptation for the purpose of this License. For the +avoidance of doubt, where the Work is a musical work, performance or +phonogram, the synchronization of the Work in timed-relation with a +moving image (\"synching\") will be considered an Adaptation for the +purpose of this License. In addition, where the Work is designed to +output a neural network the output of the neural network will be +considered an Adaptation for the purpose of this license. + +Bodily Harm is any physical hurt or injury to a person that interferes +with the health or comfort of the person and that is more than merely +transient or trifling in nature. + +Distribute is to make available to the public the original and copies of +the Work or Adaptation, as appropriate, through sale, gift or any other +transfer of possession or ownership. + +Incarceration is Confinement in a jail, prison, or any other place where +individuals of any kind are held against either their will or (if their +will cannot be determined) the will of their legal guardian or +guardians. In the case of a conflict between the will of the individual +and the will of their legal guardian or guardians, the will of the +individual will take precedence. + +Licensor is The individual, individuals, entity, or entities that +offer(s) the Work under the terms of this License + +Original Author is in the case of a literary or artistic work, the +individual, individuals, entity or entities who created the Work or if +no individual or entity can be identified, the publisher; and in +addition + +- in the case of a performance the actors, singers, musicians, + dancers, and other persons who act, sing, deliver, declaim, play in, + interpret or otherwise perform literary or artistic works or + expressions of folklore; + +- in the case of a phonogram the producer being the person or legal + entity who first fixes the sounds of a performance or other sounds; + and, + +- in the case of broadcasts, the organization that transmits the + broadcast. + +Work is the literary and/or artistic work offered under the terms of +this License including without limitation any production in the +literary, scientific and artistic domain, whatever may be the mode or +form of its expression including digital form, such as a book, pamphlet +and other writing; a lecture, address, sermon or other work of the same +nature; a dramatic or dramatico-musical work; a choreographic work or +entertainment in dumb show; a musical composition with or without words; +a cinematographic work to which are assimilated works expressed by a +process analogous to cinematography; a work of drawing, painting, +architecture, sculpture, engraving or lithography; a photographic work +to which are assimilated works expressed by a process analogous to +photography; a work of applied art; an illustration, map, plan, sketch +or three-dimensional work relative to geography, topography, +architecture or science; a performance; a broadcast; a phonogram; a +compilation of data to the extent it is protected as a copyrightable +work; or a work performed by a variety or circus performer to the extent +it is not otherwise considered a literary or artistic work. + +You means an individual or entity exercising rights under this License +who has not previously violated the terms of this License with respect +to the Work, or who has received express permission from the Licensor to +exercise rights under this License despite a previous violation. + +Publicly Perform means to perform public recitations of the Work and to +communicate to the public those public recitations, by any means or +process, including by wire or wireless means or public digital +performances; to make available to the public Works in such a way that +members of the public may access these Works from a place and at a place +individually chosen by them; to perform the Work to the public by any +means or process and the communication to the public of the performances +of the Work, including by public digital performance; to broadcast and +rebroadcast the Work by any means including signs, sounds or images. + +Reproduce is to make copies of the Work by any means including without +limitation by sound or visual recordings and the right of fixation and +reproducing fixations of the Work, including storage of a protected +performance or phonogram in digital form or other electronic medium. + +Software is any digital Work which, through use of a third-party piece +of Software or through the direct usage of itself on a computer system, +the memory of the computer is modified dynamically or semi-dynamically. +\"Software\", secondly, processes or interprets information. + +Source Code is Any digital Work which, through use of a third-party +piece of Software or through the direct usage of itself on a computer +system, the memory of the computer is modified dynamically or +semi-dynamically. \"Software\", secondly, processes or interprets +information. + +Surveilling is the use of the Work to either overtly or covertly observe +and record persons and or their activities. + +A Network Service is the use of a piece of Software to interpret or +modify information that is subsequently and directly served to users +over the Internet. + +To Discriminate is use of a work to differentiate between humans in a +such a way which prioritizes some above others on the basis of percieved +membership within certain groups. + +Hate Speech is Communication or any form of expression which is solely +for the purpose of expressing hatred for some group or advocating a form +of Discrimination between humans. + +Coercion is leveraging of the threat of force or use of force to +intimidate a person in order to gain compliance, or to offer large +incentives which aim to entice a person to act against their will. + +# Fair Dealing Rights + +Nothing in this License is intended to reduce, limit, or restrict any +uses free from copyright or rights arising from limitations or +exceptions that are provided for in connection with the copyright +protection under copyright law or other applicable laws. + +# License Grant + +Subject to the terms and conditions of this License, Licensor hereby +grants You a worldwide, royalty-free, non-exclusive, perpetual (for the +duration of the applicable copyright) license to exercise the rights in +the Work as stated below: + +To Reproduce the Work, to incorporate the Work into one or more +Collections, and to Reproduce the Work as incorporated in the +Collections + +To create and Reproduce Adaptations provided that any such Adaptation, +including any translation in any medium, takes reasonable steps to +clearly label, demarcate or otherwise identify that changes were made to +the original Work. For example, a translation could be marked \"The +original work was translated from English to Spanish,\" or a +modification could indicate \"The original work has been modified.\" + +To Distribute and Publicly Perform the Work including as incorporated in +Collections. + +To Distribute and Publicly Perform Adaptations. The above rights may be +exercised in all media and formats whether now known or hereafter +devised. The above rights include the right to make such modifications +as are technically necessary to exercise the rights in other media and +formats. This License constitutes the entire agreement between the +parties with respect to the Work licensed here. There are no +understandings, agreements or representations with respect to the Work +not specified here. Licensor shall not be bound by any additional +provisions that may appear in any communication from You. This License +may not be modified without the mutual written agreement of the Licensor +and You. All rights not expressly granted by Licensor are hereby +reserved, including but not limited to the rights set forth in +Non-waivable Compulsory License Schemes, Waivable Compulsory License +Schemes, and Voluntary License Schemes in the restrictions. + +# Restrictions + +The license granted in the license grant above is expressly made subject +to and limited by the following restrictions: + +You may Distribute or Publicly Perform the Work only under the terms of +this License. You must include a copy of, or the Uniform Resource +Identifier (URI) for, this License with every copy of the Work You +Distribute or Publicly Perform. You may not offer or impose any terms on +the Work that restrict the terms of this License or the ability of the +recipient of the Work to exercise the rights granted to that recipient +under the terms of the License. You may not sublicense the Work. You +must keep intact all notices that refer to this License and to the +disclaimer of warranties with every copy of the Work You Distribute or +Publicly Perform. When You Distribute or Publicly Perform the Work, You +may not impose any effective technological measures on the Work that +restrict the ability of a recipient of the Work from You to exercise the +rights granted to that recipient under the terms of the License. This +Section applies to the Work as incorporated in a Collection, but this +does not require the Collection apart from the Work itself to be made +subject to the terms of this License. If You create a Collection, upon +notice from any Licensor You must, to the extent practicable, remove +from the Collection any credit as requested. If You create an +Adaptation, upon notice from any Licensor You must, to the extent +practicable, remove from the Adaptation any credit as requested. + +## Commercial Restrictions + +You may not exercise any of the rights granted to You in the above +section in any manner that is primarily intended for or directed toward +commercial advantage or private monetary compensation unless you meet +the following requirements. + +i. You are a worker-owned business or worker-owned collective. + +ii. after tax, all financial gain, surplus, profits and benefits + produced by the business or collective are distributed among the + worker-owners unless a set amount is to be allocated towards + community projects as decided by a previously-established consensus + agreement between the worker-owners where all worker-owners agreed. + +iii. You are not using such rights on behalf of a business other than + those specified in (i) or (ii) above, nor are using such rights as + a proxy on behalf of a business with the intent to circumvent the + aforementioned restrictions on such a business. + +The exchange of the Work for other copyrighted works by means of digital +file-sharing or otherwise shall not be considered to be intended for or +directed toward commercial advantage or private monetary compensation, +provided there is no payment of any monetary compensation in connection +with the exchange of copyrighted works. + +If the Work meets the definition of Software, You may exercise the +rights granted in the license grant only if You provide a copy of the +corresponding Source Code from which the Work was derived in digital +form, or You provide a URI for the corresponding Source Code of the +Work, to any recipients upon request. + +If the Work is used as or for a Network Service, You may exercise the +rights granted in the license grant only if You provide a copy of the +corresponding Source Code from which the Work was derived in digital +form, or You provide a URI for the corresponding Source Code to the +Work, to any recipients of the data served or modified by the Web +Service. + +Any use by a business that is privately owned and managed, and that +seeks to generate profit from the labor of employees paid by salary or +other wages, is not permitted under this license. + +## + +You may exercise the rights granted in the license grant for any +purposes only if: + +i. You do not use the Work for the purpose of inflicting Bodily Harm on + human beings (subject to criminal prosecution or otherwise) outside + of providing medical aid or undergoing a voluntary procedure under + no form of Coercion. + +ii. You do not use the Work for the purpose of Surveilling or tracking + individuals for financial gain. + +iii. You do not use the Work in an Act of War. + +iv. You do not use the Work for the purpose of supporting or profiting + from an Act of War. + +v. You do not use the Work for the purpose of Incarceration. + +vi. You do not use the Work for the purpose of extracting, processing, + or refining, oil, gas, or coal. Or to in any other way to + deliberately pollute the environment as a byproduct of manufacturing + or irresponsible disposal of hazardous materials. + +vii. You do not use the Work for the purpose of expediting, + coordinating, or facilitating paid work undertaken by individuals + under the age of 12 years. + +viii. You do not use the Work to either Discriminate or spread Hate + Speech on the basis of sex, sexual orientation, gender identity, + race, age, disability, color, national origin, religion, caste, or + lower economic status. + +## + +If You Distribute, or Publicly Perform the Work or any Adaptations or +Collections, You must, unless a request has been made by any Licensor to +remove credit from a Collection or Adaptation, keep intact all copyright +notices for the Work and provide, reasonable to the medium or means You +are utilizing: + +i. the name of the Original Author (or pseudonym, if applicable) if + supplied, and/or if the Original Author and/or Licensor designate + another party or parties (e.g., a sponsor institute, publishing + entity, journal) for attribution (\"Attribution Parties\") in + Licensor\'s copyright notice, terms of service or by other + reasonable means, the name of such party or parties; + +ii. the title of the Work if supplied; + +iii. to the extent reasonably practicable, the URI, if any, that + Licensor to be associated with the Work, unless such URI does not + refer to the copyright notice or licensing information for the + Work; and, + +iv. in the case of an Adaptation, a credit identifying the use of the + Work in the Adaptation (e.g., \"French translation of the Work by + Original Author,\" or \"Screenplay based on original Work by + Original Author\"). + +If any Licensor has sent notice to request removing credit, You must, to +the extent practicable, remove any credit as requested. The credit +required by this Section may be implemented in any reasonable manner; +provided, however, that in the case of an Adaptation or Collection, at a +minimum such credit will appear, if a credit for all contributing +authors of the Adaptation or Collection appears, then as part of these +credits and in a manner at least as prominent as the credits for the +other contributing authors. For the avoidance of doubt, You may only use +the credit required by this Section for the purpose of attribution in +the manner set out above and, by exercising Your rights under this +License, You may not implicitly or explicitly assert or imply any +connection with, sponsorship or endorsement by the Original Author, +Licensor and/or Attribution Parties, as appropriate, of You or Your use +of the Work, without the separate, express prior written permission of +the Original Author, Licensor and/or Attribution Parties. + +Non-waivable Compulsory License Schemes. In those jurisdictions in which +the right to collect royalties through any statutory or compulsory +licensing scheme cannot be waived, the Licensor reserves the exclusive +right to collect such royalties for any exercise by You of the rights +granted under this License + +Waivable Compulsory License Schemes. In those jurisdictions in which the +right to collect royalties through any statutory or compulsory licensing +scheme can be waived, the Licensor reserves the exclusive right to +collect such royalties for any exercise by You of the rights granted +under this License if Your exercise of such rights is for a purpose or +use which is otherwise than noncommercial as permitted under Commercial +Restrictions and otherwise waives the right to collect royalties through +any statutory or compulsory licensing scheme. + +Voluntary License Schemes. The Licensor reserves the right to collect +royalties, whether individually or, in the event that the Licensor is a +member of a collecting society that administers voluntary licensing +schemes, via that society, from any exercise by You of the rights +granted under this License that is for a purpose or use which is +otherwise than noncommercial as permitted under the license grant. + +Except as otherwise agreed in writing by the Licensor or as may be +otherwise permitted by applicable law, if You Reproduce, Distribute or +Publicly Perform the Work either by itself or as part of any Adaptations +or Collections, You must not distort, mutilate, modify or take other +derogatory action in relation to the Work which would be prejudicial to +the Original Author\'s honor or reputation. Licensor agrees that in +those jurisdictions (e.g. Japan), in which any exercise of the right +granted in the license grant of this License (the right to make +Adaptations) would be deemed to be a distortion, mutilation, +modification or other derogatory action prejudicial to the Original +Author\'s honor and reputation, the Licensor will waive or not assert, +as appropriate, this Section, to the fullest extent permitted by the +applicable national law, to enable You to reasonably exercise Your right +under the license grant of this License (right to make Adaptations) but +not otherwise. + +Do not make any legal claim against anyone accusing the Work, with or +without changes, alone or with other works, of infringing any patent +claim. + +# Representations Warranties and Disclaimer + +UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR +OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY +KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, +INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, +FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF +LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, +WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE +EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU. + +# Limitation on Liability + +EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL +LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, +INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF +THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED +OF THE POSSIBILITY OF SUCH DAMAGES. + +# Termination + +This License and the rights granted hereunder will terminate +automatically upon any breach by You of the terms of this License. +Individuals or entities who have received Adaptations or Collections +from You under this License, however, will not have their licenses +terminated provided such individuals or entities remain in full +compliance with those licenses. The Sections on definitions, fair +dealing rights, representations, warranties, and disclaimer, limitation +on liability, termination, and revised license versions will survive any +termination of this License. + +Subject to the above terms and conditions, the license granted here is +perpetual (for the duration of the applicable copyright in the Work). +Notwithstanding the above, Licensor reserves the right to release the +Work under different license terms or to stop distributing the Work at +any time; provided, however that any such election will not serve to +withdraw this License (or any other license that has been, or is +required to be, granted under the terms of this License), and this +License will continue in full force and effect unless terminated as +stated above. + +# Revised License Versions + +This License may receive future revisions in the original spirit of the +license intended to strengthen This License. Each version of This +License has an incrementing version number. + +Unless otherwise specified like in the below subsection The Licensor has +only granted this current version of This License for The Work. In this +case future revisions do not apply. + +The Licensor may specify that the latest available revision of This +License be used for The Work by either explicitly writing so or by +suffixing the License URI with a \"+\" symbol. + +The Licensor may specify that The Work is also available under the terms +of This License\'s current revision as well as specific future +revisions. The Licensor may do this by writing it explicitly or +suffixing the License URI with any additional version numbers each +separated by a comma. + +# Miscellaneous + +Each time You Distribute or Publicly Perform the Work or a Collection, +the Licensor offers to the recipient a license to the Work on the same +terms and conditions as the license granted to You under this License. + +Each time You Distribute or Publicly Perform an Adaptation, Licensor +offers to the recipient a license to the original Work on the same terms +and conditions as the license granted to You under this License. + +If the Work is classified as Software, each time You Distribute or +Publicly Perform an Adaptation, Licensor offers to the recipient a copy +and/or URI of the corresponding Source Code on the same terms and +conditions as the license granted to You under this License. + +If the Work is used as a Network Service, each time You Distribute or +Publicly Perform an Adaptation, or serve data derived from the Software, +the Licensor offers to any recipients of the data a copy and/or URI of +the corresponding Source Code on the same terms and conditions as the +license granted to You under this License. + +If any provision of this License is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this License, and without further action +by the parties to this agreement, such provision shall be reformed to +the minimum extent necessary to make such provision valid and +enforceable. + +No term or provision of this License shall be deemed waived and no +breach consented to unless such waiver or consent shall be in writing +and signed by the party to be charged with such waiver or consent. + +This License constitutes the entire agreement between the parties with +respect to the Work licensed here. There are no understandings, +agreements or representations with respect to the Work not specified +here. Licensor shall not be bound by any additional provisions that may +appear in any communication from You. This License may not be modified +without the mutual written agreement of the Licensor and You. + +The rights granted under, and the subject matter referenced, in this +License were drafted utilizing the terminology of the Berne Convention +for the Protection of Literary and Artistic Works (as amended on +September 28, 1979), the Rome Convention of 1961, the WIPO Copyright +Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and +the Universal Copyright Convention (as revised on July 24, 1971). These +rights and subject matter take effect in the relevant jurisdiction in +which the License terms are sought to be enforced according to the +corresponding provisions of the implementation of those treaty +provisions in the applicable national law. If the standard suite of +rights granted under applicable copyright law includes additional rights +not granted under this License, such additional rights are deemed to be +included in the License; this License is not intended to restrict the +license of any rights under applicable law. diff --git a/README.md b/README.md new file mode 100644 index 0000000..996f795 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# restic-wrapper + +restic-wrapper is a cli wrapper for restic, to make usage with multiple repos +and data sources easier. + +## Installation + +Use the package manager +[cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html) to +install `restic-wrapper`. + +```bash +cargo install restic-wrapper +``` + +## Usage + +```text +$ restic-wrapper --help +Usage: restic-wrapper [OPTIONS] + +Arguments: + + + + [OPTIONS] + +Options: + -h, --help Print help +``` + +For config options, see `config.sample.yaml`. + +## Contributing + +Pull requests are welcome. For major changes, please open an issue first +to discuss what you would like to change. + +Please make sure to update tests as appropriate. + +## License + +[CNPLv7](https://thufie.lain.haus/NPL.html) diff --git a/config.sample.yaml b/config.sample.yaml new file mode 100644 index 0000000..a33b4c1 --- /dev/null +++ b/config.sample.yaml @@ -0,0 +1,17 @@ +--- +repositories: + one: + url: /path/to/local/repo + password: s3cr3t + two: + url: rest:https://user:password@user.repo.borgbase.com + password: s3cr3t +sources: + fs: + path: / + db: + command: pg_dumpall + filename: dump.sql +options: + fs: >- + --exclude-caches diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..a5e7f7c --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,16 @@ +use std::path::PathBuf; + +use clap::Parser; + +#[derive(Parser)] +#[command(author, version, about, long_about)] +pub struct Cli { + /// Path to config file + pub config: PathBuf, + /// Name of repository in config file + pub repository: String, + /// Name of data source in config file + pub source: String, + /// Name of options string in config file + pub options: Option, +} diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..2419440 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,23 @@ +use std::{path::PathBuf, collections::HashMap}; + +use serde::Deserialize; + +#[derive(Deserialize)] +pub struct Config { + pub repositories: HashMap, + pub sources: HashMap, + pub options: HashMap, +} + +#[derive(Deserialize)] +pub struct Repository { + pub url: String, + pub password: String, +} + +#[derive(Deserialize)] +#[serde(untagged)] +pub enum Source { + Path { path: PathBuf }, + Stdin { command: String, filename: PathBuf }, +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..90a66ea --- /dev/null +++ b/src/main.rs @@ -0,0 +1,86 @@ +use std::{ + fs::File, + process::{Command, ExitCode}, +}; + +use anyhow::{Context, Result, bail}; +use clap::Parser; + +mod cli; +mod config; + +use cli::Cli; +use config::{Source, Repository, Config}; + +fn main() -> Result { + let (repository, source, options) = setup()?; + + let exit_status = Command::new("sh").arg("-c") + .arg("restic cat config || restic init") + .env("RESTIC_REPOSITORY", &repository.url) + .env("RESTIC_PASSWORD", &repository.password) + .spawn()?.wait()?; + + if !exit_status.success() { + bail!("Couldn't ensure repository is initialized!") + } + + let mut backup_command = Command::new("sh"); + backup_command + .arg("-c") + .env("RESTIC_REPOSITORY", &repository.url) + .env("RESTIC_PASSWORD", &repository.password); + let command = match source { + Source::Path { path } => backup_command.arg(format!( + "restic backup {} {}", + options, + path.to_string_lossy() + )), + Source::Stdin { command, filename } => backup_command.arg(format!( + "{} | restic backup {} --stdin --stdin-filename '{}'", + command, + options, + filename.to_string_lossy(), + )), + }; + + if let Some(code) = command.spawn()?.wait()?.code() { + let code: u8 = code.try_into()?; + Ok(ExitCode::from(code)) + } else { + Ok(ExitCode::SUCCESS) + } +} + +fn setup() -> Result<(Repository, Source, String)> { + let args = Cli::parse(); + let mut config: Config = serde_yaml::from_reader(File::open(&args.config)?)?; + + let repository = config.repositories.remove(&args.repository).with_context(|| { + format!( + "Repository {} not contained in config file {}", + args.repository, + &args.config.to_string_lossy() + ) + })?; + + let source = config.sources.remove(&args.source).with_context(|| { + format!( + "Source {} not contained in config file {}", + args.source, + &args.config.to_string_lossy() + ) + })?; + + let options = match args.options { + Some(options) => config.options.remove(&options).with_context(|| { + format!( + "Options {} not contained in config file {}", + &options, + &args.config.to_string_lossy() + ) + })?, + None => Default::default(), + }; + Ok((repository, source, options)) +}