├── .github └── workflows │ ├── ci.yml │ └── vulncheck.yml ├── .gitignore ├── .golangci.yml ├── .goreleaser.yml ├── CREDITS ├── LICENSE ├── README.md ├── backup.go ├── certs.go ├── config.srv.env ├── delete.go ├── globals.go ├── go.mod ├── go.sum ├── handlers.go ├── info.go ├── list.go ├── lxc.go ├── lxmin.go ├── main.go ├── notify.go ├── restore.go ├── systemd ├── README.md └── lxmin.service └── testdata ├── client.crt ├── client.key └── server ├── capath ├── client.crt └── public.crt ├── private.key └── public.crt /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | on: 3 | pull_request: 4 | branches: 5 | - main 6 | 7 | # This ensures that previous jobs for the PR are canceled when the PR is 8 | # updated. 9 | concurrency: 10 | group: ${{ github.workflow }}-${{ github.head_ref }} 11 | cancel-in-progress: true 12 | 13 | permissions: 14 | contents: read 15 | 16 | 17 | jobs: 18 | build: 19 | runs-on: ubuntu-latest 20 | strategy: 21 | matrix: 22 | go-version: [ 1.21.x ] 23 | os: [ubuntu-latest] 24 | 25 | steps: 26 | - uses: actions/checkout@v3 27 | - name: Setup Go 28 | uses: actions/setup-go@v4 29 | with: 30 | go-version: ${{ matrix.go-version }} 31 | check-latest: true 32 | - name: Install dependencies 33 | run: go get . 34 | - name: Build 35 | run: go build -v ./... 36 | - name: Test with the Go CLI 37 | run: go test 38 | -------------------------------------------------------------------------------- /.github/workflows/vulncheck.yml: -------------------------------------------------------------------------------- 1 | name: VulnCheck 2 | on: 3 | pull_request: 4 | branches: 5 | - master 6 | - main 7 | push: 8 | branches: 9 | - master 10 | - main 11 | jobs: 12 | vulncheck: 13 | name: Analysis 14 | runs-on: ubuntu-latest 15 | strategy: 16 | matrix: 17 | go-version: [ 1.21.x ] 18 | steps: 19 | - name: Check out code into the Go module directory 20 | uses: actions/checkout@v3 21 | - uses: actions/setup-go@v3 22 | with: 23 | go-version: ${{ matrix.go-version }} 24 | check-latest: true 25 | - name: Get govulncheck 26 | run: go install golang.org/x/vuln/cmd/govulncheck@latest 27 | shell: bash 28 | - name: Run govulncheck 29 | run: govulncheck ./... 30 | shell: bash 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lxmin 2 | *.tar.gz 3 | dist/ 4 | config.env 5 | *~ -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | linters-settings: 2 | golint: 3 | min-confidence: 0 4 | 5 | misspell: 6 | locale: US 7 | 8 | linters: 9 | disable-all: true 10 | enable: 11 | - typecheck 12 | - goimports 13 | - misspell 14 | - govet 15 | - revive 16 | - ineffassign 17 | - gosimple 18 | - deadcode 19 | - structcheck 20 | 21 | issues: 22 | exclude-use-default: false 23 | exclude: 24 | - should have a package comment 25 | - error strings should not be capitalized or end with punctuation or a newline 26 | service: 27 | golangci-lint-version: 1.21.0 # use the fixed version to not introduce new linters unexpectedly 28 | -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | project_name: lxmin 2 | 3 | release: 4 | name_template: "Release version {{.Version}}" 5 | 6 | github: 7 | owner: minio 8 | name: lxmin 9 | 10 | before: 11 | hooks: 12 | - go mod tidy -compat=1.21 13 | 14 | builds: 15 | - 16 | goos: 17 | - linux 18 | - darwin 19 | - windows 20 | goarch: 21 | - amd64 22 | - arm64 23 | - ppc64le 24 | - s390x 25 | ignore: 26 | - goos: windows 27 | goarch: arm64 28 | env: 29 | - CGO_ENABLED=0 30 | flags: 31 | - -trimpath 32 | - --tags=kqueue 33 | ldflags: 34 | - "-s -w -X main.version={{.Version}}" 35 | 36 | archives: 37 | - 38 | name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}" 39 | format: binary 40 | 41 | nfpms: 42 | - 43 | vendor: MinIO, Inc. 44 | homepage: https://github.com/minio/lxmin 45 | maintainer: MinIO Development 46 | description: backup and restore LXC instances from MinIO 47 | license: GNU Affero General Public License v3.0 48 | formats: 49 | - deb 50 | - rpm 51 | contents: 52 | # Basic file that applies to all packagers 53 | - src: systemd/lxmin.service 54 | dst: /etc/systemd/system/lxmin.service 55 | 56 | snapshot: 57 | name_template: v0.0.0@{{.ShortCommit}} 58 | 59 | changelog: 60 | sort: asc 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 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 Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published by 637 | the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lxmin 2 | 3 | Backup and restore LXC instances with MinIO 4 | 5 | ## Install 6 | 7 | ### Binary Releases 8 | 9 | | OS | ARCH | Binary | 10 | |:--------:|:-------:|:------------------------------------------------------------------------------------------------:| 11 | | Linux | amd64 | [linux-amd64](https://github.com/minio/lxmin/releases/latest/download/lxmin-linux-amd64) | 12 | | Linux | arm64 | [linux-arm64](https://github.com/minio/lxmin/releases/latest/download/lxmin-linux-arm64) | 13 | | Linux | ppc64le | [linux-ppc64le](https://github.com/minio/lxmin/releases/latest/download/lxmin-linux-ppc64le) | 14 | | Linux | s390x | [linux-s390x](https://github.com/minio/lxmin/releases/latest/download/lxmin-linux-s390x) | 15 | | Apple M1 | arm64 | [darwin-arm64](https://github.com/minio/lxmin/releases/latest/download/lxmin-darwin-arm64) | 16 | | Apple | amd64 | [darwin-amd64](https://github.com/minio/lxmin/releases/latest/download/lxmin-darwin-amd64) | 17 | | Windows | amd64 | [windows-amd64](https://github.com/minio/lxmin/releases/latest/download/lxmin-windows-amd64.exe) | 18 | 19 | ### Usage 20 | 21 | ```sh 22 | NAME: 23 | lxmin - backup and restore LXC instances with MinIO 24 | 25 | USAGE: 26 | lxmin [FLAGS] COMMAND [COMMAND FLAGS | -h] [ARGUMENTS...] 27 | 28 | COMMANDS: 29 | backup backup an instance image to MinIO 30 | restore restore an instance image from MinIO 31 | info pretty print tags on an instance image on MinIO 32 | list, ls list all backups from MinIO 33 | delete, rm deletes a specific backup by 'name' for an instance from MinIO 34 | 35 | GLOBAL FLAGS: 36 | --endpoint value endpoint for MinIO server [$LXMIN_ENDPOINT] 37 | --bucket value bucket to save/restore backup(s) [$LXMIN_BUCKET] 38 | --access-key value access key credential [$LXMIN_ACCESS_KEY] 39 | --secret-key value secret key credential [$LXMIN_SECRET_KEY] 40 | --address value enable TLS REST API service [$LXMIN_ADDRESS] 41 | --cert value TLS server certificate [$LXMIN_TLS_CERT] 42 | --key value TLS server private key [$LXMIN_TLS_KEY] 43 | --capath value TLS trust certs for incoming clients [$LXMIN_TLS_CAPATH] 44 | --notify-endpoint value HTTP(S) POST endpoint to send notifications for REST API [$LXMIN_NOTIFY_ENDPOINT] 45 | --staging value root path for staging the backups before uploading to MinIO [$LXMIN_STAGING_ROOT] 46 | --help, -h show help 47 | 48 | ENVIRONMENT VARIABLES: 49 | LXMIN_ENDPOINT endpoint for MinIO server 50 | LXMIN_BUCKET bucket to save/restore backup(s) 51 | LXMIN_ACCESS_KEY access key credential 52 | LXMIN_SECRET_KEY secret key credential 53 | LXMIN_ADDRESS enable TLS REST API service 54 | LXMIN_TLS_CERT TLS server certificate 55 | LXMIN_TLS_KEY TLS server private key 56 | LXMIN_TLS_CAPATH TLS trust certs for incoming clients 57 | LXMIN_NOTIFY_ENDPOINT HTTP(S) POST endpoint to send notifications for REST API 58 | LXMIN_STAGING_ROOT root path for staging the backups before uploading to MinIO 59 | 60 | ``` 61 | 62 | ## REST API 63 | 64 | `lxmin` exposes an mTLS authentication based REST API. HTTPs is mandatory for this service so you would need relevant server and client public certs. We recommend that you re-use your LXD server certificates. 65 | 66 | ```sh 67 | export LXMIN_ENDPOINT=http://147.75.71.77:9000 68 | export LXMIN_BUCKET="backups" 69 | export LXMIN_ACCESS_KEY="minioadmin" 70 | export LXMIN_SECRET_KEY="minioadmin" 71 | export LXMIN_ADDRESS=":8000" 72 | export LXMIN_NOTIFY_ENDPOINT="https://webhook.site/9d86f64f-78dd-4cbc-bd6c-5fbd90ef1701" 73 | export LXMIN_TLS_CERT="/var/snap/lxd/common/lxd/server.crt" 74 | export LXMIN_TLS_KEY="/var/snap/lxd/common/lxd/server.key" 75 | export LXMIN_TLS_CAPATH="${HOME}/.lxc/" 76 | 77 | lxmin 78 | 2022/02/26 08:31:51 Server listening on :8000 79 | ``` 80 | 81 | The spirit of this this API is to be close to LXD REST API documentation, authentication shall be achieved using the similar mTLS based authentication as per LXD REST API documentation 82 | 83 | | Method | API | Desc | 84 | |:-------|:---------------------------------------|:-------------------------------------------------------------------------------------------------------------------------| 85 | | POST | /1.0/instances/{name}/backups | Create a backup to MinIO (Optionally you can add x-amz-tagging: "key=value" format to add additional tags on the backup) | 86 | | GET | /1.0/instances/{name}/backups/{backup} | Get backup specific metadata and information | 87 | | POST | /1.0/instances/{name}/backups/{backup} | Restore a backup from MinIO | 88 | | GET | /1.0/instances/{name}/backups | Get the backups (Returns a list of instance backups on MinIO, along with some addtional metadata) | 89 | | DELETE | /1.0/instances/{name}/backups/{backup} | Delete a backup from MinIO | 90 | 91 | Response type for this API will be always `application/json` 92 | 93 | ### POST /1.0/instances/{name}/backups 94 | 95 | | Query Params | Desc | 96 | |:---------------|:------------------------------------------------------------------------------------| 97 | | optimize | enables optimized backup for faster restore operations | 98 | | tags | allow custom tags on the current backup | 99 | | notifyEndpoint | notification endpoint for success/failed backup operation (overrides env/CLI value) | 100 | | partSize | custom part size used for uploading to MinIO storage, defaults to '67108864' | 101 | 102 | Response example: 103 | 104 | ```json 105 | { 106 | "metadata": { 107 | "name": "backup_2022-02-26-07-5218", 108 | "optimized": true, 109 | "compressed": true 110 | }, 111 | "status": "Operation created", 112 | "status_code": 100, 113 | "type": "async" 114 | } 115 | ``` 116 | 117 | ### GET /1.0/instances/{name}/backups/{backup} 118 | 119 | Response example when backup is generated: 120 | 121 | ```json 122 | { 123 | "metadata": { 124 | "name": "backup_2022-03-01-00-2142.tar.gz", 125 | "state": "generating", 126 | "progress": 0 127 | }, 128 | "status": "Success", 129 | "status_code": 200, 130 | "type": "sync" 131 | } 132 | ``` 133 | 134 | Response example when backup is being uploaded: 135 | 136 | ```json 137 | { 138 | "metadata": { 139 | "name": "backup_2022-03-01-00-2530.tar.gz", 140 | "size": 555339059, 141 | "state": "uploading", 142 | "progress": 40206336 143 | }, 144 | "status": "Success", 145 | "status_code": 200, 146 | "type": "sync" 147 | } 148 | ``` 149 | 150 | Response example when backup is persisted: 151 | 152 | ```json 153 | { 154 | "metadata": { 155 | "name": "backup_2022-02-26-08-2027.tar.gz", 156 | "created": "2022-02-26T08:22:12Z", 157 | "size": 1302974262, 158 | "optimized": true, 159 | "compressed": true, 160 | "tags": { 161 | "os": "Ubuntu", 162 | "version": "20.04" 163 | } 164 | }, 165 | "status": "Success", 166 | "status_code": 200, 167 | "type": "sync" 168 | } 169 | ``` 170 | 171 | ### POST /1.0/instances/{name}/backups/{backup} 172 | 173 | | Query Params | Desc | 174 | |:---------------|:-------------------------------------------------------------------------------------| 175 | | notifyEndpoint | notification endpoint for success/failed restore operation (overrides env/CLI value) | 176 | 177 | Response example: 178 | 179 | ```json 180 | { 181 | "status": "Operation created", 182 | "status_code": 100, 183 | "type": "async" 184 | } 185 | ``` 186 | 187 | ### GET /1.0/instances/{name}/backups 188 | 189 | Response example: 190 | 191 | ```json 192 | { 193 | "metadata": [ 194 | { 195 | "name": "backup_2022-02-17-08-3732", 196 | "created": "2022-02-17T08:38:47.609Z", 197 | "size": 913921606, 198 | "optimized": true, 199 | "compressed": false 200 | }, 201 | { 202 | "name": "backup_2022-02-17-09-0524", 203 | "created": "2022-02-17T09:06:39.324Z", 204 | "size": 913898354, 205 | "optimized": true, 206 | "compressed": false 207 | }, 208 | { 209 | "name": "backup_2022-02-17-09-3329", 210 | "created": "2022-02-17T09:34:44.868Z", 211 | "size": 913879736, 212 | "optimized": true, 213 | "compressed": false 214 | }, 215 | { 216 | "name": "backup_2022-02-26-07-3921", 217 | "created": "2022-02-26T07:41:07.868Z", 218 | "size": 1303072030, 219 | "optimized": true, 220 | "compressed": true 221 | } 222 | ], 223 | "status": "Success", 224 | "status_code": 200, 225 | "type": "sync" 226 | } 227 | ``` 228 | 229 | ### DELETE /1.0/instances/{name}/backups/{backup} 230 | 231 | Response example: 232 | 233 | ```json 234 | { 235 | "status": "Success", 236 | "status_code": 200, 237 | "type": "sync" 238 | } 239 | ``` 240 | 241 | ## CLI (command line) 242 | 243 | `lxmin` can be run as a manual tool to manage your `lxc` backups. 244 | 245 | ### Create a backup 246 | 247 | ```sh 248 | export LXMIN_ENDPOINT=http://147.75.71.77:9000 249 | export LXMIN_BUCKET="backups" 250 | export LXMIN_ACCESS_KEY="minioadmin" 251 | export LXMIN_SECRET_KEY="minioadmin" 252 | 253 | lxmin backup u2 --tags "OS=Ubuntu&Version=20.04&Build=10" 254 | Preparing backup for (u2) instance: success 255 | Uploading backup_2022-02-17-09-3329.tar.gz ┃▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┃ 100.12 MiB/s 256 | ``` 257 | 258 | ### Create an optimized backup 259 | 260 | Optimize flag enables faster restore time. It is only supported for ZFS, BTRFS, RBD based storage pools. 261 | 262 | ```sh 263 | lxmin backup u2 --optimize 264 | Preparing backup for (u2) instance: success 265 | Uploading backup_2022-02-17-09-3329.tar.gz ┃▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┃ 100.12 MiB/s 266 | ``` 267 | 268 | ### List all backups 269 | 270 | ```sh 271 | lxmin list 272 | ┌──────────┐┌───────────────────────────┐┌─────────────────────────┐┌─────────┐┌───────────┐ 273 | │ Instance ││ Name ││ Created ││ Size ││ Optimized │ 274 | │ ││ ││ ││ ││ │ 275 | │ u2 ││ backup_2022-02-17-08-3732 ││ 2022-02-17 08:38:47 UTC ││ 872 MiB ││ ✔ │ 276 | │ u2 ││ backup_2022-02-17-09-0524 ││ 2022-02-17 09:06:39 UTC ││ 872 MiB ││ ✔ │ 277 | │ u2 ││ backup_2022-02-17-09-3329 ││ 2022-02-17 09:34:44 UTC ││ 872 MiB ││ ✔ │ 278 | └──────────┘└───────────────────────────┘└─────────────────────────┘└─────────┘└───────────┘ 279 | ``` 280 | 281 | ### Restore a backup 282 | 283 | ```sh 284 | lxmin restore u2 backup_2022-02-17-09-3329 285 | Downloading backup_2022-02-17-09-3329.tar.gz ┃▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┃ 209.10 MiB/s 286 | Launching instance (u2) from backup: success 287 | ``` 288 | 289 | ### Display backup info 290 | 291 | ```sh 292 | Name : backup_2022-02-17-09-3329 293 | Date : 2022-02-17 09:34:44 UTC 294 | Size : 872 MiB 295 | Tags : 296 | Version : 20.04 297 | Build : 10 298 | OS : Ubuntu 299 | Metadata : 300 | Optimized : ✔ 301 | Compressed: ✔ 302 | ``` 303 | 304 | ### Delete a backup 305 | 306 | Delete a backup by name `backup_2022-02-16-04-1040` 307 | 308 | ```sh 309 | lxmin delete u2 backup_2022-02-16-04-1040 310 | Backup backup_2022-02-16-04-1040 deleted successfully 311 | ``` 312 | 313 | Delete all backups (dangerous operation) 314 | 315 | ```sh 316 | lxmin delete u2 --all --force 317 | All backups for u2 deleted successfully 318 | ``` 319 | -------------------------------------------------------------------------------- /backup.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2022 MinIO, Inc. 2 | // 3 | // This project is part of MinIO Object Storage stack 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Affero General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Affero General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with this program. If not, see . 17 | 18 | package main 19 | 20 | import ( 21 | "context" 22 | "fmt" 23 | "io" 24 | "log" 25 | "mime" 26 | "os" 27 | "path" 28 | "strconv" 29 | "strings" 30 | "time" 31 | 32 | tea "github.com/charmbracelet/bubbletea" 33 | "github.com/cheggaaa/pb/v3" 34 | "github.com/dustin/go-humanize" 35 | "github.com/minio/cli" 36 | "github.com/minio/minio-go/v7" 37 | "github.com/minio/minio-go/v7/pkg/tags" 38 | ) 39 | 40 | var backupFlags = []cli.Flag{ 41 | cli.BoolFlag{ 42 | Name: "optimized, O", 43 | Usage: "use storage driver optimized format", 44 | }, 45 | cli.StringFlag{ 46 | Name: "tags", 47 | Usage: "add additional tags for the backup", 48 | }, 49 | cli.Int64Flag{ 50 | Name: "part-size", 51 | Value: 64 * humanize.MiByte, 52 | Usage: "configure upload part size per transfer", 53 | }, 54 | } 55 | 56 | var backupCmd = cli.Command{ 57 | Name: "backup", 58 | Usage: "backup an instance image to MinIO", 59 | Action: backupMain, 60 | Before: setGlobalsFromContext, 61 | Flags: append(backupFlags, globalFlags...), 62 | CustomHelpTemplate: `NAME: 63 | {{.HelpName}} - {{.Usage}} 64 | 65 | USAGE: 66 | {{.HelpName}} [FLAGS] INSTANCENAME 67 | 68 | FLAGS: 69 | {{range .VisibleFlags}}{{.}} 70 | {{end}} 71 | EXAMPLES: 72 | 1. Backup an instance 'u2' with storage optimized (faster imports): 73 | {{.Prompt}} {{.HelpName}} u2 --optimized 74 | 2. Backup an instance 'u2', add custom tags of 'k1=v1&k2=v2' form: 75 | {{.Prompt}} {{.HelpName}} u2 --optimized --tags "category=prod&project=backup" 76 | 3. Backup a remote instance 'u3' on remote 'mylxdserver': 77 | {{.Prompt}} {{.HelpName}} mylxdserver:u3 --optimized 78 | `, 79 | } 80 | 81 | func backupMain(c *cli.Context) error { 82 | if len(c.Args()) > 1 { 83 | cli.ShowAppHelpAndExit(c, 1) // last argument is exit code 84 | } 85 | 86 | instance := strings.TrimSpace(c.Args().Get(0)) 87 | if instance == "" { 88 | cli.ShowAppHelpAndExit(c, 1) // last argument is exit code 89 | } 90 | 91 | partSize := c.Int64("part-size") 92 | if partSize == 0 { 93 | partSize = 64 * humanize.MiByte 94 | } 95 | 96 | tagsHdr := c.String("tags") 97 | tagsSet, err := tags.Parse(tagsHdr, true) 98 | if err != nil { 99 | return err 100 | } 101 | 102 | if err := checkInstance(instance); err == nil { 103 | return fmt.Errorf("no instance found by name: '%s'", instance) 104 | } 105 | 106 | backupNamePrefix := "backup_" + time.Now().Format("2006-01-02-15-0405") 107 | 108 | // Save profiles to files. 109 | profiles, profileInfo, err := backupProfiles(globalContext, instance, backupNamePrefix) 110 | if err != nil { 111 | return err 112 | } 113 | 114 | instanceBackupName, instanceBackupSize, err := backupInstance(globalContext, c.Bool("optimized"), instance, backupNamePrefix) 115 | if err != nil { 116 | return err 117 | } 118 | 119 | // Backup to MinIO 120 | 121 | // Collect total upload size. 122 | var totalSize int64 123 | backupPath := path.Join(globalContext.StagingRoot, instanceBackupName) 124 | if st, err := os.Stat(backupPath); err != nil { 125 | return fmt.Errorf("Unable to stat file %s: %v", backupPath, err) 126 | } else { 127 | totalSize = st.Size() 128 | } 129 | for _, v := range profileInfo { 130 | totalSize += v.Size 131 | } 132 | 133 | progress := pb.Start64(totalSize) 134 | progress.Set(pb.Bytes, true) 135 | 136 | if err := uploadInstanceBackup(globalContext, c.Bool("optimized"), instance, instanceBackupName, instanceBackupSize, progress, tagsSet, partSize); err != nil { 137 | return err 138 | } 139 | if err := uploadProfilesBackup(globalContext, instance, profiles, profileInfo, progress, tagsSet, partSize); err != nil { 140 | return err 141 | } 142 | 143 | progress.Finish() 144 | return err 145 | } 146 | 147 | func uploadInstanceBackup(ctx *lxminContext, optimized bool, instance, backupName string, size int64, bar *pb.ProgressBar, tagsSet *tags.Tags, partSize int64) error { 148 | usermetadata := map[string]string{} 149 | // Save additional information if the backup is optimized or not. 150 | usermetadata["optimized"] = strconv.FormatBool(optimized) 151 | usermetadata["compressed"] = "true" // This is always true. 152 | 153 | fpath := path.Join(ctx.StagingRoot, backupName) 154 | barReader, err := newBarUpdateReader(fpath, bar, tmplUp) 155 | if err != nil { 156 | return err 157 | } 158 | 159 | defer barReader.Close() 160 | defer os.Remove(fpath) 161 | opts := minio.PutObjectOptions{ 162 | UserTags: tagsSet.ToMap(), 163 | PartSize: uint64(partSize), 164 | UserMetadata: usermetadata, 165 | ContentType: mime.TypeByExtension(".tar.gz"), 166 | } 167 | _, err = globalContext.Clnt.PutObject(context.Background(), globalContext.Bucket, path.Join(instance, backupName), barReader, size, opts) 168 | if err != nil { 169 | return fmt.Errorf("Error uploading file %s: %v", fpath, err) 170 | } 171 | return nil 172 | } 173 | 174 | func uploadProfilesBackup(ctx *lxminContext, instance string, pList []string, prInfo map[string]profileInfo, bar *pb.ProgressBar, tagsSet *tags.Tags, partSize int64) error { 175 | for _, profile := range pList { 176 | err := func() error { 177 | profileFile := prInfo[profile].FileName 178 | size := prInfo[profile].Size 179 | fpath := path.Join(ctx.StagingRoot, profileFile) 180 | barReader, err := newBarUpdateReader(fpath, bar, tmplUp) 181 | if err != nil { 182 | return err 183 | } 184 | defer barReader.Close() 185 | defer os.Remove(fpath) 186 | 187 | opts := minio.PutObjectOptions{ 188 | UserTags: tagsSet.ToMap(), 189 | PartSize: uint64(partSize), 190 | ContentType: mime.TypeByExtension(".yaml"), 191 | } 192 | _, err = ctx.Clnt.PutObject(context.Background(), ctx.Bucket, path.Join(instance, profileFile), barReader, size, opts) 193 | if err != nil { 194 | return fmt.Errorf("Error uploading file %s: %v", fpath, err) 195 | } 196 | return nil 197 | }() 198 | if err != nil { 199 | return err 200 | } 201 | } 202 | return nil 203 | } 204 | 205 | type barUpdateReader struct { 206 | r io.Reader 207 | bar *pb.ProgressBar 208 | } 209 | 210 | func newBarUpdateReader(fpath string, bar *pb.ProgressBar, tmpl string) (*barUpdateReader, error) { 211 | r, err := os.Open(fpath) 212 | if err != nil { 213 | return nil, fmt.Errorf("Unable to open %s: %v", fpath, err) 214 | } 215 | 216 | bar.SetTemplateString(fmt.Sprintf(tmpl, path.Base(fpath))) 217 | 218 | return &barUpdateReader{ 219 | r: r, 220 | bar: bar, 221 | }, nil 222 | } 223 | 224 | func (b *barUpdateReader) Read(p []byte) (n int, err error) { 225 | n, err = b.r.Read(p) 226 | b.bar.Add(n) 227 | return 228 | } 229 | 230 | // Close closes the underlying reader if it is a io.Closer. 231 | func (b *barUpdateReader) Close() error { 232 | if c, ok := b.r.(io.Closer); ok { 233 | return c.Close() 234 | } 235 | return nil 236 | } 237 | 238 | func backupInstance(ctx *lxminContext, optimized bool, instance, backupNamePrefix string) (string, int64, error) { 239 | backup := backupNamePrefix + "_instance.tar.gz" 240 | localPath := path.Join(ctx.StagingRoot, backup) 241 | 242 | var size int64 243 | exportFn := func() tea.Msg { 244 | n, err := exportInstance(instance, localPath, optimized) 245 | if err != nil { 246 | return err 247 | } 248 | 249 | size = n 250 | return true 251 | } 252 | 253 | ui := initCmdSpinnerUI(exportFn, cOpts{ 254 | instance: instance, 255 | message: `%s Preparing backup for instance: %s`, 256 | }) 257 | 258 | if err := tea.NewProgram(ui).Start(); err != nil { 259 | log.Fatalln(err) 260 | } 261 | 262 | return backup, size, nil 263 | } 264 | 265 | type profileInfo struct { 266 | FileName string 267 | Size int64 268 | } 269 | 270 | func backupProfiles(ctx *lxminContext, instance, backupNamePrefix string) ([]string, map[string]profileInfo, error) { 271 | var profiles []string 272 | { 273 | listProfilesFn := func() tea.Msg { 274 | ps, err := listProfiles(instance) 275 | if err != nil { 276 | return err 277 | } 278 | 279 | profiles = ps 280 | return true 281 | } 282 | ui := initCmdSpinnerUI(listProfilesFn, cOpts{ 283 | instance: instance, 284 | message: `%s Listing profiles for instance: %s`, 285 | }) 286 | if err := tea.NewProgram(ui).Start(); err != nil { 287 | log.Fatalln(err) 288 | } 289 | } 290 | 291 | if len(profiles) > 1000 { 292 | log.Fatalf("More than a 1000 profiles per instance not supported.") 293 | } 294 | 295 | pInfo := make(map[string]profileInfo, len(profiles)) 296 | for pno, profile := range profiles { 297 | // Profiles are numbered because their order matters - settings 298 | // in the later profiles override those from earlier profiles. 299 | profileFile := fmt.Sprintf("%s_profile_%03d_%s.yaml", backupNamePrefix, pno, profile) 300 | profilePath := path.Join(ctx.StagingRoot, profileFile) 301 | 302 | var prSize int64 303 | exportProfileFn := func() tea.Msg { 304 | n, err := exportProfile(profile, profilePath) 305 | if err != nil { 306 | return err 307 | } 308 | prSize = n 309 | return true 310 | } 311 | 312 | ui := initCmdSpinnerUI(exportProfileFn, cOpts{ 313 | instance: instance, 314 | message: `%s Fetching profile '` + profile + `' for instance: %s`, 315 | }) 316 | 317 | if err := tea.NewProgram(ui).Start(); err != nil { 318 | log.Fatalln(err) 319 | } 320 | 321 | pInfo[profile] = profileInfo{ 322 | FileName: profileFile, 323 | Size: prSize, 324 | } 325 | } 326 | 327 | return profiles, pInfo, nil 328 | } 329 | -------------------------------------------------------------------------------- /certs.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2022 MinIO, Inc. 2 | // 3 | // This project is part of MinIO Object Storage stack 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Affero General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Affero General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with this program. If not, see . 17 | 18 | package main 19 | 20 | import ( 21 | "bytes" 22 | "crypto" 23 | "crypto/ecdsa" 24 | "crypto/tls" 25 | "crypto/x509" 26 | "encoding/pem" 27 | "errors" 28 | "fmt" 29 | "io/ioutil" 30 | ) 31 | 32 | // parsePublicCertFile - parses public cert into its *x509.Certificate equivalent. 33 | func parsePublicCertFile(certFile string) (x509Certs []*x509.Certificate, err error) { 34 | // Read certificate file. 35 | var data []byte 36 | if data, err = ioutil.ReadFile(certFile); err != nil { 37 | return nil, err 38 | } 39 | 40 | // Trimming leading and tailing white spaces. 41 | data = bytes.TrimSpace(data) 42 | 43 | // Parse all certs in the chain. 44 | current := data 45 | for len(current) > 0 { 46 | var pemBlock *pem.Block 47 | if pemBlock, current = pem.Decode(current); pemBlock == nil { 48 | return nil, fmt.Errorf("could not read PEM block from file %s", certFile) 49 | } 50 | 51 | var x509Cert *x509.Certificate 52 | if x509Cert, err = x509.ParseCertificate(pemBlock.Bytes); err != nil { 53 | return nil, fmt.Errorf("failed to parse `%s`: %v", certFile, err) 54 | } 55 | 56 | x509Certs = append(x509Certs, x509Cert) 57 | } 58 | 59 | if len(x509Certs) == 0 { 60 | return nil, fmt.Errorf("empty public certificate file %s", certFile) 61 | } 62 | 63 | return x509Certs, nil 64 | } 65 | 66 | // loadX509KeyPair - load an X509 key pair (private key , certificate) 67 | // from the provided paths. 68 | func loadX509KeyPair(certFile, keyFile string) (tls.Certificate, error) { 69 | certPEMBlock, err := ioutil.ReadFile(certFile) 70 | if err != nil { 71 | return tls.Certificate{}, err 72 | } 73 | keyPEMBlock, err := ioutil.ReadFile(keyFile) 74 | if err != nil { 75 | return tls.Certificate{}, err 76 | } 77 | key, rest := pem.Decode(keyPEMBlock) 78 | if len(rest) > 0 { 79 | return tls.Certificate{}, errors.New("private key contains additional data") 80 | } 81 | if key == nil { 82 | return tls.Certificate{}, errors.New("private key is not readable") 83 | } 84 | if x509.IsEncryptedPEMBlock(key) { 85 | // FIXME: support 86 | return tls.Certificate{}, errors.New("encrypted private keys are not supported") 87 | } 88 | cert, err := tls.X509KeyPair(certPEMBlock, keyPEMBlock) 89 | if err != nil { 90 | return tls.Certificate{}, err 91 | } 92 | // Ensure that the private key is not a P-384 or P-521 EC key. 93 | // The Go TLS stack does not provide constant-time implementations of P-384 and P-521. 94 | if priv, ok := cert.PrivateKey.(crypto.Signer); ok { 95 | if pub, ok := priv.Public().(*ecdsa.PublicKey); ok { 96 | switch pub.Params().Name { 97 | case "P-521": 98 | // unfortunately there is no cleaner way to check 99 | return tls.Certificate{}, fmt.Errorf("tls: the ECDSA curve '%s' is not supported", pub.Params().Name) 100 | } 101 | } 102 | } 103 | return cert, nil 104 | } 105 | -------------------------------------------------------------------------------- /config.srv.env: -------------------------------------------------------------------------------- 1 | export LXMIN_ENDPOINT=http://localhost:9000 2 | export LXMIN_BUCKET="backups" 3 | export LXMIN_ACCESS_KEY="minioadmin" 4 | export LXMIN_SECRET_KEY="minioadmin" 5 | export LXMIN_ADDRESS=":8000" 6 | export LXMIN_TLS_CERT="/var/snap/lxd/common/lxd/server.crt" 7 | export LXMIN_TLS_KEY="/var/snap/lxd/common/lxd/server.key" 8 | export LXMIN_TLS_CAPATH="/home/harsha/go/src/github.com/minio/certgen" 9 | export LXMIN_STAGING_ROOT="/var/lib/lxd/backups" -------------------------------------------------------------------------------- /delete.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2022 MinIO, Inc. 2 | // 3 | // This project is part of MinIO Object Storage stack 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Affero General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Affero General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with this program. If not, see . 17 | 18 | package main 19 | 20 | import ( 21 | "errors" 22 | "fmt" 23 | "strings" 24 | 25 | "github.com/minio/cli" 26 | ) 27 | 28 | var deleteFlags = []cli.Flag{ 29 | cli.BoolFlag{ 30 | Name: "all", 31 | Usage: "delete all backups for an instance", 32 | }, 33 | cli.BoolFlag{ 34 | Name: "force", 35 | Usage: "allow all backups to be deleted, only valid when '--all' is specified", 36 | }, 37 | } 38 | 39 | var deleteCmd = cli.Command{ 40 | Name: "delete", 41 | Aliases: []string{"rm"}, 42 | Usage: "deletes a specific backup by 'name' for an instance from MinIO", 43 | Action: deleteMain, 44 | Before: setGlobalsFromContext, 45 | Flags: append(deleteFlags, globalFlags...), 46 | CustomHelpTemplate: `NAME: 47 | {{.HelpName}} - {{.Usage}} 48 | 49 | USAGE: 50 | {{.HelpName}} [FLAGS] INSTANCENAME BACKUPNAME 51 | 52 | TIP: 53 | --all --force flags can be provided without 'BACKUPNAME' to delete all backups. 54 | 55 | FLAGS: 56 | {{range .VisibleFlags}}{{.}} 57 | {{end}} 58 | EXAMPLES: 59 | 1. Delete a backup 'backup_2022-02-16-04-1040' for instance 'u2': 60 | {{.Prompt}} {{.HelpName}} u2 backup_2022-02-16-04-1040 61 | `, 62 | } 63 | 64 | func deleteMain(c *cli.Context) error { 65 | if len(c.Args()) > 2 { 66 | cli.ShowAppHelpAndExit(c, 1) // last argument is exit code 67 | } 68 | 69 | instance := strings.TrimSpace(c.Args().Get(0)) 70 | if instance == "" { 71 | cli.ShowAppHelpAndExit(c, 1) // last argument is exit code 72 | } 73 | 74 | backupName := strings.TrimSpace(c.Args().Get(1)) 75 | deleteAll := c.Bool("all") 76 | isForceOn := c.Bool("force") 77 | 78 | if backupName != "" && deleteAll { 79 | return errors.New("backup name is not required with --all") 80 | } 81 | 82 | if backupName == "" && !deleteAll { 83 | return errors.New("Use the --all flag to delete all backups or provide a backup name") 84 | } 85 | 86 | if backupName != "" && deleteAll && !isForceOn { 87 | return errors.New("DANGEROUS operation: this will delete **all** backups for the given instance - if you are sure add the --force flag") 88 | } 89 | 90 | var err error 91 | if backupName != "" { 92 | bkp := backup{instance: instance, backupName: backupName} 93 | err = globalContext.DeleteBackup(bkp) 94 | } else { 95 | err = globalContext.DeleteAllBackups(instance) 96 | } 97 | if err != nil { 98 | return err 99 | } 100 | 101 | if deleteAll { 102 | fmt.Printf("All backups for '%s' deleted successfully\n", instance) 103 | } else { 104 | fmt.Printf("Backup '%s' deleted successfully\n", backupName) 105 | } 106 | return nil 107 | } 108 | -------------------------------------------------------------------------------- /globals.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2022 MinIO, Inc. 2 | // 3 | // This project is part of MinIO Object Storage stack 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Affero General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Affero General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with this program. If not, see . 17 | 18 | package main 19 | 20 | import ( 21 | "context" 22 | "crypto/tls" 23 | "net" 24 | "net/http" 25 | "net/url" 26 | "time" 27 | 28 | "github.com/minio/cli" 29 | "github.com/minio/minio-go/v7" 30 | "github.com/minio/minio-go/v7/pkg/credentials" 31 | "github.com/minio/pkg/v2/certs" 32 | ) 33 | 34 | var globalContext *lxminContext 35 | 36 | // Set global states. NOTE: It is deliberately kept monolithic to ensure we dont miss out any flags. 37 | func setGlobalsFromContext(c *cli.Context) error { 38 | u, err := url.Parse(c.String("endpoint")) 39 | if err != nil { 40 | return err 41 | } 42 | 43 | s3Client, err := minio.New(u.Host, &minio.Options{ 44 | Creds: credentials.NewStaticV4(c.String("access-key"), c.String("secret-key"), ""), 45 | Secure: u.Scheme == "https", 46 | }) 47 | if err != nil { 48 | return err 49 | } 50 | 51 | globalContext = &lxminContext{ 52 | Clnt: s3Client, 53 | Bucket: c.String("bucket"), 54 | StagingRoot: c.String("staging"), 55 | } 56 | 57 | if c.String("cert") != "" || c.String("key") != "" { 58 | tlsCerts, err := certs.NewManager(context.Background(), c.String("cert"), c.String("key"), loadX509KeyPair) 59 | if err != nil { 60 | return err 61 | } 62 | 63 | publicCerts, err := parsePublicCertFile(c.String("cert")) 64 | if err != nil { 65 | return err 66 | } 67 | 68 | rootCAs, err := certs.GetRootCAs(c.String("capath")) 69 | if err != nil { 70 | return err 71 | } 72 | 73 | for _, cert := range publicCerts { 74 | rootCAs.AddCert(cert) 75 | } 76 | 77 | globalContext.TLSCerts = tlsCerts 78 | globalContext.RootCAs = rootCAs 79 | } 80 | 81 | globalContext.NotifyEndpoint = c.String("notify-endpoint") 82 | globalContext.NotifyClnt = &http.Client{ 83 | Transport: &http.Transport{ 84 | Proxy: http.ProxyFromEnvironment, 85 | DialContext: (&net.Dialer{ 86 | Timeout: 30 * time.Second, 87 | KeepAlive: 30 * time.Second, 88 | }).DialContext, 89 | MaxIdleConns: 256, 90 | MaxIdleConnsPerHost: 16, 91 | ResponseHeaderTimeout: time.Minute, 92 | IdleConnTimeout: time.Minute, 93 | TLSHandshakeTimeout: 10 * time.Second, 94 | ExpectContinueTimeout: 10 * time.Second, 95 | // Set this value so that the underlying transport round-tripper 96 | // doesn't try to auto decode the body of objects with 97 | // content-encoding set to `gzip`. 98 | // 99 | // Refer: 100 | // https://golang.org/src/net/http/transport.go?h=roundTrip#L1843 101 | DisableCompression: true, 102 | TLSClientConfig: &tls.Config{ 103 | // Can't use SSLv3 because of POODLE and BEAST 104 | // Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher 105 | // Can't use TLSv1.1 because of RC4 cipher usage 106 | MinVersion: tls.VersionTLS12, 107 | RootCAs: globalContext.RootCAs, 108 | }, 109 | }, 110 | } 111 | 112 | return nil 113 | } 114 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/minio/lxmin 2 | 3 | go 1.21 4 | 5 | require ( 6 | github.com/charmbracelet/bubbles v0.15.0 7 | github.com/charmbracelet/bubbletea v0.23.2 8 | github.com/charmbracelet/lipgloss v0.6.0 9 | github.com/cheggaaa/pb/v3 v3.1.0 10 | github.com/dustin/go-humanize v1.0.1 11 | github.com/gorilla/handlers v1.5.1 12 | github.com/gorilla/mux v1.8.0 13 | github.com/minio/cli v1.24.2 14 | github.com/minio/minio-go/v7 v7.0.63 15 | github.com/minio/pkg/v2 v2.0.2 16 | gopkg.in/yaml.v2 v2.4.0 17 | ) 18 | 19 | require ( 20 | github.com/VividCortex/ewma v1.2.0 // indirect 21 | github.com/aymanbagabas/go-osc52 v1.2.1 // indirect 22 | github.com/containerd/console v1.0.3 // indirect 23 | github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect 24 | github.com/fatih/color v1.14.1 // indirect 25 | github.com/felixge/httpsnoop v1.0.3 // indirect 26 | github.com/goccy/go-json v0.10.2 // indirect 27 | github.com/google/uuid v1.3.0 // indirect 28 | github.com/json-iterator/go v1.1.12 // indirect 29 | github.com/klauspost/compress v1.16.7 // indirect 30 | github.com/klauspost/cpuid/v2 v2.2.5 // indirect 31 | github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect 32 | github.com/lestrrat-go/blackmagic v1.0.1 // indirect 33 | github.com/lestrrat-go/httpcc v1.0.1 // indirect 34 | github.com/lestrrat-go/iter v1.0.2 // indirect 35 | github.com/lestrrat-go/jwx v1.2.26 // indirect 36 | github.com/lestrrat-go/option v1.0.1 // indirect 37 | github.com/lucasb-eyer/go-colorful v1.2.0 // indirect 38 | github.com/mattn/go-colorable v0.1.13 // indirect 39 | github.com/mattn/go-isatty v0.0.17 // indirect 40 | github.com/mattn/go-localereader v0.0.1 // indirect 41 | github.com/mattn/go-runewidth v0.0.14 // indirect 42 | github.com/minio/md5-simd v1.1.2 // indirect 43 | github.com/minio/sha256-simd v1.0.1 // indirect 44 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 45 | github.com/modern-go/reflect2 v1.0.2 // indirect 46 | github.com/muesli/ansi v0.0.0-20221106050444-61f0cd9a192a // indirect 47 | github.com/muesli/cancelreader v0.2.2 // indirect 48 | github.com/muesli/reflow v0.3.0 // indirect 49 | github.com/muesli/termenv v0.14.0 // indirect 50 | github.com/pkg/errors v0.9.1 // indirect 51 | github.com/rivo/uniseg v0.4.4 // indirect 52 | github.com/rjeczalik/notify v0.9.3 // indirect 53 | github.com/rs/xid v1.5.0 // indirect 54 | github.com/sirupsen/logrus v1.9.3 // indirect 55 | golang.org/x/crypto v0.12.0 // indirect 56 | golang.org/x/net v0.14.0 // indirect 57 | golang.org/x/sync v0.1.0 // indirect 58 | golang.org/x/sys v0.11.0 // indirect 59 | golang.org/x/term v0.11.0 // indirect 60 | golang.org/x/text v0.12.0 // indirect 61 | gopkg.in/ini.v1 v1.67.0 // indirect 62 | ) 63 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 2 | github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= 3 | github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow= 4 | github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4= 5 | github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= 6 | github.com/aymanbagabas/go-osc52 v1.0.3/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4= 7 | github.com/aymanbagabas/go-osc52 v1.2.1 h1:q2sWUyDcozPLcLabEMd+a+7Ea2DitxZVN9hTxab9L4E= 8 | github.com/aymanbagabas/go-osc52 v1.2.1/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4= 9 | github.com/charmbracelet/bubbles v0.15.0 h1:c5vZ3woHV5W2b8YZI1q7v4ZNQaPetfHuoHzx+56Z6TI= 10 | github.com/charmbracelet/bubbles v0.15.0/go.mod h1:Y7gSFbBzlMpUDR/XM9MhZI374Q+1p1kluf1uLl8iK74= 11 | github.com/charmbracelet/bubbletea v0.23.1/go.mod h1:JAfGK/3/pPKHTnAS8JIE2u9f61BjWTQY57RbT25aMXU= 12 | github.com/charmbracelet/bubbletea v0.23.2 h1:vuUJ9HJ7b/COy4I30e8xDVQ+VRDUEFykIjryPfgsdps= 13 | github.com/charmbracelet/bubbletea v0.23.2/go.mod h1:FaP3WUivcTM0xOKNmhciz60M6I+weYLF76mr1JyI7sM= 14 | github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao= 15 | github.com/charmbracelet/lipgloss v0.6.0 h1:1StyZB9vBSOyuZxQUcUwGr17JmojPNm87inij9N3wJY= 16 | github.com/charmbracelet/lipgloss v0.6.0/go.mod h1:tHh2wr34xcHjC2HCXIlGSG1jaDF0S0atAUvBMP6Ppuk= 17 | github.com/cheggaaa/pb/v3 v3.1.0 h1:3uouEsl32RL7gTiQsuaXD4Bzbfl5tGztXGUvXbs4O04= 18 | github.com/cheggaaa/pb/v3 v3.1.0/go.mod h1:YjrevcBqadFDaGQKRdmZxTY42pXEqda48Ea3lt0K/BE= 19 | github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= 20 | github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= 21 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 22 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 23 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 24 | github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= 25 | github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= 26 | github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= 27 | github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= 28 | github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= 29 | github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= 30 | github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w= 31 | github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg= 32 | github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= 33 | github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= 34 | github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= 35 | github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= 36 | github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= 37 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 38 | github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= 39 | github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 40 | github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= 41 | github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q= 42 | github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= 43 | github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= 44 | github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= 45 | github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= 46 | github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= 47 | github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= 48 | github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= 49 | github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= 50 | github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= 51 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 52 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 53 | github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= 54 | github.com/lestrrat-go/backoff/v2 v2.0.8 h1:oNb5E5isby2kiro9AgdHLv5N5tint1AnDVVf2E2un5A= 55 | github.com/lestrrat-go/backoff/v2 v2.0.8/go.mod h1:rHP/q/r9aT27n24JQLa7JhSQZCKBBOiM/uP402WwN8Y= 56 | github.com/lestrrat-go/blackmagic v1.0.1 h1:lS5Zts+5HIC/8og6cGHb0uCcNCa3OUt1ygh3Qz2Fe80= 57 | github.com/lestrrat-go/blackmagic v1.0.1/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU= 58 | github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE= 59 | github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E= 60 | github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI= 61 | github.com/lestrrat-go/iter v1.0.2/go.mod h1:Momfcq3AnRlRjI5b5O8/G5/BvpzrhoFTZcn06fEOPt4= 62 | github.com/lestrrat-go/jwx v1.2.26 h1:4iFo8FPRZGDYe1t19mQP0zTRqA7n8HnJ5lkIiDvJcB0= 63 | github.com/lestrrat-go/jwx v1.2.26/go.mod h1:MaiCdGbn3/cckbOFSCluJlJMmp9dmZm5hDuIkx8ftpQ= 64 | github.com/lestrrat-go/option v1.0.0/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I= 65 | github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU= 66 | github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I= 67 | github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= 68 | github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= 69 | github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= 70 | github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= 71 | github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= 72 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 73 | github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= 74 | github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 75 | github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= 76 | github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 77 | github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= 78 | github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= 79 | github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= 80 | github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= 81 | github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 82 | github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= 83 | github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 84 | github.com/minio/cli v1.24.2 h1:J+fCUh9mhPLjN3Lj/YhklXvxj8mnyE/D6FpFduXJ2jg= 85 | github.com/minio/cli v1.24.2/go.mod h1:bYxnK0uS629N3Bq+AOZZ+6lwF77Sodk4+UL9vNuXhOY= 86 | github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= 87 | github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= 88 | github.com/minio/minio-go/v7 v7.0.63 h1:GbZ2oCvaUdgT5640WJOpyDhhDxvknAJU2/T3yurwcbQ= 89 | github.com/minio/minio-go/v7 v7.0.63/go.mod h1:Q6X7Qjb7WMhvG65qKf4gUgA5XaiSox74kR1uAEjxRS4= 90 | github.com/minio/mux v1.8.2 h1:r9oVDFM09y+u8CF4HPLanguAG41niXgYwZAFkVHce9M= 91 | github.com/minio/mux v1.8.2/go.mod h1:1pAare17ZRL5GpmNL+9YmqHoWnLmMZF9C/ioUCfy0BQ= 92 | github.com/minio/pkg/v2 v2.0.2 h1:cytXmC21fBNS+0NVKEE5FuYmQfY+HFTqis6Kkj3U9ac= 93 | github.com/minio/pkg/v2 v2.0.2/go.mod h1:6xTAr5M9yobpUroXAAaTrGJ9fhOZIqKYOT0I87u2yZ4= 94 | github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= 95 | github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= 96 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 97 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= 98 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 99 | github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= 100 | github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= 101 | github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho= 102 | github.com/muesli/ansi v0.0.0-20221106050444-61f0cd9a192a h1:jlDOeO5TU0pYlbc/y6PFguab5IjANI0Knrpg3u/ton4= 103 | github.com/muesli/ansi v0.0.0-20221106050444-61f0cd9a192a/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= 104 | github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= 105 | github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= 106 | github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ= 107 | github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= 108 | github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= 109 | github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs= 110 | github.com/muesli/termenv v0.13.0/go.mod h1:sP1+uffeLaEYpyOTb8pLCUctGcGLnoFjSn4YJK5e2bc= 111 | github.com/muesli/termenv v0.14.0 h1:8x9NFfOe8lmIWK4pgy3IfVEy47f+ppe3tUqdPZG2Uy0= 112 | github.com/muesli/termenv v0.14.0/go.mod h1:kG/pF1E7fh949Xhe156crRUrHNyK221IuGO7Ez60Uc8= 113 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= 114 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= 115 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 116 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 117 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 118 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 119 | github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= 120 | github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= 121 | github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= 122 | github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= 123 | github.com/rjeczalik/notify v0.9.3 h1:6rJAzHTGKXGj76sbRgDiDcYj/HniypXmSJo1SWakZeY= 124 | github.com/rjeczalik/notify v0.9.3/go.mod h1:gF3zSOrafR9DQEWSE8TjfI9NkooDxbyT4UgRGKZA0lc= 125 | github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= 126 | github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= 127 | github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= 128 | github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= 129 | github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 130 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 131 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 132 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 133 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 134 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 135 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 136 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 137 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 138 | github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= 139 | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 140 | github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 141 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 142 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 143 | golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= 144 | golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= 145 | golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= 146 | golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= 147 | golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 148 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 149 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 150 | golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 151 | golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= 152 | golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= 153 | golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= 154 | golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= 155 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 156 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 157 | golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= 158 | golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 159 | golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 160 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 161 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 162 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 163 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 164 | golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 165 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 166 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 167 | golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 168 | golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 169 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 170 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 171 | golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 172 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 173 | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 174 | golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 175 | golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= 176 | golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 177 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 178 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 179 | golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= 180 | golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= 181 | golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0= 182 | golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= 183 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 184 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 185 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 186 | golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 187 | golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= 188 | golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= 189 | golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= 190 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 191 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 192 | golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= 193 | golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= 194 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 195 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 196 | gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= 197 | gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 198 | gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= 199 | gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 200 | gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= 201 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 202 | gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 203 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 204 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 205 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 206 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 207 | -------------------------------------------------------------------------------- /handlers.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2022 MinIO, Inc. 2 | // 3 | // This project is part of MinIO Object Storage stack 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Affero General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Affero General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with this program. If not, see . 17 | 18 | package main 19 | 20 | import ( 21 | "context" 22 | "encoding/json" 23 | "errors" 24 | "fmt" 25 | "log" 26 | "mime" 27 | "net/http" 28 | "net/url" 29 | "os" 30 | "path" 31 | "strconv" 32 | "sync" 33 | "sync/atomic" 34 | "time" 35 | 36 | "github.com/dustin/go-humanize" 37 | "github.com/gorilla/mux" 38 | "github.com/minio/minio-go/v7" 39 | "github.com/minio/minio-go/v7/pkg/tags" 40 | ) 41 | 42 | var errNotifyEpRequired = errors.New("a notification endpoint is required") 43 | 44 | // ResponseType represents a valid LXD response type 45 | type ResponseType string 46 | 47 | // LXD response types 48 | const ( 49 | SyncResponse ResponseType = "sync" 50 | AsyncResponse ResponseType = "async" 51 | ErrorResponse ResponseType = "error" 52 | ) 53 | 54 | // Response represents an API response 55 | type Response interface { 56 | Render(w http.ResponseWriter) error 57 | String() string 58 | } 59 | 60 | func writeErrorResponse(w http.ResponseWriter, err error) { 61 | w.WriteHeader(http.StatusBadRequest) 62 | errResp := errorResponse{ 63 | Code: http.StatusBadRequest, 64 | Error: fmt.Sprintf("%v", err), 65 | Type: ErrorResponse, 66 | } 67 | json.NewEncoder(w).Encode(&errResp) 68 | } 69 | 70 | func writeSuccessResponse(w http.ResponseWriter, data interface{}, sync bool) { 71 | sresp := &successResponse{ 72 | Code: http.StatusOK, 73 | Metadata: data, 74 | Type: func() ResponseType { 75 | if sync { 76 | return SyncResponse 77 | } 78 | return AsyncResponse 79 | }(), 80 | } 81 | sresp.Render(w) 82 | } 83 | 84 | // NotFound returns a not found response (404) with the given error. 85 | func NotFound(err error) *errorResponse { 86 | message := "not found" 87 | if err != nil { 88 | message = err.Error() 89 | } 90 | 91 | return &errorResponse{ 92 | Code: http.StatusNotFound, 93 | Error: message, 94 | Type: ErrorResponse, 95 | } 96 | } 97 | 98 | type errorResponse struct { 99 | Code int `json:"code"` 100 | Error string `json:"error"` 101 | Type ResponseType `json:"type"` 102 | } 103 | 104 | func (e *errorResponse) Render(w http.ResponseWriter) { 105 | if e == nil { 106 | return 107 | } 108 | 109 | w.Header().Set("Content-Type", "application/json") 110 | w.Header().Set("X-Content-Type-Options", "nosniff") 111 | 112 | w.WriteHeader(e.Code) 113 | json.NewEncoder(w).Encode(e) 114 | } 115 | 116 | type successResponse struct { 117 | Metadata interface{} `json:"metadata,omitempty"` 118 | Status string `json:"status"` 119 | Code int `json:"status_code"` 120 | Type ResponseType `json:"type"` 121 | } 122 | 123 | func (s *successResponse) Render(w http.ResponseWriter) { 124 | if s == nil { 125 | return 126 | } 127 | 128 | s.Status = "Success" 129 | 130 | w.Header().Set("Content-Type", "application/json") 131 | w.Header().Set("X-Content-Type-Options", "nosniff") 132 | 133 | w.WriteHeader(s.Code) 134 | json.NewEncoder(w).Encode(s) 135 | } 136 | 137 | type backupInfo struct { 138 | Instance string `json:"instance,omitempty"` 139 | Name string `json:"name"` 140 | Created *time.Time `json:"created,omitempty"` 141 | Size int64 `json:"size,omitempty"` 142 | Optimized *bool `json:"optimized,omitempty"` 143 | Compressed *bool `json:"compressed,omitempty"` 144 | Tags map[string]string `json:"tags,omitempty"` 145 | State string `json:"state,omitempty"` 146 | Progress *int64 `json:"progress,omitempty"` 147 | } 148 | 149 | type backupReader struct { 150 | Started bool 151 | Size int64 152 | Progress int64 153 | } 154 | 155 | func (bk *backupReader) Read(b []byte) (int, error) { 156 | atomic.AddInt64(&bk.Progress, int64(len(b))) 157 | return len(b), nil 158 | } 159 | 160 | type backupState struct { 161 | sync.RWMutex 162 | backups map[string]*backupReader 163 | } 164 | 165 | func (s *backupState) Store(bname string, rk *backupReader) { 166 | s.Lock() 167 | defer s.Unlock() 168 | 169 | s.backups[bname] = rk 170 | } 171 | 172 | func (s *backupState) Pop(bname string) { 173 | s.Lock() 174 | defer s.Unlock() 175 | 176 | delete(s.backups, bname) 177 | } 178 | 179 | func (s *backupState) Get(bname string) *backupReader { 180 | s.RLock() 181 | defer s.RUnlock() 182 | 183 | return s.backups[bname] 184 | } 185 | 186 | var globalBackupState = &backupState{ 187 | backups: map[string]*backupReader{}, 188 | } 189 | 190 | func performBackup(instance, backupName string, tagsMap map[string]string, partSize int64, startedAt time.Time, notifyEndpoint string, r *http.Request) error { 191 | notifyEvent(eventInfo{ 192 | OpType: Backup, 193 | State: Started, 194 | Name: backupName, 195 | Instance: instance, 196 | StartedAt: &startedAt, 197 | RawURL: r.URL.String(), 198 | }, notifyEndpoint) 199 | 200 | bkReader := &backupReader{Started: true} 201 | globalBackupState.Store(backupName, bkReader) 202 | defer globalBackupState.Pop(backupName) 203 | 204 | // Export profiles to files. 205 | 206 | profiles, err := listProfiles(instance) 207 | if err != nil { 208 | return err 209 | } 210 | 211 | if len(profiles) > 1000 { 212 | return fmt.Errorf("More than a 1000 profiles per instance not supported.") 213 | } 214 | 215 | prInfo := make(map[string]profileInfo, len(profiles)) 216 | for pno, profile := range profiles { 217 | // Profiles are numbered because their order matters - settings 218 | // in the later profiles override those from earlier profiles. 219 | profileFile := fmt.Sprintf("%s_profile_%03d_%s.yaml", backupName, pno, profile) 220 | profilePath := path.Join(globalContext.StagingRoot, profileFile) 221 | 222 | prSize, err := exportProfile(profile, profilePath) 223 | if err != nil { 224 | return err 225 | } 226 | 227 | prInfo[profile] = profileInfo{ 228 | FileName: profileFile, 229 | Size: prSize, 230 | } 231 | } 232 | 233 | // Export instance to tarball 234 | 235 | instanceBkpFilename := backupName + "_instance.tar.gz" 236 | localPath := path.Join(globalContext.StagingRoot, instanceBkpFilename) 237 | optimized := r.Form.Get("optimize") == "true" 238 | instanceSize, err := exportInstance(instance, localPath, optimized) 239 | if err != nil { 240 | return err 241 | } 242 | 243 | // Upload instance tarball to MinIO. 244 | 245 | bkReader.Size = instanceSize 246 | globalBackupState.Store(backupName, bkReader) 247 | 248 | usermetadata := map[string]string{} 249 | // Save additional information if the backup is optimized or not. 250 | usermetadata["optimized"] = strconv.FormatBool(optimized) 251 | usermetadata["compressed"] = "true" // This is always true. 252 | 253 | opts := minio.PutObjectOptions{ 254 | UserTags: tagsMap, 255 | PartSize: uint64(partSize), 256 | UserMetadata: usermetadata, 257 | ContentType: mime.TypeByExtension(".tar.gz"), 258 | Progress: bkReader, 259 | } 260 | 261 | f, err := os.Open(localPath) 262 | if err != nil { 263 | return err 264 | } 265 | defer f.Close() 266 | defer os.Remove(localPath) 267 | 268 | bkp := backup{instance: instance, backupName: backupName} 269 | _, err = globalContext.Clnt.PutObject(context.Background(), globalContext.Bucket, bkp.key(), f, instanceSize, opts) 270 | if err != nil { 271 | return err 272 | } 273 | 274 | // Upload profiles to MinIO. 275 | for _, profile := range profiles { 276 | err := func() error { 277 | profileFile := prInfo[profile].FileName 278 | size := prInfo[profile].Size 279 | fpath := path.Join(globalContext.StagingRoot, profileFile) 280 | f, err := os.Open(fpath) 281 | if err != nil { 282 | return err 283 | } 284 | defer f.Close() 285 | defer os.Remove(fpath) 286 | 287 | opts := minio.PutObjectOptions{ 288 | UserTags: tagsMap, 289 | PartSize: uint64(partSize), 290 | ContentType: mime.TypeByExtension(".yaml"), 291 | } 292 | _, err = globalContext.Clnt.PutObject(context.Background(), globalContext.Bucket, path.Join(instance, profileFile), f, size, opts) 293 | if err != nil { 294 | return fmt.Errorf("Error uploading file %s: %v", fpath, err) 295 | } 296 | return nil 297 | }() 298 | if err != nil { 299 | return err 300 | } 301 | } 302 | 303 | completedAt := time.Now() 304 | notifyEvent(eventInfo{ 305 | OpType: Backup, 306 | State: Success, 307 | Name: backupName, 308 | Instance: instance, 309 | StartedAt: &startedAt, 310 | CompletedAt: &completedAt, 311 | RawURL: r.URL.String(), 312 | }, notifyEndpoint) 313 | return err 314 | } 315 | 316 | func performRestore(instance, backupName string, startedAt time.Time, notifyEndpoint string, r *http.Request) error { 317 | notifyEvent(eventInfo{ 318 | OpType: Restore, 319 | State: Started, 320 | Name: backupName, 321 | Instance: instance, 322 | StartedAt: &startedAt, 323 | RawURL: r.URL.String(), 324 | }, notifyEndpoint) 325 | 326 | bkp := backup{instance: instance, backupName: backupName} 327 | 328 | // Fetch restore info 329 | resInfo, err := globalContext.fetchRestoreInfo(bkp) 330 | if err != nil { 331 | return err 332 | } 333 | 334 | // Download profiles 335 | for _, pkey := range resInfo.profileKeys { 336 | err := globalContext.downloadItem(pkey, nil) 337 | if err != nil { 338 | return fmt.Errorf("Error downloading profile file %s: %v", pkey, err) 339 | } 340 | } 341 | 342 | // Download instance backup 343 | if err := globalContext.downloadItem(bkp.key(), nil); err != nil { 344 | return fmt.Errorf("Error downloading instance backup %s: %v", bkp.key(), err) 345 | } 346 | 347 | // Fetch existing profiles on the system 348 | existingProfiles, err := fetchExistingProfiles() 349 | if err != nil { 350 | return err 351 | } 352 | 353 | // Restore profiles - skip those that already exist. 354 | for i, pf := range resInfo.profiles { 355 | err := restoreProfile(globalContext, pf, resInfo.profileKeys[i], existingProfiles) 356 | if _, ok := err.(warnMsgErr); ok { 357 | // Skip warning that profile was not replaced for now. 358 | continue 359 | } else if err != nil { 360 | return err 361 | } 362 | } 363 | 364 | // Restore instance 365 | _, err = restoreInstance(globalContext, bkp) 366 | if err != nil { 367 | return err 368 | } 369 | 370 | completedAt := time.Now() 371 | 372 | notifyEvent(eventInfo{ 373 | OpType: Restore, 374 | State: Success, 375 | Name: backupName, 376 | Instance: instance, 377 | StartedAt: &startedAt, 378 | CompletedAt: &completedAt, 379 | RawURL: r.URL.String(), 380 | }, notifyEndpoint) 381 | 382 | return nil 383 | } 384 | 385 | func restoreHandler(w http.ResponseWriter, r *http.Request) { 386 | vars := mux.Vars(r) 387 | instance := vars["name"] 388 | backup := vars["backup"] 389 | 390 | if instance == "" { 391 | writeErrorResponse(w, errors.New("instance name cannot be empty")) 392 | return 393 | } 394 | 395 | if backup == "" { 396 | writeErrorResponse(w, errors.New("backup name cannot be empty")) 397 | return 398 | } 399 | 400 | if err := checkInstance(instance); err != nil { 401 | writeErrorResponse(w, err) 402 | return 403 | } 404 | 405 | notifyEndpoint, err := url.QueryUnescape(r.Form.Get("notifyEndpoint")) 406 | if err != nil { 407 | writeErrorResponse(w, errors.New("invalid notifyEndpoint")) 408 | return 409 | } 410 | 411 | if notifyEndpoint == "" { 412 | notifyEndpoint = globalContext.NotifyEndpoint 413 | } 414 | 415 | if notifyEndpoint == "" { 416 | writeErrorResponse(w, errNotifyEpRequired) 417 | return 418 | } 419 | 420 | go func() { 421 | startedAt := time.Now() 422 | if err := performRestore(instance, backup, startedAt, notifyEndpoint, r); err != nil { 423 | failedAt := time.Now() 424 | notifyEvent(eventInfo{ 425 | OpType: Restore, 426 | State: Failed, 427 | Name: backup, 428 | Instance: instance, 429 | StartedAt: &startedAt, 430 | FailedAt: &failedAt, 431 | Error: err, 432 | RawURL: r.URL.String(), 433 | }, notifyEndpoint) 434 | log.Println(err) 435 | } 436 | }() 437 | 438 | sresp := &successResponse{ 439 | Status: "Operation created", 440 | Code: 100, 441 | Type: AsyncResponse, 442 | } 443 | 444 | w.Header().Set("Content-Type", "application/json") 445 | w.Header().Set("X-Content-Type-Options", "nosniff") 446 | 447 | json.NewEncoder(w).Encode(sresp) 448 | } 449 | 450 | func backupHandler(w http.ResponseWriter, r *http.Request) { 451 | vars := mux.Vars(r) 452 | instance := vars["name"] 453 | 454 | if instance == "" { 455 | writeErrorResponse(w, errors.New("instance name cannot be empty")) 456 | return 457 | } 458 | 459 | partSize, err := strconv.ParseInt(r.Form.Get("partSize"), 10, 64) 460 | if err != nil && r.Form.Get("partSize") != "" { 461 | writeErrorResponse(w, err) 462 | return 463 | } 464 | if partSize == 0 { 465 | partSize = 64 * humanize.MiByte 466 | } 467 | 468 | tagsSet, err := tags.Parse(r.Form.Get("tags"), true) 469 | if err != nil { 470 | writeErrorResponse(w, err) 471 | return 472 | } 473 | 474 | notifyEndpoint, err := url.QueryUnescape(r.Form.Get("notifyEndpoint")) 475 | if err != nil { 476 | writeErrorResponse(w, err) 477 | return 478 | } 479 | 480 | if notifyEndpoint == "" { 481 | notifyEndpoint = globalContext.NotifyEndpoint 482 | } 483 | 484 | if notifyEndpoint == "" { 485 | writeErrorResponse(w, errNotifyEpRequired) 486 | return 487 | } 488 | 489 | backup := "backup_" + time.Now().Format("2006-01-02-15-0405") 490 | go func() { 491 | startedAt := time.Now() 492 | if err := performBackup(instance, backup, tagsSet.ToMap(), partSize, startedAt, notifyEndpoint, r); err != nil { 493 | failedAt := time.Now() 494 | notifyEvent(eventInfo{ 495 | OpType: Backup, 496 | State: Failed, 497 | Name: backup, 498 | Instance: instance, 499 | StartedAt: &startedAt, 500 | FailedAt: &failedAt, 501 | Error: err, 502 | RawURL: r.URL.String(), 503 | }, notifyEndpoint) 504 | log.Println(err) 505 | } 506 | }() 507 | 508 | optimized := r.Form.Get("optimize") == "true" 509 | compressed := true 510 | 511 | sresp := &successResponse{ 512 | Metadata: backupInfo{ 513 | Name: backup, 514 | Optimized: &optimized, 515 | Compressed: &compressed, 516 | }, 517 | Status: "Operation created", 518 | Code: 100, 519 | Type: AsyncResponse, 520 | } 521 | 522 | w.Header().Set("Content-Type", "application/json") 523 | w.Header().Set("X-Content-Type-Options", "nosniff") 524 | 525 | json.NewEncoder(w).Encode(sresp) 526 | } 527 | 528 | func deleteHandler(w http.ResponseWriter, r *http.Request) { 529 | vars := mux.Vars(r) 530 | instance := vars["name"] 531 | backupName := vars["backup"] 532 | 533 | if instance == "" { 534 | writeErrorResponse(w, errors.New("instance name cannot be empty")) 535 | return 536 | } 537 | 538 | if backupName == "" { 539 | writeErrorResponse(w, errors.New("backup name cannot be empty")) 540 | return 541 | } 542 | 543 | bkp := backup{ 544 | instance: instance, 545 | backupName: backupName, 546 | } 547 | 548 | err := globalContext.DeleteBackup(bkp) 549 | if err != nil { 550 | writeErrorResponse(w, err) 551 | return 552 | } 553 | 554 | writeSuccessResponse(w, nil, true) 555 | } 556 | 557 | func infoHandler(w http.ResponseWriter, r *http.Request) { 558 | vars := mux.Vars(r) 559 | instance := vars["name"] 560 | backupName := vars["backup"] 561 | 562 | if instance == "" { 563 | writeErrorResponse(w, errors.New("instance name cannot be empty")) 564 | return 565 | } 566 | 567 | if backupName == "" { 568 | writeErrorResponse(w, errors.New("backup name cannot be empty")) 569 | return 570 | } 571 | 572 | if reader := globalBackupState.Get(backupName); reader != nil { 573 | state := "generating" 574 | progress := atomic.LoadInt64(&reader.Progress) 575 | if reader.Started && progress > 0 { 576 | state = "uploading" 577 | } 578 | writeSuccessResponse(w, backupInfo{ 579 | Name: backupName, 580 | Size: reader.Size, 581 | State: state, 582 | Progress: &progress, 583 | }, true) 584 | return 585 | } 586 | 587 | bkp := backup{ 588 | instance: instance, 589 | backupName: backupName, 590 | } 591 | 592 | tags, err := globalContext.GetTags(bkp) 593 | if err != nil { 594 | writeErrorResponse(w, err) 595 | return 596 | } 597 | 598 | meta, err := globalContext.GetMetadata(bkp) 599 | if err != nil { 600 | writeErrorResponse(w, err) 601 | return 602 | } 603 | 604 | optimized := meta.UserMetadata["Optimized"] == "true" 605 | compressed := meta.UserMetadata["Compressed"] == "true" 606 | 607 | info := backupInfo{ 608 | Name: backupName, 609 | Created: &meta.LastModified, 610 | Size: meta.Size, 611 | Optimized: &optimized, 612 | Compressed: &compressed, 613 | Tags: tags.ToMap(), 614 | } 615 | 616 | writeSuccessResponse(w, info, true) 617 | } 618 | 619 | func listHandler(w http.ResponseWriter, r *http.Request) { 620 | vars := mux.Vars(r) 621 | instance := vars["name"] 622 | 623 | if instance == "" { 624 | writeErrorResponse(w, errors.New("instance name cannot be empty")) 625 | return 626 | } 627 | 628 | // Allow obtaining all backups 629 | if instance == "*" { 630 | instance = "" 631 | } 632 | 633 | backups, err := globalContext.ListBackups(instance) 634 | if err != nil { 635 | writeErrorResponse(w, err) 636 | return 637 | } 638 | 639 | writeSuccessResponse(w, backups, true) 640 | } 641 | 642 | func healthHandler(w http.ResponseWriter, r *http.Request) { 643 | // A very simple health check. 644 | w.Header().Set("Content-Type", "application/json") 645 | w.Header().Set("X-Content-Type-Options", "nosniff") 646 | 647 | w.WriteHeader(http.StatusOK) 648 | } 649 | -------------------------------------------------------------------------------- /info.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2022 MinIO, Inc. 2 | // 3 | // This project is part of MinIO Object Storage stack 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Affero General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Affero General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with this program. If not, see . 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "strings" 23 | 24 | "github.com/dustin/go-humanize" 25 | "github.com/minio/cli" 26 | ) 27 | 28 | var infoCmd = cli.Command{ 29 | Name: "info", 30 | Usage: "pretty print tags on an instance image on MinIO", 31 | Action: infoMain, 32 | Before: setGlobalsFromContext, 33 | Flags: globalFlags, 34 | CustomHelpTemplate: `NAME: 35 | {{.HelpName}} - {{.Usage}} 36 | 37 | USAGE: 38 | {{.HelpName}} [FLAGS] INSTANCENAME BACKUPNAME 39 | 40 | FLAGS: 41 | {{range .VisibleFlags}}{{.}} 42 | {{end}} 43 | EXAMPLES: 44 | 1. Pretty print tags for a backup 'backup_2022-02-16-04-1040' for instance 'u2': 45 | {{.Prompt}} {{.HelpName}} u2 backup_2022-02-16-04-1040 46 | `, 47 | } 48 | 49 | func infoMain(c *cli.Context) error { 50 | if len(c.Args()) > 2 { 51 | cli.ShowAppHelpAndExit(c, 1) // last argument is exit code 52 | } 53 | 54 | instance := strings.TrimSpace(c.Args().Get(0)) 55 | if instance == "" { 56 | cli.ShowAppHelpAndExit(c, 1) // last argument is exit code 57 | } 58 | 59 | backupName := strings.TrimSpace(c.Args().Get(1)) 60 | if backupName == "" { 61 | cli.ShowAppHelpAndExit(c, 1) // last argument is exit code 62 | } 63 | 64 | bkp := backup{instance: instance, backupName: backupName} 65 | 66 | tags, err := globalContext.GetTags(bkp) 67 | if err != nil { 68 | return err 69 | } 70 | 71 | meta, err := globalContext.GetMetadata(bkp) 72 | if err != nil { 73 | return err 74 | } 75 | 76 | var msgBuilder strings.Builder 77 | // Format properly for alignment based on maxKey leng 78 | backupName = fmt.Sprintf("%-10s: %s", "Name", backupName) 79 | msgBuilder.WriteString(backupName + "\n") 80 | msgBuilder.WriteString(fmt.Sprintf("%-10s: %s ", "Date", meta.LastModified.Format(printDate)) + "\n") 81 | msgBuilder.WriteString(fmt.Sprintf("%-10s: %-6s ", "Size", humanize.IBytes(uint64(meta.Size))) + "\n") 82 | 83 | maxTagsKey := 0 84 | for k := range tags.ToMap() { 85 | if len(k) > maxTagsKey { 86 | maxTagsKey = len(k) 87 | } 88 | } 89 | 90 | maxKeyMetadata := 0 91 | for k := range meta.UserMetadata { 92 | if !strings.HasPrefix(strings.ToLower(k), serverEncryptionKeyPrefix) { 93 | switch k { 94 | case "Optimized", "Compressed": 95 | if len(k) > maxKeyMetadata { 96 | maxKeyMetadata = len(k) 97 | } 98 | } 99 | } 100 | } 101 | 102 | maxPad := maxTagsKey 103 | if maxTagsKey < maxKeyMetadata { 104 | maxPad = maxKeyMetadata 105 | } 106 | 107 | if maxTagsKey > 0 { 108 | msgBuilder.WriteString(fmt.Sprintf("%-10s:", "Tags") + "\n") 109 | for k, v := range tags.ToMap() { 110 | msgBuilder.WriteString(fmt.Sprintf(" %-*.*s : %s ", maxPad, maxPad, k, v) + "\n") 111 | } 112 | } 113 | 114 | if maxKeyMetadata > 0 { 115 | msgBuilder.WriteString(fmt.Sprintf("%-10s:", "Metadata") + "\n") 116 | for k, v := range meta.UserMetadata { 117 | if !strings.HasPrefix(strings.ToLower(k), serverEncryptionKeyPrefix) { 118 | switch k { 119 | case "Compressed", "Optimized": 120 | if v == "true" { 121 | v = tickCell 122 | } else { 123 | v = crossTickCell 124 | } 125 | default: 126 | continue 127 | } 128 | msgBuilder.WriteString(fmt.Sprintf(" %-*.*s : %s ", maxKeyMetadata, maxKeyMetadata, k, v) + "\n") 129 | } 130 | } 131 | } 132 | 133 | fmt.Println(msgBuilder.String()) 134 | return nil 135 | } 136 | -------------------------------------------------------------------------------- /list.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2022 MinIO, Inc. 2 | // 3 | // This project is part of MinIO Object Storage stack 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Affero General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Affero General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with this program. If not, see . 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "strings" 23 | 24 | "github.com/charmbracelet/lipgloss" 25 | "github.com/dustin/go-humanize" 26 | "github.com/minio/cli" 27 | ) 28 | 29 | var listCmd = cli.Command{ 30 | Name: "list", 31 | Aliases: []string{"ls"}, 32 | Usage: "list all backups from MinIO", 33 | Action: listMain, 34 | Before: setGlobalsFromContext, 35 | Flags: globalFlags, 36 | CustomHelpTemplate: `NAME: 37 | {{.HelpName}} - {{.Usage}} 38 | 39 | USAGE: 40 | {{.HelpName}} [FLAGS] [INSTANCENAME] 41 | 42 | FLAGS: 43 | {{range .VisibleFlags}}{{.}} 44 | {{end}} 45 | EXAMPLES: 46 | 1. List all backups: 47 | {{.Prompt}} {{.HelpName}} 48 | 2. List all backups by instance name 'u2': 49 | {{.Prompt}} {{.HelpName}} u2 50 | `, 51 | } 52 | 53 | const ( 54 | tickCell string = "✔ " 55 | crossTickCell string = "✗ " 56 | ) 57 | 58 | var subtle = lipgloss.AdaptiveColor{Light: "#D9DCCF", Dark: "#383838"} 59 | 60 | func listMain(c *cli.Context) error { 61 | if len(c.Args()) > 1 { 62 | cli.ShowAppHelpAndExit(c, 1) // last argument is exit code 63 | } 64 | 65 | instance := strings.TrimSpace(c.Args().Get(0)) 66 | 67 | var table strings.Builder 68 | 69 | list := lipgloss.NewStyle(). 70 | BorderStyle(lipgloss.NormalBorder()). 71 | BorderForeground(subtle) 72 | 73 | listHeader := lipgloss.NewStyle(). 74 | PaddingLeft(1). 75 | PaddingRight(1). 76 | PaddingBottom(1). 77 | Render 78 | 79 | listItem := lipgloss.NewStyle(). 80 | PaddingLeft(1). 81 | PaddingRight(1). 82 | Render 83 | 84 | backups, err := globalContext.ListBackups(instance) 85 | if err != nil { 86 | return err 87 | } 88 | 89 | data := map[string][]string{} 90 | for _, bkp := range backups { 91 | data["Instance"] = append(data["Instance"], bkp.Instance) 92 | data["Name"] = append(data["Name"], bkp.Name) 93 | data["Created"] = append(data["Created"], bkp.Created.Format(printDate)) 94 | data["Size"] = append(data["Size"], humanize.IBytes(uint64(bkp.Size))) 95 | if *bkp.Optimized { 96 | data["Optimized"] = append(data["Optimized"], tickCell) 97 | } else { 98 | data["Optimized"] = append(data["Optimized"], crossTickCell) 99 | } 100 | } 101 | 102 | items := func(header string) []string { 103 | var itemRenders []string 104 | itemRenders = append(itemRenders, listHeader(header)) 105 | for _, d := range data[header] { 106 | itemRenders = append(itemRenders, listItem(d)) 107 | } 108 | return itemRenders 109 | } 110 | 111 | renderLists := []string{} 112 | for _, header := range []string{"Instance", "Name", "Created", "Size", "Optimized"} { 113 | renderLists = append(renderLists, list.Render(lipgloss.JoinVertical(lipgloss.Left, items(header)...))) 114 | } 115 | lists := lipgloss.JoinHorizontal(lipgloss.Top, renderLists...) 116 | table.WriteString(lipgloss.JoinHorizontal(lipgloss.Top, lists)) 117 | 118 | docStyle := lipgloss.NewStyle() 119 | fmt.Println(docStyle.Render(table.String())) 120 | return nil 121 | } 122 | -------------------------------------------------------------------------------- /lxc.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2022 MinIO, Inc. 2 | // 3 | // This project is part of MinIO Object Storage stack 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Affero General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Affero General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with this program. If not, see . 17 | 18 | package main 19 | 20 | import ( 21 | "bytes" 22 | "errors" 23 | "fmt" 24 | "io/ioutil" 25 | "os" 26 | "os/exec" 27 | "path" 28 | "strings" 29 | 30 | "github.com/charmbracelet/bubbles/spinner" 31 | tea "github.com/charmbracelet/bubbletea" 32 | "github.com/charmbracelet/lipgloss" 33 | "github.com/minio/minio-go/v7/pkg/set" 34 | "gopkg.in/yaml.v2" 35 | ) 36 | 37 | const ( 38 | printDate = "2006-01-02 15:04:05 MST" 39 | serverEncryptionKeyPrefix = "x-amz-server-side-encryption" 40 | ) 41 | 42 | type cmdSpinnerUI struct { 43 | spinner spinner.Model 44 | quitting bool 45 | err error 46 | warningMsg string 47 | cmdFn func() tea.Msg 48 | opts cOpts 49 | } 50 | 51 | type cOpts struct { 52 | instance, message string 53 | } 54 | 55 | func (m *cmdSpinnerUI) Init() tea.Cmd { 56 | return tea.Batch(m.spinner.Tick, m.cmdFn) 57 | } 58 | 59 | func (m *cmdSpinnerUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { 60 | switch msg := msg.(type) { 61 | case tea.KeyMsg: 62 | switch msg.String() { 63 | case "ctrl+c": 64 | m.err = errors.New("canceling") 65 | m.quitting = true 66 | return m, tea.Quit 67 | default: 68 | return m, nil 69 | } 70 | case spinner.TickMsg: 71 | var cmd tea.Cmd 72 | m.spinner, cmd = m.spinner.Update(msg) 73 | return m, cmd 74 | case error: 75 | m.err = msg 76 | m.quitting = true 77 | return m, tea.Quit 78 | case warningMessage: 79 | m.warningMsg = msg.msg 80 | return m, tea.Quit 81 | case bool: 82 | if msg { 83 | m.quitting = true 84 | return m, tea.Quit 85 | } 86 | } 87 | return m, nil 88 | } 89 | 90 | func (m *cmdSpinnerUI) View() string { 91 | spin := m.spinner.View() 92 | 93 | if m.warningMsg != "" { 94 | spin = "ⓘ" 95 | m.opts.message = m.warningMsg 96 | m.opts.message += "\n" 97 | } else if m.quitting { 98 | if m.err != nil { 99 | return m.err.Error() 100 | } 101 | spin = "✔" 102 | m.opts.message += "\n" 103 | } 104 | 105 | return fmt.Sprintf(m.opts.message, spin, m.opts.instance) 106 | } 107 | 108 | type warningMessage struct { 109 | msg string 110 | } 111 | 112 | func initCmdSpinnerUI(fn func() tea.Msg, opts cOpts) *cmdSpinnerUI { 113 | s := spinner.New() 114 | s.Spinner = spinner.Dot 115 | s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205")) 116 | return &cmdSpinnerUI{ 117 | spinner: s, 118 | cmdFn: fn, 119 | opts: opts, 120 | } 121 | } 122 | 123 | type spinnerUI struct { 124 | spinner spinner.Model 125 | quitting bool 126 | err error 127 | opts lxcOpts 128 | } 129 | 130 | func (m *spinnerUI) Init() tea.Cmd { 131 | return m.spinner.Tick 132 | } 133 | 134 | func (m *spinnerUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { 135 | switch msg := msg.(type) { 136 | case tea.KeyMsg: 137 | switch msg.String() { 138 | case "ctrl+c": 139 | m.err = errors.New("canceling") 140 | m.quitting = true 141 | return m, tea.Quit 142 | default: 143 | return m, nil 144 | } 145 | case spinner.TickMsg: 146 | var cmd tea.Cmd 147 | m.spinner, cmd = m.spinner.Update(msg) 148 | return m, cmd 149 | case error: 150 | m.err = msg 151 | m.quitting = true 152 | return m, tea.Quit 153 | case bool: 154 | if msg { 155 | m.quitting = true 156 | return m, tea.Quit 157 | } 158 | } 159 | return m, nil 160 | } 161 | 162 | func (m *spinnerUI) View() string { 163 | spin := m.spinner.View() 164 | if m.quitting { 165 | if m.err != nil { 166 | return m.err.Error() 167 | } 168 | spin = "✔" 169 | m.opts.message += "\n" 170 | } 171 | 172 | return fmt.Sprintf(m.opts.message, spin, m.opts.instance) 173 | } 174 | 175 | type lxcOpts struct { 176 | instance, message string 177 | } 178 | 179 | func initSpinnerUI(opts lxcOpts) *spinnerUI { 180 | s := spinner.New() 181 | s.Spinner = spinner.Dot 182 | s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205")) 183 | return &spinnerUI{ 184 | spinner: s, 185 | opts: opts, 186 | } 187 | } 188 | 189 | var instanceExists = errors.New("instance exists") 190 | 191 | func checkInstance(instance string) error { 192 | var out bytes.Buffer 193 | cmd := exec.Command("lxc", "list", instance, "-c", "n", "-f", "csv") 194 | cmd.Stdout = &out 195 | if err := cmd.Run(); err != nil { 196 | return err 197 | } 198 | if strings.TrimSpace(out.String()) == instance { 199 | return fmt.Errorf("'%s' instance is already running by this name: %w", instance, instanceExists) 200 | } 201 | return nil 202 | } 203 | 204 | // listProfiles - lists profiles with lxc and returns a list of profile names 205 | // attached to the given instance. 206 | func listProfiles(instance string) ([]string, error) { 207 | var outBuf bytes.Buffer 208 | cmd := exec.Command("lxc", "config", "show", instance) 209 | cmd.Stdout = &outBuf 210 | 211 | if err := cmd.Run(); err != nil { 212 | return nil, fmt.Errorf("Unable get instance config: %v", err) 213 | } 214 | 215 | type profileInfo struct { 216 | Profiles []string `yaml:"profiles"` 217 | } 218 | 219 | var profiles profileInfo 220 | if err := yaml.Unmarshal(outBuf.Bytes(), &profiles); err != nil { 221 | return nil, fmt.Errorf("Unable to parse profiles list: %v", err) 222 | } 223 | return profiles.Profiles, nil 224 | } 225 | 226 | // exportProfile - exports profile from lxc and saves it at dstPath. 227 | func exportProfile(profile, dstPath string) (int64, error) { 228 | pf, err := os.Create(dstPath) 229 | if err != nil { 230 | return -1, fmt.Errorf("Unable to create backup file %s: %v", dstPath, err) 231 | } 232 | cmd := exec.Command("lxc", "profile", "show", profile) 233 | cmd.Stdout = pf 234 | if err := cmd.Run(); err != nil { 235 | return -1, fmt.Errorf("Unable to export profile: %v", err) 236 | } 237 | 238 | // Sync file to disk 239 | if err := pf.Sync(); err != nil { 240 | return -1, fmt.Errorf("Error syncing profile file %s to disk: %v", dstPath, err) 241 | } 242 | 243 | // Save size of the file for showing progress later. 244 | stat, err := pf.Stat() 245 | if err != nil { 246 | return -1, fmt.Errorf("Unable to stat file %s: %v", dstPath, err) 247 | } 248 | 249 | // Close the file 250 | if err := pf.Close(); err != nil { 251 | return -1, fmt.Errorf("Unable to close file %s: %v", dstPath, err) 252 | } 253 | 254 | return stat.Size(), nil 255 | } 256 | 257 | func exportInstance(instance, dstFile string, optimized bool) (int64, error) { 258 | cmd := exec.Command("lxc", "export", instance, dstFile) 259 | if optimized { 260 | cmd = exec.Command("lxc", "export", "--optimized-storage", instance, dstFile) 261 | } 262 | cmd.Stdout = ioutil.Discard 263 | 264 | if err := cmd.Run(); err != nil { 265 | return -1, fmt.Errorf("Unable to export instance: %v", err) 266 | } 267 | 268 | s, err := os.Stat(dstFile) 269 | if err != nil { 270 | return -1, fmt.Errorf("Unable to stat file %s: %v", dstFile, err) 271 | } 272 | return s.Size(), nil 273 | } 274 | 275 | func fetchExistingProfiles() (s set.StringSet, err error) { 276 | // First get the list of existing profiles, so we can restore 277 | // only missing ones. 278 | var outBuf bytes.Buffer 279 | cmd := exec.Command("lxc", "profile", "list", "-f", "yaml") 280 | cmd.Stdout = &outBuf 281 | 282 | if err := cmd.Run(); err != nil { 283 | return s, fmt.Errorf("Unable to list profiles: %v", err) 284 | } 285 | 286 | type profileInfo struct { 287 | Name string `yaml:"name"` 288 | } 289 | 290 | var profileInfos []profileInfo 291 | if err := yaml.Unmarshal(outBuf.Bytes(), &profileInfos); err != nil { 292 | return nil, fmt.Errorf("Unable to parse profiles list: %v", err) 293 | } 294 | 295 | s = set.NewStringSet() 296 | for _, pi := range profileInfos { 297 | s.Add(pi.Name) 298 | } 299 | return s, nil 300 | } 301 | 302 | type warnMsgErr struct { 303 | msg warningMessage 304 | } 305 | 306 | func (w warnMsgErr) Error() string { 307 | return "" 308 | } 309 | 310 | func restoreProfile(ctx *lxminContext, profile, profileKey string, existingProfiles set.StringSet) error { 311 | proPath := path.Join(ctx.StagingRoot, path.Base(profileKey)) 312 | 313 | if existingProfiles.Contains(profile) { 314 | defer os.Remove(proPath) 315 | return warnMsgErr{msg: warningMessage{ 316 | msg: `%s Skipping profile ` + profile + ` as it already exists for: %s`, 317 | }} 318 | } 319 | 320 | cmd := exec.Command("lxc", "profile", "create", profile) 321 | if err := cmd.Run(); err != nil { 322 | return fmt.Errorf("Error creating profile %s: %v", profile, err) 323 | } 324 | 325 | profileFile, err := os.Open(proPath) 326 | if err != nil { 327 | return fmt.Errorf("Error opening backup file %s: %v", proPath, err) 328 | } 329 | 330 | cmd = exec.Command("lxc", "profile", "edit", profile) 331 | cmd.Stdin = profileFile 332 | if err := cmd.Run(); err != nil { 333 | return fmt.Errorf("Error restoring profile %s: %v", profile, err) 334 | } 335 | 336 | defer os.Remove(proPath) 337 | return nil 338 | } 339 | 340 | func restoreInstance(ctx *lxminContext, bkp backup) (*bytes.Buffer, error) { 341 | outBuf := bytes.Buffer{} 342 | localPath := path.Join(ctx.StagingRoot, bkp.backupName+"_instance.tar.gz") 343 | 344 | lastCmd := []string{"lxc", "import", localPath} 345 | cmd := exec.Command(lastCmd[0], lastCmd[1:]...) 346 | cmd.Stdout = ioutil.Discard 347 | cmd.Stderr = &outBuf 348 | if err := cmd.Run(); err != nil { 349 | errBuf := bytes.Buffer{} 350 | errBuf.Write([]byte( 351 | fmt.Sprintf("Command: %s\n", strings.Join(lastCmd, " ")), 352 | )) 353 | errBuf.Write(outBuf.Bytes()) 354 | return &errBuf, fmt.Errorf("Error importing instance: %v", err) 355 | } 356 | 357 | // Clear outBuf for next command 358 | outBuf = bytes.Buffer{} 359 | lastCmd = []string{"lxc", "start", bkp.instance} 360 | cmd = exec.Command(lastCmd[0], lastCmd[1:]...) 361 | cmd.Stdout = ioutil.Discard 362 | cmd.Stderr = &outBuf 363 | if err := cmd.Run(); err != nil { 364 | errBuf := bytes.Buffer{} 365 | errBuf.Write([]byte( 366 | fmt.Sprintf("Command: %s\n", strings.Join(lastCmd, " ")), 367 | )) 368 | errBuf.Write(outBuf.Bytes()) 369 | return &errBuf, fmt.Errorf("Error starting instance: %v", err) 370 | } 371 | 372 | defer os.Remove(localPath) 373 | return nil, nil 374 | } 375 | -------------------------------------------------------------------------------- /lxmin.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2022 MinIO, Inc. 2 | // 3 | // This project is part of MinIO Object Storage stack 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Affero General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Affero General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with this program. If not, see . 17 | 18 | package main 19 | 20 | import ( 21 | "context" 22 | "crypto/x509" 23 | "fmt" 24 | "io" 25 | "net/http" 26 | "os" 27 | "path" 28 | "strings" 29 | "time" 30 | 31 | "github.com/cheggaaa/pb/v3" 32 | "github.com/minio/minio-go/v7" 33 | "github.com/minio/minio-go/v7/pkg/tags" 34 | "github.com/minio/pkg/v2/certs" 35 | ) 36 | 37 | type backupMeta struct { 38 | Size int64 39 | LastModified time.Time 40 | UserMetadata minio.StringMap 41 | } 42 | 43 | type lxminContext struct { 44 | Clnt *minio.Client 45 | Bucket string 46 | StagingRoot string 47 | TLSCerts *certs.Manager 48 | RootCAs *x509.CertPool 49 | NotifyClnt *http.Client 50 | NotifyEndpoint string 51 | } 52 | 53 | // GetTags - fetch tags on the backup. 54 | func (l *lxminContext) GetTags(bkp backup) (*tags.Tags, error) { 55 | opts := minio.GetObjectTaggingOptions{} 56 | return l.Clnt.GetObjectTagging(context.Background(), l.Bucket, bkp.key(), opts) 57 | } 58 | 59 | // GetMetadata - get backup metadata. 60 | func (l *lxminContext) GetMetadata(bkp backup) (backupMeta, error) { 61 | sopts := minio.StatObjectOptions{} 62 | obj, err := l.Clnt.StatObject(context.Background(), l.Bucket, bkp.key(), sopts) 63 | if err != nil { 64 | return backupMeta{}, err 65 | } 66 | 67 | return backupMeta{ 68 | Size: obj.Size, 69 | LastModified: obj.LastModified, 70 | UserMetadata: obj.UserMetadata, 71 | }, nil 72 | } 73 | 74 | // listAndDelete - CAUTION: deletes everything at the prefix. 75 | func (l *lxminContext) listAndDelete(prefix string) error { 76 | opts := minio.RemoveObjectOptions{} 77 | 78 | resCh := l.Clnt.ListObjects(context.Background(), l.Bucket, minio.ListObjectsOptions{ 79 | Prefix: prefix, 80 | WithVersions: true, 81 | }) 82 | 83 | isVersioned := true 84 | for obj := range resCh { 85 | if obj.Err != nil { 86 | switch minio.ToErrorResponse(obj.Err).Code { 87 | case "NotImplemented": 88 | // fallback for ListObjectVersions not implemented. 89 | resCh = l.Clnt.ListObjects(context.Background(), l.Bucket, minio.ListObjectsOptions{ 90 | Prefix: prefix, 91 | }) 92 | isVersioned = false 93 | continue 94 | default: 95 | return obj.Err 96 | } 97 | } 98 | 99 | if isVersioned { 100 | // When listing is versioned, set the version ID for 101 | // delete. 102 | opts.VersionID = obj.VersionID 103 | } 104 | if err := l.Clnt.RemoveObject(context.Background(), l.Bucket, obj.Key, opts); err != nil { 105 | return err 106 | } 107 | } 108 | 109 | return nil 110 | } 111 | 112 | // DeleteBackup - deletes a particular backup of an instance in MinIO. 113 | func (l *lxminContext) DeleteBackup(bkp backup) error { 114 | prefix := bkp.prefix() 115 | return l.listAndDelete(prefix) 116 | } 117 | 118 | // DeleteAllBackups - deletes all backups for the given instance. 119 | func (l *lxminContext) DeleteAllBackups(instance string) error { 120 | prefix := path.Clean(instance) + "/" 121 | return l.listAndDelete(prefix) 122 | } 123 | 124 | // ListItems - lists all items at the given prefix. 125 | func (l *lxminContext) ListItems(prefix string) ([]minio.ObjectInfo, error) { 126 | var oi []minio.ObjectInfo 127 | for obj := range l.Clnt.ListObjects(context.Background(), l.Bucket, minio.ListObjectsOptions{ 128 | Prefix: prefix, 129 | Recursive: true, 130 | WithMetadata: true, 131 | }) { 132 | if obj.Err != nil { 133 | return nil, obj.Err 134 | } 135 | 136 | oi = append(oi, obj) 137 | } 138 | return oi, nil 139 | } 140 | 141 | func objToBackupInfo(obj minio.ObjectInfo, instance string) backupInfo { 142 | backupName := strings.TrimSuffix(path.Base(obj.Key), "_instance.tar.gz") 143 | 144 | optimized := obj.UserMetadata["X-Amz-Meta-Optimized"] == "true" 145 | compressed := obj.UserMetadata["X-Amz-Meta-Compressed"] == "true" 146 | return backupInfo{ 147 | Instance: instance, 148 | Name: backupName, 149 | Created: &obj.LastModified, 150 | Size: obj.Size, 151 | Optimized: &optimized, 152 | Compressed: &compressed, 153 | Tags: obj.UserTags, 154 | } 155 | } 156 | 157 | // ListBackups - lists available backups in MinIO. If `instance` is empty lists 158 | // backups for all instances. 159 | func (l *lxminContext) ListBackups(instance string) ([]backupInfo, error) { 160 | var backups []backupInfo 161 | prefix := "" 162 | if instance != "" { 163 | prefix = path.Clean(instance) + "/" 164 | } 165 | backupItems, err := l.ListItems(prefix) 166 | if err != nil { 167 | return nil, err 168 | } 169 | 170 | for _, obj := range backupItems { 171 | // Do not consider the profiles in the listing. 172 | if !strings.HasSuffix(obj.Key, "_instance.tar.gz") { 173 | continue 174 | } 175 | 176 | inst := instance 177 | if instance == "" { 178 | inst = path.Dir(obj.Key) 179 | } 180 | 181 | backups = append(backups, objToBackupInfo(obj, inst)) 182 | } 183 | return backups, nil 184 | } 185 | 186 | type restoreInfo struct { 187 | profiles []string 188 | profileKeys []string 189 | totalSize int64 190 | } 191 | 192 | func (l *lxminContext) fetchRestoreInfo(bkp backup) (ri restoreInfo, err error) { 193 | items, err := l.ListItems(path.Join(bkp.instance, bkp.backupName+"_profile_")) 194 | if err != nil { 195 | return ri, fmt.Errorf("Error listing profiles for backup %s (instance: %s): %v", bkp.backupName, bkp.instance, err) 196 | } 197 | 198 | for pno, obj := range items { 199 | expectedProfilePrefix := fmt.Sprintf("%s_profile_%03d_", bkp.backupName, pno) 200 | profileName := strings.TrimPrefix( 201 | strings.TrimSuffix(path.Base(obj.Key), ".yaml"), 202 | expectedProfilePrefix, 203 | ) 204 | 205 | // Validate the profile object name. 206 | if !strings.HasPrefix(path.Base(obj.Key), expectedProfilePrefix) || !strings.HasSuffix(obj.Key, ".yaml") || profileName == "" { 207 | return ri, fmt.Errorf("Unexpected profile file found: %s", obj.Key) 208 | } 209 | 210 | ri.totalSize += obj.Size 211 | ri.profiles = append(ri.profiles, profileName) 212 | ri.profileKeys = append(ri.profileKeys, obj.Key) 213 | } 214 | 215 | oi, err := l.Clnt.StatObject(context.Background(), l.Bucket, bkp.key(), minio.StatObjectOptions{}) 216 | if err != nil { 217 | return ri, fmt.Errorf("Error getting instance backup file info: %v", err) 218 | } 219 | 220 | ri.totalSize += oi.Size 221 | return ri, nil 222 | } 223 | 224 | func (l *lxminContext) downloadItem(objPath string, bar *pb.ProgressBar) error { 225 | fpath := path.Join(l.StagingRoot, path.Base(objPath)) 226 | var w io.Writer 227 | if bar != nil { 228 | barWriter, err := newBarUpdateWriter(fpath, bar, tmplDl) 229 | if err != nil { 230 | return err 231 | } 232 | defer barWriter.Close() 233 | w = barWriter 234 | } else { 235 | f, err := os.Create(fpath) 236 | if err != nil { 237 | return err 238 | } 239 | defer f.Close() 240 | w = f 241 | } 242 | 243 | obj, err := l.Clnt.GetObject(context.Background(), l.Bucket, objPath, minio.GetObjectOptions{}) 244 | if err != nil { 245 | return err 246 | } 247 | defer obj.Close() 248 | 249 | _, err = io.Copy(w, obj) 250 | return err 251 | } 252 | 253 | type backup struct { 254 | instance, backupName string 255 | } 256 | 257 | func (b *backup) key() string { 258 | return path.Join(b.instance, b.backupName+"_instance.tar.gz") 259 | } 260 | 261 | // prefix - returns the prefix at which all backup files are present. 262 | func (b *backup) prefix() string { 263 | return path.Join(b.instance, b.backupName) 264 | } 265 | 266 | type backupOpts struct { 267 | TagsSet *tags.Tags 268 | PartSize int64 269 | Optimized bool 270 | } 271 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2022 MinIO, Inc. 2 | // 3 | // This project is part of MinIO Object Storage stack 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Affero General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Affero General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with this program. If not, see . 17 | 18 | package main 19 | 20 | import ( 21 | "context" 22 | "crypto/tls" 23 | "crypto/x509" 24 | "errors" 25 | "log" 26 | "net" 27 | "net/http" 28 | "os" 29 | "os/exec" 30 | "os/signal" 31 | "time" 32 | 33 | "github.com/gorilla/handlers" 34 | "github.com/gorilla/mux" 35 | "github.com/minio/cli" 36 | ) 37 | 38 | const ( 39 | tmplUp = `Uploading %s {{ bar . "┃" "▓" "▓" "░" "┃"}} {{speed . "%%s/s" "? MiB/s"}}` 40 | tmplDl = `Downloading %s {{ bar . "┃" "▓" "▓" "░" "┃"}} {{speed . "%%s/s" "? MiB/s"}}` 41 | ) 42 | 43 | var globalFlags = []cli.Flag{ 44 | cli.StringFlag{ 45 | Name: "endpoint", 46 | EnvVar: "LXMIN_ENDPOINT", 47 | Usage: "endpoint for MinIO server", 48 | }, 49 | cli.StringFlag{ 50 | Name: "bucket", 51 | EnvVar: "LXMIN_BUCKET", 52 | Usage: "bucket to save/restore backup(s)", 53 | }, 54 | cli.StringFlag{ 55 | Name: "access-key", 56 | EnvVar: "LXMIN_ACCESS_KEY", 57 | Usage: "access key credential", 58 | }, 59 | cli.StringFlag{ 60 | Name: "secret-key", 61 | EnvVar: "LXMIN_SECRET_KEY", 62 | Usage: "secret key credential", 63 | }, 64 | cli.StringFlag{ 65 | Name: "address", 66 | EnvVar: "LXMIN_ADDRESS", 67 | Usage: "enable TLS REST API service", 68 | }, 69 | cli.StringFlag{ 70 | Name: "cert", 71 | EnvVar: "LXMIN_TLS_CERT", 72 | Usage: "TLS server certificate", 73 | }, 74 | cli.StringFlag{ 75 | Name: "key", 76 | EnvVar: "LXMIN_TLS_KEY", 77 | Usage: "TLS server private key", 78 | }, 79 | cli.StringFlag{ 80 | Name: "capath", 81 | EnvVar: "LXMIN_TLS_CAPATH", 82 | Usage: "TLS trust certs for incoming clients", 83 | }, 84 | cli.StringFlag{ 85 | Name: "notify-endpoint", 86 | EnvVar: "LXMIN_NOTIFY_ENDPOINT", 87 | Usage: "HTTP(S) POST endpoint to send notifications for REST API", 88 | }, 89 | cli.StringFlag{ 90 | Name: "staging", 91 | EnvVar: "LXMIN_STAGING_ROOT", 92 | Usage: "root path for staging the backups before uploading to MinIO", 93 | }, 94 | } 95 | 96 | var helpTemplate = `NAME: 97 | {{.Name}} - {{.Usage}} 98 | 99 | USAGE: 100 | {{.Name}} {{if .VisibleFlags}}[FLAGS] {{end}}COMMAND{{if .VisibleFlags}} [COMMAND FLAGS | -h]{{end}} [ARGUMENTS...] 101 | 102 | COMMANDS: 103 | {{range .VisibleCommands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} 104 | {{end}}{{if .VisibleFlags}} 105 | GLOBAL FLAGS: 106 | {{range .VisibleFlags}}{{.}} 107 | {{end}} 108 | ENVIRONMENT VARIABLES:{{range .VisibleFlags}} 109 | {{if ne .EnvVar ""}}{{.EnvVar}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}} 110 | ` 111 | 112 | var appCmds = []cli.Command{ 113 | backupCmd, 114 | restoreCmd, 115 | infoCmd, 116 | listCmd, 117 | deleteCmd, 118 | } 119 | 120 | func authenticateTLSClientHandler(h http.Handler) http.Handler { 121 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 122 | if r.TLS == nil { 123 | writeErrorResponse(w, errors.New("no tls connection")) 124 | return 125 | } 126 | 127 | // A client may send a certificate chain such that we end up 128 | // with multiple peer certificates. However, we can only accept 129 | // a single client certificate. Otherwise, the certificate to 130 | // policy mapping would be ambigious. 131 | // However, we can filter all CA certificates and only check 132 | // whether they client has sent exactly one (non-CA) leaf certificate. 133 | peerCertificates := make([]*x509.Certificate, 0, len(r.TLS.PeerCertificates)) 134 | for _, cert := range r.TLS.PeerCertificates { 135 | if cert.IsCA { 136 | continue 137 | } 138 | peerCertificates = append(peerCertificates, cert) 139 | } 140 | r.TLS.PeerCertificates = peerCertificates 141 | 142 | // Now, we have to check that the client has provided exactly one leaf 143 | // certificate that we can map to a policy. 144 | if len(r.TLS.PeerCertificates) == 0 { 145 | writeErrorResponse(w, errors.New("no client certificate provided")) 146 | return 147 | } 148 | 149 | if len(r.TLS.PeerCertificates) > 1 { 150 | writeErrorResponse(w, errors.New("more than one client certificate provided")) 151 | return 152 | } 153 | 154 | certificate := r.TLS.PeerCertificates[0] 155 | if _, err := certificate.Verify(x509.VerifyOptions{ 156 | KeyUsages: []x509.ExtKeyUsage{ 157 | x509.ExtKeyUsageClientAuth, 158 | }, 159 | Roots: globalContext.RootCAs, 160 | }); err != nil { 161 | writeErrorResponse(w, err) 162 | return 163 | } 164 | 165 | if err := r.ParseForm(); err != nil { 166 | writeErrorResponse(w, err) 167 | return 168 | } 169 | 170 | h.ServeHTTP(w, r) 171 | }) 172 | } 173 | 174 | func mainHTTP(c *cli.Context) error { 175 | if c.Args().Present() { 176 | // With args present no need to start lxmin service. 177 | return nil 178 | } 179 | if !c.IsSet("address") { 180 | return errors.New("address cannot be empty please use '--address=:8000' to start lxmin as service") 181 | } 182 | 183 | if err := setGlobalsFromContext(c); err != nil { 184 | return err 185 | } 186 | 187 | r := mux.NewRouter() 188 | r.StrictSlash(false) 189 | r.SkipClean(true) 190 | 191 | r.HandleFunc("/1.0/instances/{name}/backups", listHandler).Methods(http.MethodGet) 192 | r.HandleFunc("/1.0/instances/{name}/backups", backupHandler).Methods(http.MethodPost) 193 | r.HandleFunc("/1.0/instances/{name}/backups/{backup}", infoHandler).Methods(http.MethodGet) 194 | r.HandleFunc("/1.0/instances/{name}/backups/{backup}", deleteHandler).Methods(http.MethodDelete) 195 | r.HandleFunc("/1.0/instances/{name}/backups/{backup}", restoreHandler).Methods(http.MethodPost) 196 | r.HandleFunc("/1.0/health", healthHandler).Methods(http.MethodGet, http.MethodHead) 197 | r.Use(authenticateTLSClientHandler) 198 | 199 | tlsConfig := &tls.Config{ 200 | PreferServerCipherSuites: true, 201 | MinVersion: tls.VersionTLS12, 202 | NextProtos: []string{"http/1.1", "h2"}, 203 | GetCertificate: globalContext.TLSCerts.GetCertificate, 204 | ClientAuth: tls.RequestClientCert, 205 | } 206 | 207 | r.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 208 | NotFound(nil).Render(w) 209 | }) 210 | 211 | srv := &http.Server{ 212 | Handler: handlers.CompressHandler(handlers.LoggingHandler(os.Stdout, handlers.ProxyHeaders(r))), 213 | Addr: c.String("address"), 214 | TLSConfig: tlsConfig, 215 | IdleTimeout: time.Second * 60, 216 | } 217 | 218 | // Run our server in a goroutine so that it doesn't block. 219 | go func() { 220 | log.Println("Server listening on", srv.Addr) 221 | 222 | ln, err := net.Listen("tcp", srv.Addr) 223 | if err != nil { 224 | log.Fatalln(err) 225 | } 226 | 227 | defer ln.Close() 228 | 229 | if err := srv.Serve(tls.NewListener(ln, tlsConfig)); err != nil && err != http.ErrServerClosed { 230 | log.Fatalln(err) 231 | } 232 | }() 233 | 234 | ch := make(chan os.Signal, 1) 235 | // We'll accept graceful shutdowns when quit via SIGINT (Ctrl+C) 236 | // SIGKILL, SIGQUIT or SIGTERM (Ctrl+/) will not be caught. 237 | signal.Notify(ch, os.Interrupt) 238 | 239 | // Block until we receive our signal. 240 | <-ch 241 | 242 | // Create a deadline to wait for. 243 | ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) 244 | defer cancel() 245 | 246 | // Doesn't block if no connections, but will otherwise wait 247 | // until the timeout deadline. 248 | srv.Shutdown(ctx) 249 | 250 | // Optionally, you could run srv.Shutdown in a goroutine and block on 251 | // <-ctx.Done() if your application should wait for other services 252 | // to finalize based on context cancellation. 253 | return nil 254 | } 255 | 256 | func main() { 257 | app := cli.NewApp() 258 | app.Copyright = "MinIO, Inc." 259 | app.Usage = "backup and restore LXC instances with MinIO" 260 | app.CustomAppHelpTemplate = helpTemplate 261 | app.HideHelpCommand = true 262 | app.HideVersion = true 263 | app.Flags = globalFlags 264 | app.Commands = appCmds 265 | app.Before = func(c *cli.Context) error { 266 | if c.Bool("help") { 267 | cli.ShowAppHelpAndExit(c, 0) // last argument is exit code 268 | } 269 | _, err := exec.LookPath("lxc") 270 | return err 271 | } 272 | 273 | // Start http service if configured. 274 | app.Action = mainHTTP 275 | 276 | if err := app.Run(os.Args); err != nil { 277 | log.Fatalln(err) 278 | } 279 | } 280 | -------------------------------------------------------------------------------- /notify.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2022 MinIO, Inc. 2 | // 3 | // This project is part of MinIO Object Storage stack 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Affero General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Affero General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with this program. If not, see . 17 | 18 | package main 19 | 20 | import ( 21 | "bytes" 22 | "encoding/json" 23 | "fmt" 24 | "log" 25 | "net/http" 26 | "time" 27 | ) 28 | 29 | // Consts for different operations 30 | const ( 31 | Backup = "backup" 32 | Restore = "restore" 33 | ) 34 | 35 | // Consts for backup, restore states 36 | const ( 37 | Failed = "failed" 38 | Success = "success" 39 | Started = "started" 40 | ) 41 | 42 | type eventInfo struct { 43 | OpType string `json:"opType"` 44 | State string `json:"state"` 45 | Name string `json:"name"` 46 | Instance string `json:"instance"` 47 | StartedAt *time.Time `json:"startedAt,omitempty"` 48 | CompletedAt *time.Time `json:"completedAt,omitempty"` 49 | FailedAt *time.Time `json:"failedAt,omitempty"` 50 | RawURL string `json:"rawURL,omitempty"` 51 | Error error `json:"error,omitempty"` 52 | } 53 | 54 | func notifyEvent(e eventInfo, endpoint string) { 55 | data, err := json.Marshal(&e) 56 | if err != nil { 57 | log.Println(err) 58 | return 59 | } 60 | 61 | req, err := http.NewRequest(http.MethodPost, endpoint, bytes.NewReader(data)) 62 | if err != nil { 63 | log.Println(err) 64 | return 65 | } 66 | 67 | // Set proper content type. 68 | req.Header.Set("Content-Type", "application/json") 69 | 70 | resp, err := globalContext.NotifyClnt.Do(req) 71 | if err != nil { 72 | log.Println(err) 73 | return 74 | } 75 | defer resp.Body.Close() 76 | 77 | if resp.StatusCode != http.StatusOK { 78 | log.Println(fmt.Sprintf("notification endpoint returned error: %s", resp.Status)) 79 | return 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /restore.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2022 MinIO, Inc. 2 | // 3 | // This project is part of MinIO Object Storage stack 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Affero General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Affero General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with this program. If not, see . 17 | 18 | package main 19 | 20 | import ( 21 | "bytes" 22 | "fmt" 23 | "io" 24 | "log" 25 | "os" 26 | "path" 27 | "strings" 28 | 29 | tea "github.com/charmbracelet/bubbletea" 30 | "github.com/cheggaaa/pb/v3" 31 | "github.com/minio/cli" 32 | "github.com/minio/minio-go/v7/pkg/set" 33 | ) 34 | 35 | var restoreCmd = cli.Command{ 36 | Name: "restore", 37 | Usage: "restore an instance image from MinIO", 38 | Action: restoreMain, 39 | Before: setGlobalsFromContext, 40 | Flags: globalFlags, 41 | CustomHelpTemplate: `NAME: 42 | {{.HelpName}} - {{.Usage}} 43 | 44 | USAGE: 45 | {{.HelpName}} [FLAGS] INSTANCENAME BACKUPNAME 46 | 47 | FLAGS: 48 | {{range .VisibleFlags}}{{.}} 49 | {{end}} 50 | EXAMPLES: 51 | 1. Restore an instance 'u2' from a backup 'backup_2022-02-16-04-1040': 52 | {{.Prompt}} {{.HelpName}} u2 backup_2022-02-16-04-1040 53 | `, 54 | } 55 | 56 | func restoreMain(c *cli.Context) error { 57 | if len(c.Args()) > 2 { 58 | cli.ShowAppHelpAndExit(c, 1) // last argument is exit code 59 | } 60 | 61 | instance := strings.TrimSpace(c.Args().Get(0)) 62 | if instance == "" { 63 | cli.ShowAppHelpAndExit(c, 1) // last argument is exit code 64 | } 65 | 66 | backupName := strings.TrimSpace(c.Args().Get(1)) 67 | if backupName == "" { 68 | cli.ShowAppHelpAndExit(c, 1) // last argument is exit code 69 | } 70 | 71 | if err := checkInstance(instance); err != nil { 72 | return err 73 | } 74 | 75 | bkp := backup{instance: instance, backupName: backupName} 76 | 77 | // List and collect all backup related files. 78 | resInfo := collectBackupInfo(globalContext, bkp) 79 | 80 | // Download all backup files to staging directory 81 | err := downloadBackupFiles(globalContext, bkp, resInfo) 82 | if err != nil { 83 | return err 84 | } 85 | 86 | restoreProfiles(globalContext, instance, backupName, resInfo) 87 | 88 | restoreInstanceCLI(globalContext, bkp) 89 | 90 | return nil 91 | } 92 | 93 | func restoreInstanceCLI(ctx *lxminContext, bkp backup) { 94 | var lastCmd []string 95 | var outBuf *bytes.Buffer 96 | restoreCmd := func() tea.Msg { 97 | ob, err := restoreInstance(ctx, bkp) 98 | if err != nil { 99 | outBuf = ob 100 | return err 101 | } 102 | return true 103 | } 104 | 105 | sUI := initCmdSpinnerUI( 106 | restoreCmd, 107 | cOpts{instance: bkp.instance, message: `%s Launching instance: %s`}, 108 | ) 109 | if err := tea.NewProgram(sUI).Start(); err != nil { 110 | log.Printf("Last command: `%s`", strings.Join(lastCmd, " ")) 111 | log.Printf("Output: %s", string(outBuf.Bytes())) 112 | log.Fatalln(err) 113 | } 114 | } 115 | 116 | func restoreProfiles(ctx *lxminContext, instance, backupNamePrefix string, resInfo restoreInfo) { 117 | existingProfiles := set.NewStringSet() 118 | retrieveExistingProfiles := func() tea.Msg { 119 | p, err := fetchExistingProfiles() 120 | if err != nil { 121 | return err 122 | } 123 | existingProfiles = p 124 | return true 125 | } 126 | 127 | sUI := initCmdSpinnerUI( 128 | retrieveExistingProfiles, 129 | cOpts{instance: instance, message: `%s Retrieving existing profiles list: %s`}, 130 | ) 131 | if err := tea.NewProgram(sUI).Start(); err != nil { 132 | log.Fatalln(err) 133 | } 134 | 135 | for i, pf := range resInfo.profiles { 136 | restoreProfile := func() tea.Msg { 137 | err := restoreProfile(ctx, pf, resInfo.profileKeys[i], existingProfiles) 138 | if w, ok := err.(warnMsgErr); ok { 139 | return w.msg 140 | } else if err != nil { 141 | return err 142 | } 143 | return true 144 | } 145 | 146 | sUI := initCmdSpinnerUI(restoreProfile, 147 | cOpts{instance: instance, message: `%s Created profile ` + pf + ` for: %s`}) 148 | if err := tea.NewProgram(sUI).Start(); err != nil { 149 | log.Fatalln(err) 150 | } 151 | } 152 | } 153 | 154 | func downloadBackupFiles(ctx *lxminContext, bkp backup, resInfo restoreInfo) error { 155 | bar := pb.Start64(resInfo.totalSize) 156 | bar.Set(pb.Bytes, true) 157 | defer bar.Finish() 158 | 159 | // Download profiles 160 | for _, pkey := range resInfo.profileKeys { 161 | err := ctx.downloadItem(pkey, bar) 162 | if err != nil { 163 | return fmt.Errorf("Error downloading profile file %s: %v", pkey, err) 164 | } 165 | } 166 | 167 | // Download instance backup 168 | if err := ctx.downloadItem(bkp.key(), bar); err != nil { 169 | return fmt.Errorf("Error downloading instance backup %s: %v", bkp.key(), err) 170 | } 171 | return nil 172 | } 173 | 174 | type barUpdateWriter struct { 175 | w io.Writer 176 | bar *pb.ProgressBar 177 | } 178 | 179 | func newBarUpdateWriter(fpath string, bar *pb.ProgressBar, tmpl string) (*barUpdateWriter, error) { 180 | w, err := os.Create(fpath) 181 | if err != nil { 182 | return nil, fmt.Errorf("Unable to create %s: %v", fpath, err) 183 | } 184 | 185 | bar.SetTemplateString(fmt.Sprintf(tmpl, path.Base(fpath))) 186 | 187 | return &barUpdateWriter{ 188 | w: w, 189 | bar: bar, 190 | }, nil 191 | } 192 | 193 | func (b *barUpdateWriter) Write(p []byte) (n int, err error) { 194 | n, err = b.w.Write(p) 195 | b.bar.Add(n) 196 | return 197 | } 198 | 199 | // Close closes the underlying writer if it is a io.Closer. 200 | func (b *barUpdateWriter) Close() error { 201 | if c, ok := b.w.(io.Closer); ok { 202 | return c.Close() 203 | } 204 | return nil 205 | } 206 | 207 | // collectBackupInfo collects backup info so we can show a progress bar and 208 | // restore profiles in order. 209 | func collectBackupInfo(ctx *lxminContext, bkp backup) (bi restoreInfo) { 210 | populateRestoreInfo := func() tea.Msg { 211 | ri, err := ctx.fetchRestoreInfo(bkp) 212 | if err != nil { 213 | return err 214 | } 215 | bi = ri 216 | return true 217 | } 218 | 219 | sUI := initCmdSpinnerUI( 220 | populateRestoreInfo, 221 | cOpts{instance: bkp.instance, message: `%s Collecting info for backup: %s`}, 222 | ) 223 | if err := tea.NewProgram(sUI).Start(); err != nil { 224 | log.Fatalln(err) 225 | } 226 | 227 | return bi 228 | } 229 | -------------------------------------------------------------------------------- /systemd/README.md: -------------------------------------------------------------------------------- 1 | # Systemd service for Lxmin 2 | 3 | Systemd script for `lxmin`. 4 | 5 | ## Installation 6 | 7 | - Systemd script is configured to run the binary from /usr/local/bin/ 8 | - Download the binary from https://github.com/minio/lxmin/releases 9 | 10 | ## Create default configuration 11 | 12 | ```sh 13 | $ cat <> /etc/default/lxmin 14 | 15 | ## MinIO endpoint configuration 16 | LXMIN_ENDPOINT=http://localhost:9000 17 | LXMIN_BUCKET="backups" 18 | LXMIN_ACCESS_KEY="minioadmin" 19 | LXMIN_SECRET_KEY="minioadmin" 20 | 21 | ## LXMIN address 22 | LXMIN_ADDRESS=":8000" 23 | 24 | ## LXMIN server certificate and client trust certs. 25 | LXMIN_TLS_CERT="/var/snap/lxd/common/lxd/server.crt" 26 | LXMIN_TLS_KEY="/var/snap/lxd/common/lxd/server.key" 27 | LXMIN_TLS_CAPATH="/var/snap/lxd/capath" 28 | EOF 29 | ``` 30 | 31 | ## Systemctl 32 | 33 | Download lxmin.service in /etc/systemd/system/ 34 | 35 | ## Enable startup on boot 36 | 37 | ``` 38 | systemctl enable lxmin.service 39 | ``` 40 | 41 | ## Note 42 | Replace User=nobody and Group=nobody in lxmin.service file with your local setup user. 43 | -------------------------------------------------------------------------------- /systemd/lxmin.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Lxmin 3 | Documentation=https://github.com/minio/lxmin/blob/master/README.md 4 | Wants=network-online.target 5 | After=network-online.target 6 | AssertFileIsExecutable=/usr/bin/lxmin 7 | 8 | [Service] 9 | User=nobody 10 | Group=nogroup 11 | 12 | EnvironmentFile=/etc/default/lxmin 13 | ExecStart=/usr/bin/lxmin 14 | 15 | # Let systemd restart this service always 16 | Restart=always 17 | 18 | # Specifies the maximum file descriptor number that can be opened by this process 19 | LimitNOFILE=65536 20 | 21 | # Disable timeout logic and wait until process is stopped 22 | TimeoutStopSec=infinity 23 | SendSIGKILL=no 24 | 25 | [Install] 26 | WantedBy=multi-user.target 27 | 28 | -------------------------------------------------------------------------------- /testdata/client.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIHzMIGmoAMCAQICEQC5nWSqvp/J4YtyIyptR+FJMAUGAytlcDAAMB4XDTIyMDIy 3 | NTExMDIxN1oXDTIyMDMyNzExMDIxN1owADAqMAUGAytlcAMhABhRr2391G7RN0Xg 4 | YKPT7H/vIHI14fp55j6RphkcjanmozUwMzAOBgNVHQ8BAf8EBAMCB4AwEwYDVR0l 5 | BAwwCgYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADAFBgMrZXADQQBGErKoBUhctQcg 6 | lQ7ta4Nz6J5LN+7RfGg9U4tWStWR9AOsVByh2aKxL9a9xklQfh0vAB/rRrtI/k78 7 | 8FV2tuMN 8 | -----END CERTIFICATE----- 9 | -------------------------------------------------------------------------------- /testdata/client.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MC4CAQAwBQYDK2VwBCIEIGil7jWFIqFS1h0j6jGxLl3UXm6fF2tim5253zflta1l 3 | -----END PRIVATE KEY----- 4 | -------------------------------------------------------------------------------- /testdata/server/capath/client.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIB2TCCAV6gAwIBAgIQbYkhNssGzwCMsh6cJET5kzAKBggqhkjOPQQDAzA0MRww 3 | GgYDVQQKExNsaW51eGNvbnRhaW5lcnMub3JnMRQwEgYDVQQDDAtoYXJzaGFAbmFu 4 | bzAeFw0yMjAyMTcwMTQ4MjBaFw0zMjAyMTUwMTQ4MjBaMDQxHDAaBgNVBAoTE2xp 5 | bnV4Y29udGFpbmVycy5vcmcxFDASBgNVBAMMC2hhcnNoYUBuYW5vMHYwEAYHKoZI 6 | zj0CAQYFK4EEACIDYgAEHJMzTd0SvQ2kPRScLC74/yZfJVoWIoIrrnSg4gvbMLgI 7 | jtBfxtbpEXW+GJ8f1HCJP7wPuS2bgpZNfD8P9ZIuhrNDRzPI7J4b5+TD2gHtwPkC 8 | X50sKrPk5Q5V+D4RX3VeozUwMzAOBgNVHQ8BAf8EBAMCBaAwEwYDVR0lBAwwCgYI 9 | KwYBBQUHAwIwDAYDVR0TAQH/BAIwADAKBggqhkjOPQQDAwNpADBmAjEAg5tVzAjy 10 | CjxsYCxHGkupe3w7bos2vhcjAhCkPrjBdVfHDMT0SUDRHqgSx14h6RQVAjEAz5Kl 11 | B8mq6700Lrqvax6cceYUg4QFV+irGVk1IanD8q+qEDu65MoR9Sic2+mcVvTv 12 | -----END CERTIFICATE----- 13 | -------------------------------------------------------------------------------- /testdata/server/capath/public.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIHzMIGmoAMCAQICEQC5nWSqvp/J4YtyIyptR+FJMAUGAytlcDAAMB4XDTIyMDIy 3 | NTExMDIxN1oXDTIyMDMyNzExMDIxN1owADAqMAUGAytlcAMhABhRr2391G7RN0Xg 4 | YKPT7H/vIHI14fp55j6RphkcjanmozUwMzAOBgNVHQ8BAf8EBAMCB4AwEwYDVR0l 5 | BAwwCgYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADAFBgMrZXADQQBGErKoBUhctQcg 6 | lQ7ta4Nz6J5LN+7RfGg9U4tWStWR9AOsVByh2aKxL9a9xklQfh0vAB/rRrtI/k78 7 | 8FV2tuMN 8 | -----END CERTIFICATE----- 9 | -------------------------------------------------------------------------------- /testdata/server/private.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgV6TxmAbktth68Wyt 3 | D6Y/djYH0Le5mKaEYfI6jKx6BN2hRANCAAS9v5kZ/AlVFHrLQxSlGaytMu/+m7BK 4 | Relh3taHclxVR2xetWpWOy3mQ598EI9CBbjU3pnG37rhpxl6bPyTkNol 5 | -----END PRIVATE KEY----- 6 | -------------------------------------------------------------------------------- /testdata/server/public.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIBjzCCATagAwIBAgIRAKjf8EWCMOjfWyxTImFAU7swCgYIKoZIzj0EAwIwEjEQ 3 | MA4GA1UEChMHQWNtZSBDbzAeFw0yMjAyMTgwNDM5MzJaFw0yMzAyMTgwNDM5MzJa 4 | MBIxEDAOBgNVBAoTB0FjbWUgQ28wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAS9 5 | v5kZ/AlVFHrLQxSlGaytMu/+m7BKRelh3taHclxVR2xetWpWOy3mQ598EI9CBbjU 6 | 3pnG37rhpxl6bPyTkNolo20wazAOBgNVHQ8BAf8EBAMCAoQwEwYDVR0lBAwwCgYI 7 | KwYBBQUHAwEwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUQuUaBss4v/tS44VR 8 | 879SmkeeQjMwFAYDVR0RBA0wC4IJbG9jYWxob3N0MAoGCCqGSM49BAMCA0cAMEQC 9 | IGz0AI1X7Rmq14IVFHEodhGzDHKrd4+NlECMxQomh8XpAiBiNA08ikT/JSAlBcKz 10 | nFG8Oceb28m7h/noPoD6Y2aRHQ== 11 | -----END CERTIFICATE----- 12 | --------------------------------------------------------------------------------