├── .github └── workflows │ └── package.yml ├── .gitignore ├── LICENSE ├── README.md ├── README_en.md ├── lang ├── en_us.yml └── zh_cn.yml ├── mcdreforged.plugin.json ├── quick_backup_multi ├── __init__.py ├── config.py ├── constant.py └── utils.py ├── requirements.txt ├── snapshot.png └── snapshot_en.png /.github/workflows/package.yml: -------------------------------------------------------------------------------- 1 | name: CI for MCDR Plugin 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | jobs: 8 | package: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v3 13 | - name: Setup python 14 | uses: actions/setup-python@v4 15 | with: 16 | python-version: 3.9 17 | 18 | - uses: actions/cache@v3 19 | with: 20 | path: ~/.cache/pip 21 | key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} 22 | restore-keys: | 23 | ${{ runner.os }}-pip- 24 | 25 | - name: Install dependencies 26 | run: | 27 | python -m pip install --upgrade pip 28 | pip install -r requirements.txt 29 | 30 | - name: Pack Plugin 31 | run: | 32 | python -m mcdreforged pack -o ./package 33 | 34 | - uses: actions/upload-artifact@v3 35 | with: 36 | name: QuickBackupM distribution for ${{ github.sha }} 37 | path: package/ 38 | 39 | - name: Publish distribution to release 40 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') 41 | uses: softprops/action-gh-release@v1 42 | with: 43 | files: package/*.mcdr 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | /release/ 3 | /utils/ 4 | /venv/ 5 | *.mcdr 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QuickBackupM 2 | 3 | > [!NOTE] 4 | > QuickBackupM 已进入维护模式,只进行 bug 修复,不再增加新功能 5 | > 6 | > 可以去看看 [Prime Backup](https://github.com/TISUnion/PrimeBackup) 插件,这是 QuickBackupM 的接替者, 7 | > 是一套更为先进完善的备份解决方案,也是 QuickBackupM 的上位替代 8 | 9 | [English](https://github.com/TISUnion/QuickBackupM/blob/master/README_en.md) 10 | 11 | 一个支持多槽位的快速备份&回档插件 12 | 13 | `master` 分支为中文版,`english` 分支为英文版 14 | 15 | 需要 `v2.0.1` 以上的 [MCDReforged](https://github.com/Fallen-Breath/MCDReforged) 16 | 17 | ![snapshot](https://raw.githubusercontent.com/TISUnion/QuickBackupM/master/snapshot.png) 18 | 19 | 备份的存档将会存放至 qb_multi 文件夹中,文件目录格式如下: 20 | ``` 21 | mcd_root/ 22 | server.py 23 | 24 | server/ 25 | world/ 26 | 27 | qb_multi/ 28 | slot1/ 29 | info.json 30 | world/ 31 | 32 | slot2/ 33 | ... 34 | ... 35 | 36 | overwrite/ 37 | info.txt 38 | world/ 39 | ``` 40 | 41 | ## 命令格式说明 42 | 43 | `!!qb` 显示帮助信息 44 | 45 | `!!qb make []` 创建一个储存至槽位 `1` 的备份,并将后移已有槽位。`` 为可选存档注释 46 | 47 | `!!qb back []` 回档为槽位 `` 的存档。 48 | 49 | `!!qb del ` 删除槽位 `` 的存档。默认为槽位 1 50 | 51 | `!!qb rename ` 修改槽位 `` 的注释,即重命名这一槽位 52 | 53 | `!!qb confirm` 在执行 `back` 后使用,再次确认是否进行回档 54 | 55 | `!!qb abort` 在任何时候键入此指令可中断回档 56 | 57 | `!!qb list` 显示各槽位的存档信息 58 | 59 | `!!qb reload` 重新加载配置文件 60 | 61 | 当 `` 未被指定时默认选择槽位 `1` 62 | 63 | ## 配置文件选项说明 64 | 65 | 配置文件为 `config/QuickBackupM.json`。它会在第一次运行时自动生成 66 | 67 | ### slots 68 | 69 | 默认值: 70 | 71 | ``` 72 | "slots": [ 73 | { 74 | "delete_protection": 0 75 | }, 76 | { 77 | "delete_protection": 0 78 | }, 79 | { 80 | "delete_protection": 0 81 | }, 82 | { 83 | "delete_protection": 10800 84 | }, 85 | { 86 | "delete_protection": 259200 87 | } 88 | ] 89 | ``` 90 | 91 | 每个槽位被保护不被覆盖的秒数。设置为 `0` 则表示不保护 92 | 93 | 该列表的长度也决定了槽位的数量 94 | 95 | 在默认值中,一共有 5 个槽位,其中前三个槽位未设置保护时间,第四个槽位会被保护三个小时(3 * 60 * 60 秒),第五个槽位会被保护三天 96 | 97 | 请保证保护时间是随着槽位序号单调不下降的,也就是第 n 给个槽位的保护时间不能大于第 n + 1 个槽位的保护时间,否则可能有未定义的行为 98 | 99 | 由旧的 QuickBackupM 插件创建的备份不支持这个特性 100 | 101 | ### size_display 102 | 103 | 默认值: `true` 104 | 105 | 查看备份列表是否显示占用空间 106 | 107 | ### turn_off_auto_save 108 | 109 | 默认值: `true` 110 | 111 | 是否在备份时临时关闭自动保存 112 | 113 | ### enable_copy_file_range 114 | 115 | 默认值: `false` 116 | 117 | 使用 `os.copy_file_range` 进行文件的复制 118 | 119 | 在某些文件系统中,它会使用基于写时复制(copy-on-write)的 reflink 技术,从而极大地提升复制速度 120 | 121 | 需求: 122 | 123 | - Linux 平台 124 | - Python >= 3.8 125 | - 选项 `backup_format` 为 `plain` 126 | 127 | ### concurrent_copy_workers 128 | 129 | 默认值:`0` 130 | 131 | 参考值:`0`, `2`, `4` 132 | 133 | 复制文件时的并行度,当其值为 `n` 时,QBM 将使用 `n` 线程并行复制文件 134 | 135 | 当使用 SSD 或其他高 IO 性能的存储设备时,开启并行复制可以有效提升复制的速度,但 CPU、磁盘负载也会显著增加 136 | 137 | 设为 `0` 以关闭并行复制 138 | 139 | 需求: 140 | 141 | - 选项 `backup_format` 为 `plain` 142 | 143 | ### ignored_files 144 | 145 | 默认值: 146 | 147 | ``` 148 | "ignored_files": [ 149 | "session.lock" 150 | ] 151 | ``` 152 | 153 | 在备份时忽略的文件名列表,默认仅包含 `session.lock` 以解决 `session.lock` 被服务端占用导致备份失败的问题 154 | 155 | 若文件名字符串以 `*` 开头,则将忽略以指定字符串结尾的文件,如 `*.test` 表示忽略所有以 `.test` 结尾的文件,如 `a.test` 156 | 157 | 若文件名字符串以 `*` 结尾,则将忽略以指定字符串开头的文件,如 `temp*` 表示忽略所有以 `temp` 开头的文件,如 `tempfile` 158 | 159 | ### saved_world_keywords 160 | 161 | 默认值: 162 | 163 | ``` 164 | "saved_world_keywords": [ 165 | "Saved the game", 166 | "Saved the world" 167 | ] 168 | ``` 169 | 170 | 用于识别服务端已保存完毕存档的关键词 171 | 172 | 如果服务器的输出与任何一个关键词相符,则认为存档已保存完毕,随后插件将开始复制存档文件 173 | 174 | ### backup_path 175 | 176 | 默认值: `./qb_multi` 177 | 178 | 备份储存的路径 179 | 180 | ### server_path 181 | 182 | 默认值:`./server` 183 | 184 | 服务端文件夹的路径。`./server` 即为 MCDR 的默认服务端文件夹路径 185 | 186 | ### overwrite_backup_folder 187 | 188 | 默认值: `overwrite` 189 | 190 | 被覆盖的存档的备份位置,在配置文件均为默认值的情况下路径为 `./qb_multi/overwrite` 191 | 192 | ### world_names 193 | 194 | 默认值: 195 | 196 | ``` 197 | "world_names": [ 198 | "world" 199 | ] 200 | ``` 201 | 202 | 需要备份的世界文件夹列表,原版服务端只会有一个世界,在默认值基础上填上世界文件夹的名字即可 203 | 204 | 对于非原版服务端如水桶、水龙头服务端,会有三个世界文件夹,此时可填写: 205 | 206 | ``` 207 | "world_names": [ 208 | "world", 209 | "world_nether", 210 | "world_the_end" 211 | ] 212 | ``` 213 | 214 | 如果指定的世界名指向了一个符号链接文件, 则该链接文件指向的最终实际世界文件夹,以及中途所有解引用出的符号链接文件都会被备份: 215 | 216 | ```sh 217 | mcd_root/ 218 | server.py 219 | 220 | server/ 221 | world -> target_world # world 是一个当前指向 target_world 文件夹的符号链接 222 | target_world/ 223 | other_world/ 224 | 225 | qb_multi/ 226 | slot1/ 227 | info.json 228 | world -> target_world # 符号链接复制到了备份槽中 229 | target_world/ # 符号链接当前指向的世界一起复制到了备份槽中 230 | ... 231 | ``` 232 | 233 | 执行 `!!qb back` 时,会从备份槽中指定世界名对应的符号链接开始,将所有符号链接以及最终实际的世界文件夹恢复至服务端的对应位置。这表示如果后续服务端的符号链接更改了指向的世界,回档时将恢复到备份时保存的世界,且不同世界的内容不会互相覆盖 234 | 235 | ### backup_format 236 | 237 | 备份的储存格式 238 | 239 | | 值 | 含义 | 240 | |----------|---------------------------------------------------------------------------| 241 | | `plain` | 直接复制文件夹/文件来储存。默认值,这同时也是 v1.8 以前版本的 QBM 唯一支持的储存格式 | 242 | | `tar` | 使用 tar 格式直接打包储存至 `backup.tar` 文件中。推荐使用,可有效减少文件的数量,但无法方便地访问备份里面的文件 | 243 | | `tar_gz` | 使用 tar.gz 格式压缩打包储存至 `backup.tar.gz` 文件中。能减小备份体积,但是备份/回档的耗时将显著增加。支持自定义压缩等级 | 244 | | `tar_xz` | 使用 tar.xz 格式压缩打包储存至 `backup.tar.xz` 文件中。能最大化地减小备份体积,但是备份/回档的耗时将极大增加 | 245 | 246 | 槽位的备份模式会储存在槽位的 `info.json` 中,并在回档时读取,因此的不同的槽位可以有着不同的储存格式。 247 | 若其值不存在,QBM 会假定这个槽位是由旧版 QBM 创建的,并使用默认值 `plain` 248 | 249 | 若配置文件中的 `backup_format` 非法,则会使用默认值 `plain` 250 | 251 | ### compress_level 252 | 253 | 一个 1 ~ 9 的整数,代表在 `backup_format` 选项为 `tar_gz` 时,使用的压缩等级。 254 | 等级越高,压缩率相对越高,耗时也越高 255 | 256 | 默认值:1 257 | 258 | ### minimum_permission_level 259 | 260 | 默认值: 261 | 262 | ``` 263 | "minimum_permission_level": { 264 | "make": 1, 265 | "back": 2, 266 | "del": 2, 267 | "rename": 2, 268 | "confirm": 1, 269 | "abort": 1, 270 | "reload": 2, 271 | "list": 0, 272 | } 273 | ``` 274 | 275 | 一个字典,代表使用不同类型指令需要权限等级。数值含义见[此处](https://mcdreforged.readthedocs.io/zh_CN/latest/permission.html) 276 | 277 | 把所有数值设置成 `0` 以让所有人均可操作 278 | -------------------------------------------------------------------------------- /README_en.md: -------------------------------------------------------------------------------- 1 | # QuickBackupM 2 | 3 | > [!NOTE] 4 | > QuickBackupM has entered maintenance mode, where only bug fixes will be provided and no new features will be added 5 | > 6 | > You may want to check out the [Prime Backup](https://github.com/TISUnion/PrimeBackup) plugin, which is the successor to QuickBackupM. 7 | > It is a more advanced and comprehensive backup solution, serving as an upgrade over QuickBackupM 8 | 9 | [中文](https://github.com/TISUnion/QuickBackupM/blob/master/README.md) 10 | 11 | A plugin for multi slot back up / restore your world 12 | 13 | The `master` branch is the Chinese version and the `english` branch is the English version 14 | 15 | Needs `v2.0.1`+ [MCDReforged](https://github.com/Fallen-Breath/MCDReforged) 16 | 17 | ![snapshot](https://raw.githubusercontent.com/TISUnion/QuickBackupM/master/snapshot_en.png) 18 | 19 | The backup worlds will be store in folder qb_multi like below: 20 | ``` 21 | mcd_root/ 22 | server.py 23 | 24 | server/ 25 | world/ 26 | 27 | qb_multi/ 28 | slot1/ 29 | info.json 30 | world/ 31 | 32 | slot2/ 33 | ... 34 | ... 35 | 36 | overwrite/ 37 | info.txt 38 | world/ 39 | ``` 40 | 41 | ## Command 42 | 43 | `!!qb` help message 44 | 45 | `!!qb make []` Make a backup to slot 1, and shift the slots behind. `` is an optional comment message 46 | 47 | `!!qb back []` Restore the world to slot 1. When `` parameter is set it will restore to slot `` 48 | 49 | `!!qb del ` Delete the world in slot `` 50 | 51 | `!!qb rename ` Modify the comment of slot ``, aka rename the slot 52 | 53 | `!!qb confirm` Use after execute `back` to confirm restore execution 54 | 55 | `!!qb abort` Abort backup restoring 56 | 57 | `!!qb list` Display slot information 58 | 59 | `!!qb reload` Reload the config file 60 | 61 | When `` is not set the default value is `1` 62 | 63 | ## Config file explaination 64 | 65 | The config file is `config/QuickBackupM.json`. It will automatically generate at the first run 66 | 67 | ### slots 68 | 69 | Default: 70 | 71 | ``` 72 | "slots": [ 73 | { 74 | "delete_protection": 0 75 | }, 76 | { 77 | "delete_protection": 0 78 | }, 79 | { 80 | "delete_protection": 0 81 | }, 82 | { 83 | "delete_protection": 10800 84 | }, 85 | { 86 | "delete_protection": 259200 87 | } 88 | ] 89 | ``` 90 | 91 | The amount of seconds for each slots to be protected from overwriting. Set it to `0` to disable protection 92 | 93 | The size of this list also determines the amount of backup slot 94 | 95 | With the default value, there are 5 slots in total, among which the first 3 slots have no protection, the 4th slot will be protected for 3 hours (3 * 60 * 60 seconds), and the 5th slot will be protected for 3 days 96 | 97 | Please ensure that the protection time does not decrease with the slot number, that is, the protection time of the nth slot cannot be greater than the protection time of the n + 1th slot, otherwise there may be undefined behavior 98 | 99 | Backups created by older QuickBackupM plugin don't support this feature 100 | 101 | ### size_display 102 | 103 | Default: `true` 104 | 105 | Whether the occupied space is displayed when viewing the backup list 106 | 107 | ### turn_off_auto_save 108 | 109 | Default: `true` 110 | 111 | If turn off auto save when making backup or not 112 | 113 | ### enable_copy_file_range 114 | 115 | Default: `false` 116 | 117 | Use `os.copy_file_range` for file copying 118 | 119 | In some file system, it will use the copy-on-write based reflink technique to greatly accelerate the copy speed 120 | 121 | Requirements: 122 | 123 | - Linux 124 | - Python >= 3.8 125 | - Option `backup_format` set to `plain` 126 | 127 | ### concurrent_copy_workers 128 | 129 | Default: `0` 130 | 131 | Recommended values: `0`, `2`, `4` 132 | 133 | Set the concurrency level for file copying. If the value is `n`, QBM will use `n` threads to copy files concurrently 134 | 135 | When using SSDs or other high-performance I/O devices, enabling concurrent copying can boost speed significantly, but it also increases CPU and disk load 136 | 137 | Set it to `0` to turn off concurrent copying 138 | 139 | Requirements: 140 | 141 | - Option `backup_format` set to `plain` 142 | 143 | ### ignored_files 144 | 145 | Default: 146 | 147 | ``` 148 | "ignored_files": [ 149 | "session.lock" 150 | ] 151 | ``` 152 | 153 | A list of file names to be ignored during backup. It contains `session.lock` by default to solve the backup failure problem caused by `session.lock` being occupied by the server 154 | 155 | If the name string starts with `*`, then it will ignore files with name ending with specific string, e.g. `*.test` makes all files ends with `.test` be ignored, like `a.test` 156 | 157 | If the name string ends with `*`, then it will ignore files with name starting with specific string, e.g. `temp*` makes all files starts with `temp` be ignored, like `tempfile` 158 | 159 | ### saved_world_keywords 160 | 161 | Default: 162 | 163 | ``` 164 | "saved_world_keywords": [ 165 | "Saved the game", 166 | "Saved the world" 167 | ] 168 | ``` 169 | 170 | Keywords for the plugin to consider if the server has saved the world 171 | 172 | It is considered that the world has been saved if any keyword string equals to the server output, then the plugin will start copying the world files 173 | 174 | ### backup_path 175 | 176 | Default: `./qb_multi` 177 | 178 | The backup root path 179 | 180 | ### server_path 181 | 182 | Default: `./server` 183 | 184 | The folder path of the server. `./server` is the default server path for MCDR 185 | 186 | ### overwrite_backup_folder 187 | 188 | Default: `overwrite` 189 | 190 | The backup position of the overwritten world. With default config file the path will be `./qb_multi/overwrite` 191 | 192 | ### WorldNames 193 | 194 | Default: 195 | 196 | ``` 197 | "world_names": [ 198 | "world" 199 | ] 200 | ``` 201 | 202 | A list of world folder that you want to back up. For vanilla there should be only 1 folder. 203 | 204 | For not vanilla server like bukkit or paper, there are 3 folders. You can write like: 205 | 206 | ``` 207 | "world_names": [ 208 | "world", 209 | "world_nether", 210 | "world_the_end" 211 | ] 212 | ``` 213 | 214 | If the world name specified points to a symlink file, all dereferenced symbolic links and the final actual world folder will be backed up: 215 | 216 | ```sh 217 | mcd_root/ 218 | server.py 219 | 220 | server/ 221 | world -> target_world # world is a symlink currently pointing to target_world 222 | target_world/ 223 | other_world/ 224 | 225 | qb_multi/ 226 | slot1/ 227 | info.json 228 | world -> target_world # Symlink copied to backup slot 229 | target_world/ # The current linked world is copied along with symlink 230 | ... 231 | ``` 232 | 233 | Doing `!!qb back` will restore everything from world name symlink to the final actual world folder in the slot to the server's corresponding place. This implies that if the symlink has changed its target world, the server will be restored to the world when making backup, and the world before restoring will not be overwritten 234 | 235 | ### backup_format 236 | 237 | The format of the stored backup 238 | 239 | | Value | Explanation | 240 | |----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 241 | | `plain` | Store the backup directly via file / directory copy. The default value, the only supported format in QBM < v1.8 | 242 | | `tar` | Pack the files into `backup.tar` in tar format. Recommend value. It can significantly reduce the file amount. Although you cannot access files inside the backup easily | 243 | | `tar_gz` | Compress the files into `backup.tar.gz` in tar.gz format. The backup size will be smaller, but the time cost in backup / restore will increase | 244 | | `tar_xz` | Compress the files into `backup.tar.xz` in tar.xz format. The backup size will be much smaller, but the time cost in backup / restore will greatly increase | 245 | 246 | The backup format of the slot will be stored inside the `info.json` of the slot, and will be read when restoring, so you can have different backup formats in your slots. 247 | If the backup format value doesn't exist, QBM will assume that it's a backup created from old QBM, and use the default `plain` format 248 | 249 | If the `backup_format` value is invalid in the config file, the default value `plain` will be used 250 | 251 | ### compress_level 252 | 253 | An integer in range 1 ~ 9, representing the compress level when config `backup_format` is set to `tar_gz`. 254 | The higher the level is, the higher the compression rate will be, and the longer the time it will take. 255 | 256 | Default: 1 257 | 258 | ### minimum_permission_level 259 | 260 | Default: 261 | 262 | ``` 263 | "minimum_permission_level": { 264 | "make": 1, 265 | "back": 2, 266 | "del": 2, 267 | "rename": 2, 268 | "confirm": 1, 269 | "abort": 1, 270 | "reload": 2, 271 | "list": 0, 272 | } 273 | ``` 274 | 275 | A dict for minimum permission level requirement. For the meaning of these value check [this](https://mcdreforged.readthedocs.io/en/latest/permission.html) 276 | 277 | Set everything to `0` so everyone can use every command 278 | -------------------------------------------------------------------------------- /lang/en_us.yml: -------------------------------------------------------------------------------- 1 | quick_backup_multi: 2 | help_message: | 3 | ------ {1} v{2} ------ 4 | A plugin that supports multi slots world §abackup§r and backup §crestore§r 5 | §d[Format]§r 6 | §7{0}§r Display help message 7 | §7{0} make §e[]§r Make a §abackup§r to slot §61§r. §e§r is an optional comment message 8 | §7{0} back §6[]§r §cRestore§r the world to slot §6§r. Default: slot §61§r 9 | §7{0} del §6§r §cDelete§r the world in slot §6§r 10 | §7{0} rename §6§r §e§r §bModify§r the comment of slot §6§r, aka rename the slot 11 | §7{0} confirm§r Use after execute back to confirm §crestore§r execution 12 | §7{0} abort§r Abort backup §crestoring§r 13 | §7{0} list§r Display slot information 14 | §7{0} reload§r Reload config file 15 | When §6§r is not set the default value is §61§r 16 | 17 | second: "{0} seconds" 18 | minute: "{0} minutes" 19 | hour: "{0} hours" 20 | day: "{0} days" 21 | slot_info: "Date: {0}; Comment: {1}" 22 | empty_comment: §7empty§r 23 | unknown_slot: Slot format wrong, it should be a number between [{0}, {1}] 24 | empty_slot: Slot §6{}§r is empty 25 | 26 | lock.warning: Executing "{0}", please don't spam 27 | operations: 28 | delete: §aDeleting slot§r 29 | create: §aBacking up§r 30 | restore: §cRestoring§r 31 | rename: §9Renaming§r 32 | 33 | delete_backup: 34 | success: Slot §6{0}§r delete §asuccess§r 35 | fail: "Slot §6{0}§r delete §4failed§r, error code {1}" 36 | 37 | rename_backup: 38 | success: Slot §6{0}§r rename §asuccess§r 39 | fail: "Slot §6{0}§r rename §4failed§r, error code {1}" 40 | 41 | create_backup: 42 | start: §aBacking up§r, please wait 43 | abort.plugin_unload: Plugin unloaded, §aback up§r aborted! 44 | abort.no_slot: Available slot not found, §aback up§r aborted! 45 | success: §aBack up§r successfully, time elapsed §6{0}§rs 46 | fail: §aBack up§r unsuccessfully, error code {0} 47 | 48 | restore_backup: 49 | echo_action: Gonna restore the world to slot §6{0}§r, {1} 50 | confirm_hint: Use §7{0} confirm§r to confirm §crestore§r 51 | confirm_hover: Click to confirm 52 | abort_hint: §7{0} abort§r to abort 53 | abort_hover: Click to abort 54 | 55 | confirm_restore.nothing_to_confirm: Nothing to confirm 56 | 57 | do_restore: 58 | countdown.intro: §cRestore§r after 10 second 59 | countdown.text: "{0} second later the world will be §crestored§r to slot §6{1}§r, {2}" 60 | countdown.hover: Click to ABORT restore! 61 | abort: §cRestore§r aborted! 62 | 63 | trigger_abort.abort: Operation terminated! 64 | 65 | list_backup: 66 | title: §d[Slot Information]§r 67 | slot: 68 | header: "[Slot §6{}§r]" 69 | protection: "Slot protection: {0}" 70 | restore: Click to restore to slot §6{0}§r 71 | delete: Click to delete slot §6{0}§r 72 | total_space: "Total space consumed: §a{0}§r" 73 | 74 | print_help: 75 | hotbar: §d[Hotbar]§r 76 | click_to_create: 77 | text: ">>> §aClick me to create a backup§r <<<" 78 | hover: Remember to write the comment 79 | command: "{0} make I'm a comment" 80 | click_to_restore: 81 | text: ">>> §cClick me to restore to the latest backup§r <<<" 82 | hover: as known as the first slot 83 | command: "{0} back" 84 | 85 | unknown_command: 86 | text: Unknown command, input §7{0}§r for more information 87 | hover: Click to see help 88 | command: 89 | permission_denied: Permission Denied 90 | wrong_slot: Wrong Slot Number 91 | register: 92 | summory_help: §aback up§r/§crestore§r your world with §6{0}§r slots 93 | show_help: Click to see help 94 | -------------------------------------------------------------------------------- /lang/zh_cn.yml: -------------------------------------------------------------------------------- 1 | quick_backup_multi: 2 | help_message: | 3 | ------ {1} v{2} ------ 4 | 一个支持多槽位的快速§a备份§r&§c回档§r插件 5 | §d【格式说明】§r 6 | §7{0}§r 显示帮助信息 7 | §7{0} make §e[]§r 创建一个储存至槽位§61§r的§a备份§r。§e§r为可选注释 8 | §7{0} back §6[]§r §c回档§r为槽位§6§r的存档。默认为槽位§61§r 9 | §7{0} del §6§r §c删除§r槽位§6§r的存档 10 | §7{0} rename §6§r §e§r §b修改§r槽位§6§r的注释,即重命名这一槽位 11 | §7{0} confirm§r 再次确认是否进行§c回档§r 12 | §7{0} abort§r 在任何时候键入此指令可中断§c回档§r 13 | §7{0} list§r 显示各槽位的存档信息 14 | §7{0} reload§r 重新加载配置文件 15 | 当§6§r未被指定时默认选择槽位§61§r 16 | 17 | second: "{0}秒" 18 | minute: "{0}分钟" 19 | hour: "{0}小时" 20 | day: "{0}天" 21 | slot_info: "日期: {0}; 注释: {1}" 22 | empty_comment: §7空§r 23 | unknown_slot: 槽位输入错误,应输入一个位于[{0}, {1}]的数字 24 | empty_slot: 槽位输入错误,槽位§6{0}§r为空 25 | 26 | lock.warning: 正在{0}中,请等待操作执行完成 27 | operations: 28 | delete: §a删除槽位§r 29 | create: §a备份§r 30 | restore: §c回档§r 31 | rename: §9重命名§r 32 | 33 | delete_backup: 34 | success: 删除槽位§6{0}§r§a完成§r 35 | fail: "删除槽位§6{0}§r§4失败§r,错误代码: {1}" 36 | 37 | rename_backup: 38 | success: 重命名槽位§6{0}§r§a完成§r 39 | fail: "重命名槽位§6{0}§r§4失败§r,错误代码: {1}" 40 | 41 | create_backup: 42 | start: §a备份§r中...请稍等 43 | abort.plugin_unload: 插件重载,§a备份§r中断! 44 | abort.no_slot: 未找到可用槽位,§a备份§r中断! 45 | success: §a备份§r完成,耗时§6{0}§r秒 46 | fail: §a备份§r失败,错误代码{0} 47 | 48 | restore_backup: 49 | echo_action: 准备将存档恢复至槽位§6{0}§r,{1} 50 | confirm_hint: 使用§7{0} confirm§r 确认§c回档§r 51 | confirm_hover: 点击确认 52 | abort_hint: §7{0} abort§r 取消 53 | abort_hover: 点击取消 54 | 55 | confirm_restore.nothing_to_confirm: 没有什么需要确认的 56 | 57 | do_restore: 58 | countdown.intro: 10秒后关闭服务器§c回档§r 59 | countdown.text: 还有{0}秒,将§c回档§r为槽位§6{1}§r,{2} 60 | countdown.hover: 点击终止回档! 61 | abort: §c回档§r被中断! 62 | 63 | trigger_abort.abort: 终止操作! 64 | 65 | list_backup: 66 | title: §d【槽位信息】§r 67 | slot: 68 | header: "[槽位§6{0}§r]" 69 | protection: "存档保护时长: {0}" 70 | restore: 点击回档至槽位§6{0}§r 71 | delete: 点击删除槽位§6{0}§r 72 | total_space: "备份总占用空间: §a{0}§r" 73 | 74 | print_help: 75 | hotbar: §d【快捷操作】§r 76 | click_to_create: 77 | text: ">>> §a点我创建一个备份§r <<<" 78 | hover: 记得修改注释 79 | command: "{0} make 我是一个注释" 80 | click_to_restore: 81 | text: ">>> §c点我回档至最近的备份§r <<<" 82 | hover: 也就是回档至第一个槽位 83 | command: "{0} back" 84 | 85 | unknown_command: 86 | text: 参数错误!请输入§7{0}§r以获取插件信息 87 | hover: 点击查看帮助 88 | command: 89 | permission_denied: 权限不足 90 | wrong_slot: 槽位输入错误 91 | register: 92 | summory_help: §a备份§r/§c回档§r,§6{0}§r槽位 93 | show_help: 点击查看帮助信息 94 | -------------------------------------------------------------------------------- /mcdreforged.plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "quick_backup_multi", 3 | "version": "1.10.1", 4 | "name": "Quick Backup Multi", 5 | "description": { 6 | "en_us": "A backup / restore plugin, with multiple backup slot", 7 | "zh_cn": "多槽位备份/回档插件" 8 | }, 9 | "author": [ 10 | "Fallen_Breath" 11 | ], 12 | "link": "https://github.com/TISUnion/QuickBackupM", 13 | "dependencies": { 14 | "mcdreforged": ">=2.1.2" 15 | }, 16 | 17 | "archive_name": "QuickBackupM-v{version}", 18 | "resources": [ 19 | "lang", 20 | "LICENSE" 21 | ] 22 | } -------------------------------------------------------------------------------- /quick_backup_multi/__init__.py: -------------------------------------------------------------------------------- 1 | import functools 2 | import json 3 | import os 4 | import re 5 | import shutil 6 | import tarfile 7 | import time 8 | from concurrent.futures import ThreadPoolExecutor 9 | from enum import Enum, auto 10 | from threading import Lock, Event 11 | from typing import Optional, Any, Callable, Tuple, NamedTuple 12 | 13 | from mcdreforged.api.all import * 14 | 15 | from quick_backup_multi import utils 16 | from quick_backup_multi.config import Configuration 17 | from quick_backup_multi.constant import BACKUP_DONE_EVENT, Prefix, RESTORE_DONE_EVENT, TRIGGER_BACKUP_EVENT, \ 18 | CONFIG_FILE, TRIGGER_RESTORE_EVENT 19 | 20 | config: Configuration 21 | server_inst: PluginServerInterface 22 | HelpMessage: RTextBase 23 | slot_selected = None # type: Optional[int] 24 | abort_restore = Event() 25 | game_saved = Event() 26 | plugin_unloaded = False 27 | operation_lock = Lock() 28 | operation_name = RText('?') 29 | 30 | 31 | class CopyWorldIntent(Enum): 32 | backup = auto() 33 | restore = auto() 34 | 35 | 36 | class BackupFormat(Enum): 37 | class Item(NamedTuple): 38 | suffix: str 39 | supports_compress_level: bool 40 | 41 | plain = Item('', False) 42 | tar = Item('.tar', False) 43 | tar_gz = Item('.tar.gz', True) 44 | tar_xz = Item('.tar.xz', False) 45 | 46 | @classmethod 47 | def of(cls, mode: str) -> 'BackupFormat': 48 | try: 49 | return cls[mode] 50 | except KeyError: 51 | return cls.plain 52 | 53 | def get_file_name(self, base_name: str) -> str: 54 | return base_name + self.value.suffix 55 | 56 | def supports_compress_level(self) -> bool: 57 | return self.value.supports_compress_level 58 | 59 | 60 | def get_backup_format() -> BackupFormat: 61 | return BackupFormat.of(config.backup_format) 62 | 63 | 64 | def tr(translation_key: str, *args) -> RTextMCDRTranslation: 65 | return ServerInterface.get_instance().rtr('quick_backup_multi.{}'.format(translation_key), *args) 66 | 67 | 68 | def print_message(source: CommandSource, msg, tell=True, prefix='[QBM] '): 69 | msg = RTextList(prefix, msg) 70 | if source.is_player and not tell: 71 | source.get_server().say(msg) 72 | else: 73 | source.reply(msg) 74 | 75 | 76 | def command_run(message: Any, text: Any, command: str) -> RTextBase: 77 | fancy_text = message.copy() if isinstance(message, RTextBase) else RText(message) 78 | return fancy_text.set_hover_text(text).set_click_event(RAction.run_command, command) 79 | 80 | 81 | def get_backup_file_name(backup_format: BackupFormat): 82 | if backup_format == BackupFormat.plain: 83 | raise ValueError('plain mode is not supported') 84 | return backup_format.get_file_name('backup') 85 | 86 | 87 | COPY_FILE_RANGE_SUPPORTED = hasattr(os, 'copy_file_range') 88 | COPY_FILE_RANGE_BUFFER_SIZE = 2 ** 30 # 1GiB 89 | 90 | 91 | def copy_file_fast(src_path: str, dst_path: str) -> str: 92 | """ 93 | A ``shutil.copy2`` alternative that uses ``os.copy_file_range`` whenever possible 94 | 95 | ``os.copy_file_range`` may support copy-on-write, which is much faster than regular copy 96 | """ 97 | if not COPY_FILE_RANGE_SUPPORTED or not config.enable_copy_file_range: 98 | return shutil.copy2(src_path, dst_path) 99 | 100 | if os.path.isdir(dst_path): # ref: shutil.copy2 101 | dst_path = os.path.join(dst_path, os.path.basename(src_path)) 102 | 103 | try: 104 | with open(src_path, 'rb') as f_src, open(dst_path, 'wb+') as f_dst: 105 | while os.copy_file_range(f_src.fileno(), f_dst.fileno(), COPY_FILE_RANGE_BUFFER_SIZE): 106 | pass 107 | except Exception as e: 108 | server_inst.logger.warning('copy_file_range {} -> {} failed ({}), retrying with shutil.copy'.format(src_path, dst_path, e)) 109 | shutil.copy(src_path, dst_path) 110 | 111 | shutil.copystat(src_path, dst_path) # ref: shutil.copy2 112 | return dst_path 113 | 114 | 115 | def copy_tree_fast(src_path: str, dst_path: str, ignore=None, copy_function: Callable[[str, str], object] = shutil.copy2): 116 | def do_copy(src: str, dst: str): 117 | try: 118 | copy_function(src, dst) 119 | except Exception as e: 120 | server_inst.logger.error('Failed to copy file from {} to {}: {}'.format(src, dst, e)) 121 | raise 122 | 123 | if config.concurrent_copy_workers <= 0: 124 | shutil.copytree(src_path, dst_path, ignore=ignore, copy_function=do_copy) 125 | return 126 | 127 | futures = [] 128 | with ThreadPoolExecutor(max_workers=config.concurrent_copy_workers, thread_name_prefix='QBM_FileCopier') as pool: 129 | def concurrent_copy(src: str, dst: str): 130 | futures.append(pool.submit(do_copy, src, dst)) 131 | 132 | shutil.copytree(src_path, dst_path, ignore=ignore, copy_function=concurrent_copy) 133 | 134 | for future in futures: 135 | future.result() 136 | 137 | 138 | def copy_worlds(src: str, dst: str, intent: CopyWorldIntent, *, backup_format: Optional[BackupFormat] = None): 139 | if backup_format is None: 140 | backup_format = get_backup_format() 141 | if backup_format == BackupFormat.plain: 142 | for world in config.world_names: 143 | src_path = os.path.join(src, world) 144 | dst_path = os.path.join(dst, world) 145 | 146 | while os.path.islink(src_path): 147 | server_inst.logger.info('copying {} -> {} (symbolic link)'.format(src_path, dst_path)) 148 | dst_dir = os.path.dirname(dst_path) 149 | if not os.path.isdir(dst_dir): 150 | os.makedirs(dst_dir) 151 | link_path = os.readlink(src_path) 152 | os.symlink(link_path, dst_path) 153 | src_path = link_path if os.path.isabs(link_path) else os.path.normpath(os.path.join(os.path.dirname(src_path), link_path)) 154 | dst_path = os.path.join(dst, os.path.relpath(src_path, src)) 155 | 156 | server_inst.logger.info('copying {} -> {}'.format(src_path, dst_path)) 157 | if os.path.isdir(src_path): 158 | copy_tree_fast(src_path, dst_path, ignore=lambda path, files: set(filter(config.is_file_ignored, files)), copy_function=copy_file_fast) 159 | elif os.path.isfile(src_path): 160 | dst_dir = os.path.dirname(dst_path) 161 | if not os.path.isdir(dst_dir): 162 | os.makedirs(dst_dir) 163 | copy_file_fast(src_path, dst_path) 164 | else: 165 | server_inst.logger.warning('{} does not exist while copying ({} -> {})'.format(src_path, src_path, dst_path)) 166 | elif backup_format in [BackupFormat.tar, BackupFormat.tar_gz, BackupFormat.tar_xz]: 167 | if intent == CopyWorldIntent.restore: 168 | tar_path = os.path.join(src, get_backup_file_name(backup_format)) 169 | server_inst.logger.info('extracting {} -> {}'.format(tar_path, dst)) 170 | with tarfile.open(tar_path, 'r:*') as backup_file: 171 | backup_file.extractall(path=dst) 172 | else: # backup 173 | if backup_format == BackupFormat.tar_gz: 174 | tar_mode = 'w:gz' 175 | elif backup_format == BackupFormat.tar_xz: 176 | tar_mode = 'w:xz' 177 | else: 178 | tar_mode = 'w' 179 | if not os.path.isdir(dst): 180 | os.makedirs(dst) 181 | tar_path = os.path.join(dst, get_backup_file_name(backup_format)) 182 | kwargs = {} 183 | if backup_format.supports_compress_level() and 1 <= config.compress_level <= 9: 184 | kwargs['compresslevel'] = config.compress_level 185 | with tarfile.open(tar_path, tar_mode, **kwargs) as backup_file: 186 | for world in config.world_names: 187 | src_path = os.path.join(src, world) 188 | server_inst.logger.info('storing {} -> {}'.format(src_path, tar_path)) 189 | if os.path.exists(src_path): 190 | def tar_filter(info: tarfile.TarInfo) -> Optional[tarfile.TarInfo]: 191 | ignored = config.is_file_ignored(os.path.basename(info.name)) 192 | server_inst.logger.debug('tar_filter ignore {}: {}'.format(info.name, ignored)) 193 | return None if ignored else info 194 | 195 | backup_file.add(src_path, arcname=world, filter=tar_filter) 196 | else: 197 | server_inst.logger.warning('{} does not exist while storing'.format(src_path)) 198 | else: 199 | server_inst.logger.error('Unknown backup format {}'.format(backup_format.name)) 200 | 201 | 202 | def remove_worlds(folder: str): 203 | for world in config.world_names: 204 | target_path = os.path.join(folder, world) 205 | 206 | while os.path.islink(target_path): 207 | link_path = os.readlink(target_path) 208 | os.unlink(target_path) 209 | target_path = link_path if os.path.isabs(link_path) else os.path.normpath(os.path.join(os.path.dirname(target_path), link_path)) 210 | 211 | if os.path.isdir(target_path): 212 | shutil.rmtree(target_path) 213 | elif os.path.isfile(target_path): 214 | os.remove(target_path) 215 | else: 216 | ServerInterface.get_instance().logger.warning('[QBM] {} does not exist while removing'.format(target_path)) 217 | 218 | 219 | def get_slot_count(): 220 | return len(config.slots) 221 | 222 | 223 | def get_slot_path(slot: int): 224 | return os.path.join(config.backup_path, 'slot{}'.format(slot)) 225 | 226 | 227 | def get_slot_info(slot: int): 228 | """ 229 | :param int slot: the index of the slot 230 | :return: the slot info 231 | :rtype: dict or None 232 | """ 233 | try: 234 | with open(os.path.join(get_slot_path(slot), 'info.json'), encoding='utf8') as f: 235 | info = json.load(f) 236 | except: 237 | info = None 238 | return info 239 | 240 | 241 | def format_time(): 242 | return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) 243 | 244 | 245 | def format_protection_time(time_length: float) -> RTextBase: 246 | if time_length < 60: 247 | return tr('second', time_length) 248 | elif time_length < 60 * 60: 249 | return tr('minute', round(time_length / 60, 2)) 250 | elif time_length < 24 * 60 * 60: 251 | return tr('hour', round(time_length / 60 / 60, 2)) 252 | else: 253 | return tr('day', round(time_length / 60 / 60 / 24, 2)) 254 | 255 | 256 | def format_slot_info(info_dict: Optional[dict] = None) -> Optional[RTextBase]: 257 | if isinstance(info_dict, dict): 258 | info = info_dict 259 | else: 260 | return None 261 | 262 | if info is None: 263 | return None 264 | return tr('slot_info', info['time'], info.get('comment', tr('empty_comment'))) 265 | 266 | 267 | def touch_backup_folder(): 268 | def mkdir(path: str): 269 | if os.path.isfile(path): 270 | os.remove(path) 271 | if not os.path.isdir(path): 272 | os.mkdir(path) 273 | 274 | mkdir(config.backup_path) 275 | for i in range(get_slot_count()): 276 | mkdir(get_slot_path(i + 1)) 277 | 278 | 279 | def slot_check(source: CommandSource, slot: int) -> Optional[Tuple[int, dict]]: 280 | if not 1 <= slot <= get_slot_count(): 281 | print_message(source, tr('unknown_slot', 1, get_slot_count())) 282 | return None 283 | 284 | slot_info = get_slot_info(slot) 285 | if slot_info is None: 286 | print_message(source, tr('empty_slot', slot)) 287 | return None 288 | return slot, slot_info 289 | 290 | 291 | def create_slot_info(comment: Optional[str]) -> dict: 292 | slot_info = { 293 | 'time': format_time(), 294 | 'time_stamp': time.time(), 295 | 'backup_format': get_backup_format().name, 296 | } 297 | if comment is not None: 298 | slot_info['comment'] = comment 299 | return slot_info 300 | 301 | 302 | def write_slot_info(slot_path: str, slot_info: dict): 303 | with open(os.path.join(slot_path, 'info.json'), 'w', encoding='utf8') as f: 304 | json.dump(slot_info, f, indent=4, ensure_ascii=False) 305 | 306 | 307 | def single_op(name: RTextBase): 308 | def wrapper(func: Callable): 309 | @functools.wraps(func) 310 | def wrap(source: CommandSource, *args, **kwargs): 311 | global operation_name 312 | acq = operation_lock.acquire(blocking=False) 313 | if acq: 314 | operation_name = name 315 | try: 316 | func(source, *args, **kwargs) 317 | finally: 318 | operation_lock.release() 319 | else: 320 | print_message(source, tr('lock.warning', operation_name)) 321 | return wrap 322 | return wrapper 323 | 324 | 325 | @new_thread('QBM_Delete') 326 | @single_op(tr('operations.delete')) 327 | def delete_backup(source: CommandSource, slot: int): 328 | if slot_check(source, slot) is None: 329 | return 330 | try: 331 | shutil.rmtree(get_slot_path(slot)) 332 | except Exception as e: 333 | print_message(source, tr('delete_backup.fail', slot, e), tell=False) 334 | else: 335 | print_message(source, tr('delete_backup.success', slot), tell=False) 336 | 337 | 338 | @new_thread('QBM_Rename') 339 | @single_op(tr('operations.rename')) 340 | def rename_backup(source: CommandSource, slot: int, comment: str): 341 | ret = slot_check(source, slot) 342 | if ret is None: 343 | return 344 | try: 345 | slot, slot_info = ret 346 | slot_info['comment'] = comment 347 | write_slot_info(get_slot_path(slot), slot_info) 348 | except Exception as e: 349 | print_message(source, tr('rename_backup.fail', slot, e), tell=False) 350 | else: 351 | print_message(source, tr('rename_backup.success', slot), tell=False) 352 | 353 | 354 | def clean_up_slot_1(): 355 | """ 356 | try to clean up slot 1 for backup 357 | :rtype: bool 358 | """ 359 | slots = [] 360 | empty_slot_idx = None 361 | max_available_idx = None 362 | for i in range(get_slot_count()): 363 | slot_idx = i + 1 364 | slot = get_slot_info(slot_idx) 365 | slots.append(slot) 366 | if slot is None: 367 | if empty_slot_idx is None: 368 | empty_slot_idx = slot_idx 369 | else: 370 | time_stamp = slot.get('time_stamp', None) 371 | if time_stamp is not None: 372 | slot_config_data = config.slots[slot_idx - 1] 373 | if time.time() - time_stamp > slot_config_data.delete_protection: 374 | max_available_idx = slot_idx 375 | else: 376 | # old format, treat it as available 377 | max_available_idx = slot_idx 378 | 379 | if empty_slot_idx is not None: 380 | target_slot_idx = empty_slot_idx 381 | else: 382 | target_slot_idx = max_available_idx 383 | 384 | if target_slot_idx is not None: 385 | slot_info = get_slot_info(target_slot_idx) 386 | folder = get_slot_path(target_slot_idx) 387 | server_inst.logger.info('deleting slot {} ({}) to provide spaces for the incoming backup'.format(target_slot_idx, format_slot_info(info_dict=slot_info))) 388 | 389 | if os.path.isdir(folder): 390 | shutil.rmtree(folder) 391 | for i in reversed(range(1, target_slot_idx)): # n-1, n-2, ..., 1 392 | os.rename(get_slot_path(i), get_slot_path(i + 1)) 393 | os.mkdir(get_slot_path(1)) 394 | 395 | return True 396 | else: 397 | return False 398 | 399 | 400 | @new_thread('QBM_Create') 401 | def create_backup(source: CommandSource, comment: Optional[str]): 402 | _create_backup(source, comment) 403 | 404 | 405 | @single_op(tr('operations.create')) 406 | def _create_backup(source: CommandSource, comment: Optional[str]): 407 | try: 408 | print_message(source, tr('create_backup.start'), tell=False) 409 | start_time = time.time() 410 | touch_backup_folder() 411 | 412 | # start backup, trigger the /save-all command 413 | with utils.time_cost() as cost_save_wait: 414 | game_saved.clear() 415 | if config.turn_off_auto_save: 416 | source.get_server().execute('save-off') 417 | source.get_server().execute('save-all flush') 418 | 419 | game_saved.wait() 420 | if plugin_unloaded: 421 | print_message(source, tr('create_backup.abort.plugin_unload'), tell=False) 422 | return 423 | 424 | # clean up slot 1 for backup 425 | with utils.time_cost() as cost_cleanup: 426 | if not clean_up_slot_1(): 427 | print_message(source, tr('create_backup.abort.no_slot'), tell=False) 428 | return 429 | 430 | # copy worlds to the target backup slot 431 | with utils.time_cost() as cost_copy_worlds: 432 | slot_path = get_slot_path(1) 433 | copy_worlds(config.server_path, slot_path, CopyWorldIntent.backup) 434 | 435 | # create info.json 436 | slot_info = create_slot_info(comment) 437 | write_slot_info(slot_path, slot_info) 438 | 439 | # done 440 | end_time = time.time() 441 | server_inst.logger.info('Time costs: save wait {}s, clean up {}s, copy worlds {}s'.format( 442 | round(cost_save_wait, 2), round(cost_cleanup, 2), round(cost_copy_worlds, 2) 443 | )) 444 | print_message(source, tr('create_backup.success', round(end_time - start_time, 1)), tell=False) 445 | print_message(source, format_slot_info(info_dict=slot_info), tell=False) 446 | except Exception as e: 447 | source.get_server().logger.exception('[QBM] Error creating backup') 448 | print_message(source, tr('create_backup.fail', e), tell=False) 449 | else: 450 | source.get_server().dispatch_event(BACKUP_DONE_EVENT, (source, slot_info)) 451 | finally: 452 | if config.turn_off_auto_save: 453 | source.get_server().execute('save-on') 454 | 455 | 456 | def restore_backup(source: CommandSource, slot: int): 457 | ret = slot_check(source, slot) 458 | if ret is None: 459 | return 460 | else: 461 | slot, slot_info = ret 462 | global slot_selected 463 | slot_selected = slot 464 | abort_restore.clear() 465 | print_message(source, tr('restore_backup.echo_action', slot, format_slot_info(info_dict=slot_info)), tell=False) 466 | print_message( 467 | source, 468 | command_run(tr('restore_backup.confirm_hint', Prefix), tr('restore_backup.confirm_hover'), '{0} confirm'.format(Prefix)) 469 | + ', ' 470 | + command_run(tr('restore_backup.abort_hint', Prefix), tr('restore_backup.abort_hover'), '{0} abort'.format(Prefix)) 471 | , tell=False 472 | ) 473 | 474 | 475 | @new_thread('QBM_Restore') 476 | def confirm_restore(source: CommandSource): 477 | global slot_selected 478 | if slot_selected is None: 479 | print_message(source, tr('confirm_restore.nothing_to_confirm'), tell=False) 480 | else: 481 | slot = slot_selected 482 | slot_selected = None 483 | _do_restore_backup(source, slot) 484 | 485 | 486 | @single_op(tr('operations.restore')) 487 | def _do_restore_backup(source: CommandSource, slot: int): 488 | try: 489 | print_message(source, tr('do_restore.countdown.intro'), tell=False) 490 | slot_info = get_slot_info(slot) 491 | for countdown in range(1, 10): 492 | print_message(source, command_run( 493 | tr('do_restore.countdown.text', 10 - countdown, slot, format_slot_info(info_dict=slot_info)), 494 | tr('do_restore.countdown.hover'), 495 | '{} abort'.format(Prefix) 496 | ), tell=False) 497 | 498 | if abort_restore.wait(1): 499 | print_message(source, tr('do_restore.abort'), tell=False) 500 | return 501 | 502 | source.get_server().stop() 503 | server_inst.logger.info('Wait for server to stop') 504 | source.get_server().wait_for_start() 505 | 506 | server_inst.logger.info('Backup current world to avoid idiot') 507 | overwrite_backup_path = os.path.join(config.backup_path, config.overwrite_backup_folder) 508 | if os.path.exists(overwrite_backup_path): 509 | shutil.rmtree(overwrite_backup_path) 510 | copy_worlds(config.server_path, overwrite_backup_path, CopyWorldIntent.backup) 511 | with open(os.path.join(overwrite_backup_path, 'info.txt'), 'w') as f: 512 | f.write('Overwrite time: {}\n'.format(format_time())) 513 | f.write('Confirmed by: {}'.format(source)) 514 | 515 | slot_folder = get_slot_path(slot) 516 | server_inst.logger.info('Deleting world') 517 | remove_worlds(config.server_path) 518 | backup_format = BackupFormat.of(slot_info.get('backup_format')) 519 | server_inst.logger.info('Restore backup {} (mode={})'.format(slot_folder, backup_format.name)) 520 | copy_worlds(slot_folder, config.server_path, CopyWorldIntent.restore, backup_format=backup_format) 521 | 522 | source.get_server().start() 523 | except: 524 | server_inst.logger.exception('Fail to restore backup to slot {}, triggered by {}'.format(slot, source)) 525 | else: 526 | source.get_server().dispatch_event(RESTORE_DONE_EVENT, (source, slot, slot_info)) # async dispatch 527 | 528 | 529 | def trigger_abort(source: CommandSource): 530 | global slot_selected 531 | abort_restore.set() 532 | slot_selected = None 533 | print_message(source, tr('trigger_abort.abort'), tell=False) 534 | 535 | 536 | @new_thread('QBM_List') 537 | def list_backup(source: CommandSource, size_display: bool = None): 538 | if size_display is None: 539 | size_display = config.size_display 540 | 541 | def get_dir_size(dir_: str): 542 | size = 0 543 | for root, dirs, files in os.walk(dir_): 544 | size += sum([os.path.getsize(os.path.join(root, name)) for name in files]) 545 | return size 546 | 547 | def format_dir_size(size: int): 548 | if size < 2 ** 30: 549 | return '{} MiB'.format(round(size / 2 ** 20, 2)) 550 | else: 551 | return '{} GiB'.format(round(size / 2 ** 30, 2)) 552 | 553 | print_message(source, tr('list_backup.title'), prefix='') 554 | total_backup_size = 0 555 | for i in range(get_slot_count()): 556 | slot_idx = i + 1 557 | slot_info = get_slot_info(slot_idx) 558 | formatted_slot_info = format_slot_info(slot_info) 559 | if size_display: 560 | dir_size = get_dir_size(get_slot_path(slot_idx)) 561 | else: 562 | dir_size = 0 563 | total_backup_size += dir_size 564 | # noinspection PyTypeChecker 565 | text = RTextList( 566 | RText(tr('list_backup.slot.header', slot_idx)).h(tr('list_backup.slot.protection', format_protection_time(config.slots[slot_idx - 1].delete_protection))), 567 | ' ' 568 | ) 569 | if formatted_slot_info is not None: 570 | text += RTextList( 571 | RText('[▷] ', color=RColor.green).h(tr('list_backup.slot.restore', slot_idx)).c(RAction.run_command, f'{Prefix} back {slot_idx}'), 572 | RText('[×] ', color=RColor.red).h(tr('list_backup.slot.delete', slot_idx)).c(RAction.suggest_command, f'{Prefix} del {slot_idx}') 573 | ) 574 | if size_display: 575 | text += RText(format_dir_size(dir_size) + ' ', RColor.dark_green).h(BackupFormat.of(slot_info.get('backup_format')).name) 576 | text += formatted_slot_info 577 | print_message(source, text, prefix='') 578 | if size_display: 579 | print_message(source, tr('list_backup.total_space', format_dir_size(total_backup_size)), prefix='') 580 | 581 | 582 | @new_thread('QBM_Help') 583 | def print_help_message(source: CommandSource): 584 | if source.is_player: 585 | source.reply('') 586 | with source.preferred_language_context(): 587 | for line in HelpMessage.to_plain_text().splitlines(): 588 | prefix = re.search(r'(?<=§7){}[\w ]*(?=§)'.format(Prefix), line) 589 | if prefix is not None: 590 | print_message(source, RText(line).set_click_event(RAction.suggest_command, prefix.group()), prefix='') 591 | else: 592 | print_message(source, line, prefix='') 593 | list_backup(source, size_display=False).join() 594 | print_message( 595 | source, 596 | tr('print_help.hotbar') + 597 | '\n' + 598 | RText(tr('print_help.click_to_create.text')) 599 | .h(tr('print_help.click_to_create.hover')) 600 | .c(RAction.suggest_command, tr('print_help.click_to_create.command', Prefix).to_plain_text()) + 601 | '\n' + 602 | RText(tr('print_help.click_to_restore.text')) 603 | .h(tr('print_help.click_to_restore.hover')) 604 | .c(RAction.suggest_command, tr('print_help.click_to_restore.command', Prefix).to_plain_text()), 605 | prefix='' 606 | ) 607 | 608 | 609 | def on_info(server: PluginServerInterface, info: Info): 610 | if not info.is_user: 611 | if info.content in config.saved_world_keywords: 612 | game_saved.set() 613 | 614 | 615 | def print_unknown_argument_message(source: CommandSource, error: UnknownArgument): 616 | print_message(source, command_run( 617 | tr('unknown_command.text', Prefix), 618 | tr('unknown_command.hover'), 619 | Prefix 620 | )) 621 | 622 | 623 | def register_command(server: PluginServerInterface): 624 | def get_literal_node(literal): 625 | lvl = config.minimum_permission_level.get(literal, 0) 626 | return Literal(literal).requires(lambda src: src.has_permission(lvl)).on_error(RequirementNotMet, lambda src: src.reply(tr('command.permission_denied')), handled=True) 627 | 628 | def get_slot_node(): 629 | return Integer('slot').requires(lambda src, ctx: 1 <= ctx['slot'] <= get_slot_count()).on_error(RequirementNotMet, lambda src: src.reply(tr('command.wrong_slot')), handled=True) 630 | 631 | server.register_command( 632 | Literal(Prefix). 633 | runs(print_help_message). 634 | on_error(UnknownArgument, print_unknown_argument_message, handled=True). 635 | then( 636 | get_literal_node('make'). 637 | runs(lambda src: create_backup(src, None)). 638 | then(GreedyText('comment').runs(lambda src, ctx: create_backup(src, ctx['comment']))) 639 | ). 640 | then( 641 | get_literal_node('back'). 642 | runs(lambda src: restore_backup(src, 1)). 643 | then(get_slot_node().runs(lambda src, ctx: restore_backup(src, ctx['slot']))) 644 | ). 645 | then( 646 | get_literal_node('del'). 647 | then(get_slot_node().runs(lambda src, ctx: delete_backup(src, ctx['slot']))) 648 | ). 649 | then( 650 | get_literal_node('rename'). 651 | then( 652 | get_slot_node(). 653 | then(GreedyText('comment').runs(lambda src, ctx: rename_backup(src, ctx['slot'], ctx['comment']))) 654 | ) 655 | ). 656 | then(get_literal_node('confirm').runs(confirm_restore)). 657 | then(get_literal_node('abort').runs(trigger_abort)). 658 | then(get_literal_node('list').runs(lambda src: list_backup(src))). 659 | then(get_literal_node('reload').runs(lambda src: load_config(src.get_server(), src))) 660 | ) 661 | 662 | 663 | def load_config(server: ServerInterface, source: CommandSource or None = None): 664 | global config 665 | config = server_inst.load_config_simple(CONFIG_FILE, target_class=Configuration, in_data_folder=False, source_to_reply=source) 666 | last = 0 667 | for i in range(get_slot_count()): 668 | this = config.slots[i].delete_protection 669 | if this < 0: 670 | server.logger.warning('Slot {} has a negative delete protection time'.format(i + 1)) 671 | elif not last <= this: 672 | server.logger.warning('Slot {} has a delete protection time smaller than the former one'.format(i + 1)) 673 | last = this 674 | 675 | 676 | def register_event_listeners(server: PluginServerInterface): 677 | server.register_event_listener(TRIGGER_BACKUP_EVENT, lambda svr, source, comment: _create_backup(source, comment)) 678 | server.register_event_listener(TRIGGER_RESTORE_EVENT, lambda svr, source, slot: _do_restore_backup(source, slot)) 679 | 680 | 681 | def on_load(server: PluginServerInterface, old): 682 | global operation_lock, operation_name, HelpMessage, server_inst 683 | server_inst = server 684 | if hasattr(old, 'operation_lock') and type(old.operation_lock) == type(operation_lock): 685 | operation_lock = old.operation_lock 686 | operation_name = getattr(old, 'operation_name', operation_name) 687 | 688 | meta = server.get_self_metadata() 689 | HelpMessage = tr('help_message', Prefix, meta.name, meta.version) 690 | load_config(server) 691 | register_command(server) 692 | register_event_listeners(server) 693 | server.register_help_message(Prefix, command_run(tr('register.summory_help', get_slot_count()), tr('register.show_help'), Prefix)) 694 | 695 | 696 | def on_unload(server: PluginServerInterface): 697 | global plugin_unloaded 698 | plugin_unloaded = True 699 | abort_restore.set() # plugin unload is a kind of "abort" too 700 | game_saved.set() # interrupt the potential waiting on game saved 701 | -------------------------------------------------------------------------------- /quick_backup_multi/config.py: -------------------------------------------------------------------------------- 1 | from typing import List, Dict 2 | 3 | from mcdreforged.api.utils.serializer import Serializable 4 | 5 | 6 | class SlotInfo(Serializable): 7 | delete_protection: int = 0 8 | 9 | 10 | class Configuration(Serializable): 11 | size_display: bool = True 12 | turn_off_auto_save: bool = True 13 | enable_copy_file_range: bool = False 14 | concurrent_copy_workers: int = 0 15 | ignored_files: List[str] = [ 16 | 'session.lock' 17 | ] 18 | saved_world_keywords: List[str] = [ 19 | 'Saved the game', # 1.13+ 20 | 'Saved the world', # 1.12- 21 | ] 22 | backup_path: str = './qb_multi' 23 | server_path: str = './server' 24 | overwrite_backup_folder: str = 'overwrite' 25 | world_names: List[str] = [ 26 | 'world' 27 | ] 28 | backup_format: str = 'plain' # "plain", "tar", "tar_gz", "tar_xz" 29 | compress_level: int = 1 # in range [1, 9] 30 | # 0:guest 1:user 2:helper 3:admin 4:owner 31 | minimum_permission_level: Dict[str, int] = { 32 | 'make': 1, 33 | 'back': 2, 34 | 'del': 2, 35 | 'rename': 2, 36 | 'confirm': 1, 37 | 'abort': 1, 38 | 'reload': 2, 39 | 'list': 0, 40 | } 41 | slots: List[SlotInfo] = [ 42 | SlotInfo(delete_protection=0), # no protection 43 | SlotInfo(delete_protection=0), # no protection 44 | SlotInfo(delete_protection=0), # no protection 45 | SlotInfo(delete_protection=3 * 60 * 60), # 3 hours 46 | SlotInfo(delete_protection=3 * 24 * 60 * 60), # 3 days 47 | ] 48 | 49 | def is_file_ignored(self, file_name: str) -> bool: 50 | for item in self.ignored_files: 51 | if len(item) > 0: 52 | if item[0] == '*' and file_name.endswith(item[1:]): 53 | return True 54 | if item[-1] == '*' and file_name.startswith(item[:-1]): 55 | return True 56 | if file_name == item: 57 | return True 58 | return False 59 | 60 | 61 | if __name__ == '__main__': 62 | config = Configuration().get_default() 63 | config.ignored_files = ['*.abc', 'test', 'no*'] 64 | assert config.is_file_ignored('.abc') 65 | assert config.is_file_ignored('1.abc') 66 | assert config.is_file_ignored('abc') is False 67 | assert config.is_file_ignored('test') 68 | assert config.is_file_ignored('1test') is False 69 | assert config.is_file_ignored('notest') 70 | assert config.is_file_ignored('no') 71 | -------------------------------------------------------------------------------- /quick_backup_multi/constant.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from mcdreforged.api.event import LiteralEvent 4 | 5 | PLUGIN_ID = 'quick_backup_multi' 6 | Prefix = '!!qb' 7 | CONFIG_FILE = os.path.join('config', 'QuickBackupM.json') 8 | 9 | BACKUP_DONE_EVENT = LiteralEvent('{}.backup_done'.format(PLUGIN_ID)) # -> source, slot_info 10 | RESTORE_DONE_EVENT = LiteralEvent('{}.restore_done'.format(PLUGIN_ID)) # -> source, slot, slot_info 11 | TRIGGER_BACKUP_EVENT = LiteralEvent('{}.trigger_backup'.format(PLUGIN_ID)) # <- source, comment 12 | TRIGGER_RESTORE_EVENT = LiteralEvent('{}.trigger_restore'.format(PLUGIN_ID)) # <- source, slot 13 | 14 | 15 | ''' 16 | mcdr_root/ 17 | server/ 18 | world/ 19 | qb_multi/ 20 | slot1/ 21 | info.json 22 | world/ 23 | slot2/ 24 | ... 25 | ... 26 | overwrite/ 27 | info.txt 28 | world/ 29 | ''' 30 | -------------------------------------------------------------------------------- /quick_backup_multi/utils.py: -------------------------------------------------------------------------------- 1 | import contextlib 2 | import time 3 | 4 | 5 | class TimeCostHolder: 6 | cost: float = float() 7 | 8 | def __repr__(self): 9 | return repr(self.cost) 10 | 11 | def str(self): 12 | return str(self.cost) 13 | 14 | def __round__(self, *args, **kwargs): 15 | return self.cost.__round__(*args, **kwargs) 16 | 17 | 18 | @contextlib.contextmanager 19 | def time_cost(): 20 | holder = TimeCostHolder() 21 | start = time.time() 22 | yield holder 23 | holder.cost = time.time() - start 24 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | mcdreforged>=2.0.1 2 | -------------------------------------------------------------------------------- /snapshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TISUnion/QuickBackupM/c2d6f28dc64ce8f8b9c63c158501e5bac31acaf2/snapshot.png -------------------------------------------------------------------------------- /snapshot_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TISUnion/QuickBackupM/c2d6f28dc64ce8f8b9c63c158501e5bac31acaf2/snapshot_en.png --------------------------------------------------------------------------------