├── .github └── workflows │ └── release.yaml ├── .gitignore ├── .goreleaser.yaml ├── BUILD.md ├── LICENSE ├── README.md ├── build.bat ├── build.sh ├── build_cli.bat ├── buzhash.go ├── config.go ├── config.json.example ├── go.mod ├── go.sum ├── icon.go ├── mail.go ├── main.go ├── nop_snapshot.go ├── pbsapi.go ├── pxar.go ├── stub_locking.go ├── win_locking.go └── win_snapshot.go /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | # Copy from: https://github.com/safedep/vet/blob/main/.github/workflows/goreleaser.yml 2 | name: Release Automation 3 | 4 | on: 5 | push: 6 | tags: 7 | - "*" # triggers only if push new tag version, like `0.8.4` or else 8 | 9 | concurrency: ci-release-automation 10 | 11 | permissions: 12 | contents: read 13 | 14 | env: 15 | OSX_CROSS_TOOLCHAIN_REPOSITORY: https://github.com/abhisek/osxcross 16 | OSX_CROSS_MACOS_SDK_VERSION: "12.3" 17 | 18 | jobs: 19 | goreleaser: 20 | timeout-minutes: 60 21 | outputs: 22 | hashes: ${{ steps.hash.outputs.hashes }} 23 | permissions: 24 | contents: write # for goreleaser/goreleaser-action to create a GitHub release 25 | packages: write # for goreleaser/goreleaser-action to publish docker images 26 | runs-on: ubuntu-latest 27 | env: 28 | # Required for buildx on docker 19.x 29 | DOCKER_CLI_EXPERIMENTAL: enabled 30 | steps: 31 | - name: Checkout 32 | uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 33 | with: 34 | fetch-depth: 0 35 | - uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2 36 | - uses: docker/setup-buildx-action@8c0edbc76e98fa90f69d9a2c020dcb50019dc325 # v2 37 | - name: Set up Go 38 | uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0 39 | with: 40 | go-version: 1.21 41 | check-latest: true 42 | - name: ghcr-login 43 | uses: docker/login-action@dd4fa0671be5250ee6f50aedf4cb05514abda2c7 # v1 44 | with: 45 | registry: ghcr.io 46 | username: ${{ github.repository_owner }} 47 | password: ${{ secrets.GITHUB_TOKEN }} 48 | 49 | - name: Install OSX Cross Compiler Build Tools 50 | run: sudo apt-get install -y -qq clang gcc g++ zlib1g-dev libmpc-dev libmpfr-dev libgmp-dev cmake libxml2-dev libssl-dev xz-utils 51 | 52 | - name: Install windows cross compile gcc 53 | run: sudo apt-get install -y -qq gcc-mingw-w64 libayatana-appindicator3-dev 54 | 55 | - name: Setup OSX Cross Compiler Tool Chain Environment 56 | run: | 57 | echo "OSXCROSS_DIR=$(dirname $GITHUB_WORKSPACE)/osxcross" >> $GITHUB_ENV 58 | 59 | - name: Clone OSX Cross Compiler Tool Chain 60 | run: git clone $OSX_CROSS_TOOLCHAIN_REPOSITORY $OSXCROSS_DIR 61 | 62 | - name: Setup Cache for OSX Cross Compiler Tool Chain 63 | id: osxcross-cache 64 | uses: actions/cache@v3 65 | with: 66 | key: ${{ runner.os }}-osxcross-${{ env.OSX_CROSS_MACOS_SDK_VERSION }} 67 | path: | 68 | ${{ env.OSXCROSS_DIR }}/target/bin 69 | 70 | - name: Build OSX Cross Compiler Tool Chain 71 | if: steps.osxcross-cache.outputs.cache-hit != 'true' 72 | run: | 73 | cd $OSXCROSS_DIR 74 | SDK_VERSION=$OSX_CROSS_MACOS_SDK_VERSION UNATTENDED=yes ./build.sh 75 | 76 | - name: Add OSX Cross Compiler Tool Chain to Path 77 | run: | 78 | echo "$OSXCROSS_DIR/target/bin" >> $GITHUB_PATH 79 | 80 | - name: Run GoReleaser 81 | id: run-goreleaser 82 | uses: goreleaser/goreleaser-action@8f67e590f2d095516493f017008adc464e63adb1 # v4.1.0 83 | with: 84 | version: latest 85 | args: release --clean 86 | env: 87 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 88 | 89 | - name: Generate subject 90 | id: hash 91 | env: 92 | ARTIFACTS: "${{ steps.run-goreleaser.outputs.artifacts }}" 93 | run: | 94 | set -euo pipefail 95 | checksum_file=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Checksum") | .path') 96 | echo "hashes=$(cat $checksum_file | base64 -w0)" >> "$GITHUB_OUTPUT" 97 | provenance: 98 | needs: [goreleaser] 99 | permissions: 100 | actions: read # To read the workflow path. 101 | id-token: write # To sign the provenance. 102 | contents: write # To add assets to a release. 103 | uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.4.0 104 | with: 105 | base64-subjects: "${{ needs.goreleaser.outputs.hashes }}" 106 | upload-assets: true 107 | private-repository: true -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | proxmoxbackupgo_cli.exe 3 | proxmoxbackupgo.exe 4 | config.json -------------------------------------------------------------------------------- /.goreleaser.yaml: -------------------------------------------------------------------------------- 1 | # This is an example .goreleaser.yml file with some sensible defaults. 2 | # Make sure to check the documentation at https://goreleaser.com 3 | 4 | # The lines below are called `modelines`. See `:help modeline` 5 | # Feel free to remove those if you don't want/need to use them. 6 | # yaml-language-server: $schema=https://goreleaser.com/static/schema.json 7 | # vim: set ts=2 sw=2 tw=0 fo=cnqoj 8 | 9 | version: 1 10 | 11 | before: 12 | hooks: 13 | # You may remove this if you don't use go modules. 14 | - go mod tidy 15 | # you may remove this if you don't need go generate 16 | - go generate ./... 17 | 18 | env: 19 | - CGO_ENABLED=1 20 | 21 | builds: 22 | - id: windows 23 | goos: 24 | - windows 25 | goarch: 26 | - amd64 27 | env: 28 | - CC=x86_64-w64-mingw32-gcc 29 | - CXX=x86_64-w64-mingw32-g++ 30 | 31 | - id: linux 32 | binary: vet 33 | goos: 34 | - linux 35 | goarch: 36 | - amd64 37 | env: 38 | - CC=x86_64-linux-gnu-gcc 39 | - CXX=x86_64-linux-gnu-g++ 40 | 41 | - id: darwin-amd64 42 | binary: vet 43 | goos: 44 | - darwin 45 | goarch: 46 | - amd64 47 | env: 48 | - CC=o64-clang 49 | - CXX=o64-clang++ 50 | 51 | - id: darwin-arm64 52 | binary: vet 53 | goos: 54 | - darwin 55 | goarch: 56 | - arm64 57 | env: 58 | - CC=o64-clang 59 | - CXX=o64-clang++ 60 | 61 | release: 62 | # for prerelease it doesn't build and distribute 63 | prerelease: auto 64 | 65 | universal_binaries: 66 | - replace: true 67 | 68 | archives: 69 | - format: tar.gz 70 | name_template: >- 71 | {{ .ProjectName }}_ 72 | {{- title .Os }}_ 73 | {{- if eq .Arch "amd64" }}x86_64 74 | {{- else if eq .Arch "386" }}i386 75 | {{- else }}{{ .Arch }}{{ end }} 76 | {{- if .Arm }}v{{ .Arm }}{{ end }} 77 | format_overrides: 78 | - goos: windows 79 | format: zip 80 | checksum: 81 | name_template: checksums.txt 82 | snapshot: 83 | name_template: "{{ incpatch .Version }}-next" 84 | changelog: 85 | sort: asc 86 | filters: 87 | exclude: 88 | - '^docs:' 89 | - '^test:' 90 | 91 | # The lines beneath this are called `modelines`. See `:help modeline` 92 | # Feel free to remove those if you don't want/use them. 93 | # yaml-language-server: $schema=https://goreleaser.com/static/schema.json 94 | # vim: set ts=2 sw=2 tw=0 fo=cnqoj 95 | -------------------------------------------------------------------------------- /BUILD.md: -------------------------------------------------------------------------------- 1 | # Build Instructions 2 | 3 | ## Install Chocolatey 4 | 5 | - put this in an elevated "admin" powershell 6 | 7 | ```powershell 8 | Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) 9 | ``` 10 | 11 | - close the powershell 12 | - open an elevated "admin" powershell or cmd 13 | 14 | ```powershell 15 | choco install go 16 | choco install mingw 17 | ``` 18 | 19 | ## Test go / gcc 20 | 21 | - close the powershell 22 | - open a non elevated powershell or cmd 23 | 24 | ```cmd 25 | C:\>go version 26 | go version go1.22.2 windows/amd64 27 | 28 | C:\>gcc --version 29 | gcc (x86_64-posix-seh-rev0, Built by MinGW-Builds project) 13.2.0 30 | Copyright (C) 2023 Free Software Foundation, Inc. 31 | This is free software; see the source for copying conditions. There is NO 32 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 33 | ``` 34 | 35 | ## Build 36 | 37 | - open a non elevated powershell or cmd 38 | 39 | GUI version 40 | 41 | ```cmd 42 | build.bat 43 | ``` 44 | 45 | CLI version 46 | 47 | ```cmd 48 | build_cli.bat 49 | ``` 50 | -------------------------------------------------------------------------------- /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 | This software implements a proxmox backup client software for windows, backup only as of now 2 | Works on linux too especially for development 3 | 4 | The software is still alpha quality and i take no responsability for any kind of damage or data loss even of source files. 5 | 6 | Contributions are welcome especially 7 | 8 | 1. GUI with tray icon to show backup progress and backup taking place 9 | 2. Encryption support 10 | 3. A GUI way of configuring it and maybe create a json job file similiar freefilesync does 11 | 4. Async upload / compress and multicore upload + compression of chunks 12 | 5. Proxmox side patch to add another kind of entry to pxar format with Windows security descriptors in it 13 | 6. Support for windows symlinks 14 | 7. Anything interesting you can come up with :) 15 | 16 | Usage 17 | ===== 18 | 19 | A typical command would look like: 20 | ```shell 21 | proxmoxbackupgo.exe -baseurl "https://yourpbshost:8007" -certfingerprint pbsfingerprint -authid "user@realm!apiid" -secret "apisecret" -backupdir "C:\path\to\backup" -datastore "datastorename" 22 | 23 | ``` 24 | 25 | 26 | ``` 27 | proxmoxbackupgo.exe 28 | -authid string 29 | Authentication ID (PBS Api token) 30 | -secret string 31 | Secret for authentication 32 | -backupdir string 33 | Backup source directory, must not be symlink 34 | -baseurl string 35 | Base URL for the proxmox backup server, example: https://192.168.1.10:8007 36 | -certfingerprint string 37 | Certificate fingerprint for SSL connection, example: ea:7d:06:f9... 38 | -datastore string 39 | Datastore name 40 | -namespace string 41 | Namespace (optional) 42 | -backup-id string 43 | Backup ID (optional - if not specified, the hostname is used as the default for host-type backups) 44 | -pxarout string 45 | Output PXAR archive for debug purposes (optional) 46 | -backupstream string ***NEW*** 47 | Filename for stream backup 48 | -mail-host string 49 | mail notification system: mail server host(optional) 50 | -mail-port string 51 | mail notification system: mail server port(optional) 52 | -mail-username string 53 | mail notification system: mail server username(optional) 54 | -mail-password string 55 | mail notification system: mail server password(optional) 56 | -mail-insecure bool 57 | mail notification system: allow insecure communications(optional) 58 | -mail-from string 59 | mail notification system: sender mail(optional) 60 | -mail-to string 61 | mail notification system: receiver mail(optional) 62 | 63 | -mail-subject-template string 64 | mail notification system: mail subject template(optional) 65 | -mail-body-template string 66 | mail notification system: mail body template(optional) 67 | 68 | -config string 69 | Path to JSON config file. If this flag is provided all the others will override the loaded config file 70 | 71 | ``` 72 | 73 | For JSON configuration a JSON example is provided, fill in only the needed fields. 74 | 75 | 76 | Note on mail templating: 77 | [Go's templating engine](https://pkg.go.dev/text/template) is used for mail subjects and bodies, please refer to the documentation for the syntax. 78 | The following variables are available for templating: 79 | - `.NewChunks`: number of new chunks created 80 | - `.ReusedChunks`: number of chunks reused 81 | - `.Datastore`: datastore name 82 | - `.Error`: error message if any 83 | - `.Hostname`: hostname of the machine 84 | - `.StartTime`: time the backup started 85 | - `.EndTime`: time the backup ended 86 | - `.Duration`: duration of the backup 87 | - `.FromattedDuration`: formatted duration of the backup 88 | - `.Success`: a boolean telling whether the backup was successful 89 | - `.Status`: string representation of the backup status [SUCCESS, FAILURE] 90 | 91 | Stream Backup 92 | ============= 93 | This allows backing up a stream instead of a PXAR, allows endless possibilities for example you can invoke 94 | 95 | ``` 96 | mysqldump yourdatabase | ./proxmoxbackupgo -backupstream yourdatabase.sql [other options] 97 | ``` 98 | 99 | This allows leveraging buzhash for dedup even when using tar for example, or the sql dump itself, and if someone wants to attempt it should be possible with some hack to pipe DISM command to generate WIM image to this and have full host backup 100 | 101 | Known Issues 102 | ============ 103 | 104 | Windows defender antimalware being active will slow backup down up to 25% of attainable speed 105 | 106 | There's as of now no mechanism to prevent two instances being launched at same time which will screw up VSS and backup 107 | If you using windows planning utility it should theoretically prevent two instances starting at same time when originating from same job 108 | 109 | -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | set CGO_ENABLED=1 2 | set GOOS=windows 3 | go build -ldflags -H=windowsgui -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CGO_ENABLED=1 4 | GOOS=windows 5 | CC=x86_64-w64-mingw32-gcc 6 | 7 | go build -o proxmoxbackupgo_cli.exe -------------------------------------------------------------------------------- /build_cli.bat: -------------------------------------------------------------------------------- 1 | set CGO_ENABLED=1 2 | set GOOS=windows 3 | go build -o proxmoxbackupgo_cli.exe 4 | -------------------------------------------------------------------------------- /buzhash.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math/bits" 6 | ) 7 | 8 | var buzhash_table []uint32 = []uint32{ 9 | 0x458be752, 0xc10748cc, 0xfbbcdbb8, 0x6ded5b68, 0xb10a82b5, 0x20d75648, 0xdfc5665f, 0xa8428801, 10 | 0x7ebf5191, 0x841135c7, 0x65cc53b3, 0x280a597c, 0x16f60255, 0xc78cbc3e, 0x294415f5, 0xb938d494, 11 | 0xec85c4e6, 0xb7d33edc, 0xe549b544, 0xfdeda5aa, 0x882bf287, 0x3116737c, 0x05569956, 0xe8cc1f68, 12 | 0x0806ac5e, 0x22a14443, 0x15297e10, 0x50d090e7, 0x4ba60f6f, 0xefd9f1a7, 0x5c5c885c, 0x82482f93, 13 | 0x9bfd7c64, 0x0b3e7276, 0xf2688e77, 0x8fad8abc, 0xb0509568, 0xf1ada29f, 0xa53efdfe, 0xcb2b1d00, 14 | 0xf2a9e986, 0x6463432b, 0x95094051, 0x5a223ad2, 0x9be8401b, 0x61e579cb, 0x1a556a14, 0x5840fdc2, 15 | 0x9261ddf6, 0xcde002bb, 0x52432bb0, 0xbf17373e, 0x7b7c222f, 0x2955ed16, 0x9f10ca59, 0xe840c4c9, 16 | 0xccabd806, 0x14543f34, 0x1462417a, 0x0d4a1f9c, 0x087ed925, 0xd7f8f24c, 0x7338c425, 0xcf86c8f5, 17 | 0xb19165cd, 0x9891c393, 0x325384ac, 0x0308459d, 0x86141d7e, 0xc922116a, 0xe2ffa6b6, 0x53f52aed, 18 | 0x2cd86197, 0xf5b9f498, 0xbf319c8f, 0xe0411fae, 0x977eb18c, 0xd8770976, 0x9833466a, 0xc674df7f, 19 | 0x8c297d45, 0x8ca48d26, 0xc49ed8e2, 0x7344f874, 0x556f79c7, 0x6b25eaed, 0xa03e2b42, 0xf68f66a4, 20 | 0x8e8b09a2, 0xf2e0e62a, 0x0d3a9806, 0x9729e493, 0x8c72b0fc, 0x160b94f6, 0x450e4d3d, 0x7a320e85, 21 | 0xbef8f0e1, 0x21d73653, 0x4e3d977a, 0x1e7b3929, 0x1cc6c719, 0xbe478d53, 0x8d752809, 0xe6d8c2c6, 22 | 0x275f0892, 0xc8acc273, 0x4cc21580, 0xecc4a617, 0xf5f7be70, 0xe795248a, 0x375a2fe9, 0x425570b6, 23 | 0x8898dcf8, 0xdc2d97c4, 0x0106114b, 0x364dc22f, 0x1e0cad1f, 0xbe63803c, 0x5f69fac2, 0x4d5afa6f, 24 | 0x1bc0dfb5, 0xfb273589, 0x0ea47f7b, 0x3c1c2b50, 0x21b2a932, 0x6b1223fd, 0x2fe706a8, 0xf9bd6ce2, 25 | 0xa268e64e, 0xe987f486, 0x3eacf563, 0x1ca2018c, 0x65e18228, 0x2207360a, 0x57cf1715, 0x34c37d2b, 26 | 0x1f8f3cde, 0x93b657cf, 0x31a019fd, 0xe69eb729, 0x8bca7b9b, 0x4c9d5bed, 0x277ebeaf, 0xe0d8f8ae, 27 | 0xd150821c, 0x31381871, 0xafc3f1b0, 0x927db328, 0xe95effac, 0x305a47bd, 0x426ba35b, 0x1233af3f, 28 | 0x686a5b83, 0x50e072e5, 0xd9d3bb2a, 0x8befc475, 0x487f0de6, 0xc88dff89, 0xbd664d5e, 0x971b5d18, 29 | 0x63b14847, 0xd7d3c1ce, 0x7f583cf3, 0x72cbcb09, 0xc0d0a81c, 0x7fa3429b, 0xe9158a1b, 0x225ea19a, 30 | 0xd8ca9ea3, 0xc763b282, 0xbb0c6341, 0x020b8293, 0xd4cd299d, 0x58cfa7f8, 0x91b4ee53, 0x37e4d140, 31 | 0x95ec764c, 0x30f76b06, 0x5ee68d24, 0x679c8661, 0xa41979c2, 0xf2b61284, 0x4fac1475, 0x0adb49f9, 32 | 0x19727a23, 0x15a7e374, 0xc43a18d5, 0x3fb1aa73, 0x342fc615, 0x924c0793, 0xbee2d7f0, 0x8a279de9, 33 | 0x4aa2d70c, 0xe24dd37f, 0xbe862c0b, 0x177c22c2, 0x5388e5ee, 0xcd8a7510, 0xf901b4fd, 0xdbc13dbc, 34 | 0x6c0bae5b, 0x64efe8c7, 0x48b02079, 0x80331a49, 0xca3d8ae6, 0xf3546190, 0xfed7108b, 0xc49b941b, 35 | 0x32baf4a9, 0xeb833a4a, 0x88a3f1a5, 0x3a91ce0a, 0x3cc27da1, 0x7112e684, 0x4a3096b1, 0x3794574c, 36 | 0xa3c8b6f3, 0x1d213941, 0x6e0a2e00, 0x233479f1, 0x0f4cd82f, 0x6093edd2, 0x5d7d209e, 0x464fe319, 37 | 0xd4dcac9e, 0x0db845cb, 0xfb5e4bc3, 0xe0256ce1, 0x09fb4ed1, 0x0914be1e, 0xa5bdb2c3, 0xc6eb57bb, 38 | 0x30320350, 0x3f397e91, 0xa67791bc, 0x86bc0e2c, 0xefa0a7e2, 0xe9ff7543, 0xe733612c, 0xd185897b, 39 | 0x329e5388, 0x91dd236b, 0x2ecb0d93, 0xf4d82a3d, 0x35b5c03f, 0xe4e606f0, 0x05b21843, 0x37b45964, 40 | 0x5eff22f4, 0x6027f4cc, 0x77178b3c, 0xae507131, 0x7bf7cabc, 0xf9c18d66, 0x593ade65, 0xd95ddf11, 41 | } 42 | 43 | type Chunker struct { 44 | h uint32 45 | window_size uint64 46 | chunk_size uint64 47 | chunk_size_min uint64 48 | chunk_size_max uint64 49 | _chunk_size_avg uint64 50 | _discriminator uint32 51 | break_test_mask uint32 52 | break_test_minimum uint32 53 | window []byte 54 | } 55 | 56 | func (self *Chunker) New(chunk_size_avg uint64) { 57 | avg := float64(chunk_size_avg) 58 | discriminator := uint32(avg / (-1.42888852e-7*avg + 1.33237515)) 59 | break_test_mask := uint32(chunk_size_avg*2 - 1) 60 | break_test_minimum := break_test_mask - 2 61 | 62 | self.h = 0 63 | self.window_size = 0 64 | self.chunk_size = 0 65 | self.chunk_size_min = chunk_size_avg >> 2 66 | self.chunk_size_max = chunk_size_avg << 2 67 | self._chunk_size_avg = chunk_size_avg 68 | self._discriminator = discriminator 69 | self.break_test_mask = break_test_mask 70 | self.break_test_minimum = break_test_minimum 71 | self.window = make([]byte, 64) 72 | 73 | fmt.Printf("Chunk size min is %d , max %d\n", self.chunk_size_min, self.chunk_size_max) 74 | } 75 | 76 | func (self *Chunker) Scan(data []byte) uint64 { 77 | window_len := uint64(len(self.window)) 78 | data_len := uint64(len(data)) 79 | 80 | pos := uint64(0) 81 | 82 | if self.window_size < uint64(window_len) { 83 | need := window_len - self.window_size 84 | copy_len := uint64(0) 85 | if need < data_len { 86 | copy_len = need 87 | } else { 88 | copy_len = data_len 89 | } 90 | 91 | for _i := uint64(0); _i < copy_len; _i++ { 92 | B := data[pos] 93 | self.window[self.window_size] = B 94 | self.h = bits.RotateLeft32(self.h, 1) ^ buzhash_table[B] 95 | pos += 1 96 | self.window_size += 1 97 | } 98 | 99 | self.chunk_size += copy_len 100 | 101 | if self.window_size < window_len { 102 | return 0 103 | } 104 | } 105 | 106 | idx := self.chunk_size & 0x3f 107 | 108 | for pos < data_len { 109 | enter := data[pos] 110 | leave := self.window[idx] 111 | self.h = bits.RotateLeft32(self.h, 1) ^ buzhash_table[leave] ^ buzhash_table[enter] 112 | self.chunk_size += 1 113 | pos += 1 114 | self.window[idx] = enter 115 | 116 | if self.shall_break() { 117 | self.h = 0 118 | self.chunk_size = 0 119 | self.window_size = 0 120 | return pos 121 | } 122 | 123 | idx = self.chunk_size & 0x3f 124 | } 125 | 126 | return 0 127 | 128 | } 129 | 130 | func (self *Chunker) shall_break() bool { 131 | if self.chunk_size >= self.chunk_size_max { 132 | return true 133 | } 134 | 135 | if self.chunk_size < self.chunk_size_min { 136 | return false 137 | } 138 | 139 | //return (self.h % self._discriminator) == (self._discriminator - 1) 140 | return (self.h & self.break_test_mask) >= self.break_test_minimum 141 | } 142 | -------------------------------------------------------------------------------- /config.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "flag" 6 | "fmt" 7 | "os" 8 | ) 9 | 10 | type MailSendConfig struct { 11 | From string `json:"from"` 12 | To string `json:"to"` 13 | } 14 | 15 | type MailTemplate struct { 16 | Subject string `json:"subject"` 17 | Body string `json:"body"` 18 | } 19 | 20 | type SMTPConfig struct { 21 | Host string `json:"host"` 22 | Port string `json:"port"` 23 | Username string `json:"username"` 24 | Password string `json:"password"` 25 | Insecure bool `json:"insecure"` 26 | Mails []MailSendConfig `json:"mails"` 27 | Template *MailTemplate `json:"template"` 28 | } 29 | 30 | type Config struct { 31 | BaseURL string `json:"baseurl"` 32 | CertFingerprint string `json:"certfingerprint"` 33 | AuthID string `json:"authid"` 34 | Secret string `json:"secret"` 35 | Datastore string `json:"datastore"` 36 | Namespace string `json:"namespace"` 37 | BackupID string `json:"backup-id"` 38 | BackupSourceDir string `json:"backupdir"` 39 | BackupStreamName string `json:"backupstreamname"` 40 | PxarOut string `json:"pxarout"` 41 | SMTP *SMTPConfig `json:"smtp"` 42 | } 43 | 44 | func (c *Config) valid() bool { 45 | baseValid := c.BaseURL != "" && c.AuthID != "" && c.Secret != "" && c.Datastore != "" && ( c.BackupSourceDir != "" || c.BackupStreamName != "" ) 46 | if !baseValid { 47 | return baseValid 48 | } 49 | 50 | if c.SMTP != nil { 51 | mailCfgValid := c.SMTP.Host != "" && c.SMTP.Port != "" && c.SMTP.Username != "" && c.SMTP.Password != "" 52 | if len(c.SMTP.Mails) == 0 { 53 | return false 54 | } 55 | for i := range c.SMTP.Mails { 56 | mailCfgValid = mailCfgValid && (c.SMTP.Mails[i].From != "" && c.SMTP.Mails[i].To != "") 57 | } 58 | return mailCfgValid 59 | } 60 | 61 | return true 62 | } 63 | 64 | func loadConfig() *Config { 65 | // Define flags 66 | baseURLFlag := flag.String("baseurl", "", "Base URL for the proxmox backup server, example: https://192.168.1.10:8007") 67 | certFingerprintFlag := flag.String("certfingerprint", "", "Certificate fingerprint for SSL connection, example: ea:7d:06:f9...") 68 | authIDFlag := flag.String("authid", "", "Authentication ID (PBS Api token)") 69 | secretFlag := flag.String("secret", "", "Secret for authentication") 70 | datastoreFlag := flag.String("datastore", "", "Datastore name") 71 | namespaceFlag := flag.String("namespace", "", "Namespace (optional)") 72 | backupIDFlag := flag.String("backup-id", "", "Backup ID (optional - if not specified, the hostname is used as the default)") 73 | backupSourceDirFlag := flag.String("backupdir", "", "Backup source directory, must not be symlink") 74 | backupStreamNameFlag := flag.String("backupstream", "", "Filename for stream backup") 75 | pxarOutFlag := flag.String("pxarout", "", "Output PXAR archive for debug purposes (optional)") 76 | 77 | mailHostFlag := flag.String("mail-host", "", "mail notification system: mail server host(optional)") 78 | mailPortFlag := flag.String("mail-port", "", "mail notification system: mail server port(optional)") 79 | mailUsernameFlag := flag.String("mail-username", "", "mail notification system: mail server username(optional)") 80 | mailPasswordFlag := flag.String("mail-password", "", "mail notification system: mail server password(optional)") 81 | mailInsecureFlag := flag.Bool("mail-insecure", false, "mail notification system: allow insecure communications(optional)") 82 | mailFromFlag := flag.String("mail-from", "", "mail notification system: sender mail(optional)") 83 | mailToFlag := flag.String("mail-to", "", "mail notification system: receiver mail(optional)") 84 | mailSubjectTemplateFlag := flag.String("mail-subject-template", "", "mail notification system: mail subject template(optional)") 85 | mailBodyTemplateFlag := flag.String("mail-body-template", "", "mail notification system: mail body template(optional)") 86 | 87 | configFile := flag.String("config", "", "Path to JSON config file. If this flag is provided all the others will override the loaded config file") 88 | 89 | // Parse command line flags 90 | flag.Parse() 91 | 92 | config := &Config{} 93 | if *configFile != "" { 94 | file, err := os.ReadFile(*configFile) 95 | if err != nil { 96 | fmt.Printf("Error reading config file: %v\n", err) 97 | os.Exit(1) 98 | } 99 | err = json.Unmarshal(file, config) 100 | if err != nil { 101 | fmt.Printf("Error parsing config file: %v\n", err) 102 | os.Exit(1) 103 | } 104 | } 105 | 106 | if *baseURLFlag != "" { 107 | config.BaseURL = *baseURLFlag 108 | } 109 | if *certFingerprintFlag != "" { 110 | config.CertFingerprint = *certFingerprintFlag 111 | } 112 | if *authIDFlag != "" { 113 | config.AuthID = *authIDFlag 114 | } 115 | if *secretFlag != "" { 116 | config.Secret = *secretFlag 117 | } 118 | if *datastoreFlag != "" { 119 | config.Datastore = *datastoreFlag 120 | } 121 | if *namespaceFlag != "" { 122 | config.Namespace = *namespaceFlag 123 | } 124 | if *backupIDFlag != "" { 125 | config.BackupID = *backupIDFlag 126 | } 127 | if *backupSourceDirFlag != "" { 128 | config.BackupSourceDir = *backupSourceDirFlag 129 | } 130 | 131 | if *backupStreamNameFlag != "" { 132 | config.BackupStreamName = *backupStreamNameFlag 133 | } 134 | if *pxarOutFlag != "" { 135 | config.PxarOut = *pxarOutFlag 136 | } 137 | 138 | initSmtpConfigIfNeeded := func() { 139 | if config.SMTP == nil { 140 | config.SMTP = &SMTPConfig{} 141 | } 142 | } 143 | initMailConfsIfNeeded := func() { 144 | initSmtpConfigIfNeeded() 145 | if len(config.SMTP.Mails) == 0 { 146 | config.SMTP.Mails = append(config.SMTP.Mails, MailSendConfig{}) 147 | } 148 | } 149 | 150 | if *mailHostFlag != "" { 151 | initSmtpConfigIfNeeded() 152 | config.SMTP.Host = *mailHostFlag 153 | } 154 | if *mailPortFlag != "" { 155 | initSmtpConfigIfNeeded() 156 | config.SMTP.Port = *mailPortFlag 157 | } 158 | if *mailUsernameFlag != "" { 159 | initSmtpConfigIfNeeded() 160 | config.SMTP.Username = *mailUsernameFlag 161 | } 162 | if *mailPasswordFlag != "" { 163 | initSmtpConfigIfNeeded() 164 | config.SMTP.Password = *mailPasswordFlag 165 | } 166 | if *mailInsecureFlag { 167 | initSmtpConfigIfNeeded() 168 | config.SMTP.Insecure = *mailInsecureFlag 169 | } 170 | if *mailFromFlag != "" { 171 | initMailConfsIfNeeded() 172 | config.SMTP.Mails[0].From = *mailFromFlag 173 | } 174 | if *mailToFlag != "" { 175 | initMailConfsIfNeeded() 176 | config.SMTP.Mails[0].To = *mailToFlag 177 | } 178 | if *mailSubjectTemplateFlag != "" { 179 | initSmtpConfigIfNeeded() 180 | config.SMTP.Template.Subject = *mailSubjectTemplateFlag 181 | } 182 | if *mailBodyTemplateFlag != "" { 183 | initSmtpConfigIfNeeded() 184 | config.SMTP.Template.Body = *mailBodyTemplateFlag 185 | } 186 | 187 | return config 188 | } 189 | -------------------------------------------------------------------------------- /config.json.example: -------------------------------------------------------------------------------- 1 | { 2 | "baseurl": "https://your.pbs.installation.net:8007", 3 | "certfingerprint": "XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX", 4 | "authid": "MY-SECRET-AUTH-ID", 5 | "secret": "secret-uuid", 6 | "datastore": "myDatastore", 7 | "backupdir": "C:", 8 | "namespace": "", 9 | "backup-id": "", 10 | "pxarout": "", 11 | "smtp": { 12 | "host": "smtp.example.com", 13 | "port": "465", 14 | "username": "my-user@example.com", 15 | "password": "my-password", 16 | "insecure": false, 17 | "template": { 18 | "subject": "{{if not .Success}}[FAILED]{{else}}[SUCCESS]{{end}} Backup report for {{.Datastore}}", 19 | "body": "Backup {{if .Success}}completed{{else}}ended with errors{{end}} on host {{.Hostname}} (took {{.FromattedDuration}})\n{{if .Success}}Chunks New {{.NewChunks}}, Reused {{.ReusedChunks}}.{{else}}Error occurred while working, backup may be not completed.\nLast error is: {{.ErrorStr}}{{end}}" 20 | }, 21 | "mails": [{ 22 | "from": "sender1@example.com", 23 | "to": "receiver1@example.com 24 | }, { 25 | "from": "sender2@example.com", 26 | "to": "receiver2@example.com 27 | }] 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module proxmoxbackupgo 2 | 3 | go 1.19 4 | 5 | require ( 6 | github.com/cornelk/hashmap v1.0.8 7 | github.com/dchest/siphash v1.2.3 8 | github.com/gen2brain/beeep v0.0.0-20230907135156-1a38885a97fc 9 | github.com/getlantern/systray v1.2.2 10 | github.com/jeromehadorn/vss v0.1.0 11 | github.com/klauspost/compress v1.17.4 12 | github.com/rodolfoag/gow32 v0.0.0-20230512144032-1e896a3c51aa 13 | github.com/tawesoft/golib/v2 v2.10.0 14 | golang.org/x/net v0.19.0 15 | ) 16 | 17 | require ( 18 | github.com/alessio/shellescape v1.4.1 // indirect 19 | github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect 20 | github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 // indirect 21 | github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7 // indirect 22 | github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 // indirect 23 | github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 // indirect 24 | github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect 25 | github.com/go-ole/go-ole v1.2.6 // indirect 26 | github.com/go-stack/stack v1.8.0 // indirect 27 | github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect 28 | github.com/godbus/dbus/v5 v5.1.0 // indirect 29 | github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect 30 | github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect 31 | github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect 32 | golang.org/x/exp v0.0.0-20221208152030-732eee02a75a // indirect 33 | golang.org/x/sys v0.15.0 // indirect 34 | golang.org/x/text v0.14.0 // indirect 35 | ) 36 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= 2 | github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= 3 | github.com/cornelk/hashmap v1.0.8 h1:nv0AWgw02n+iDcawr5It4CjQIAcdMMKRrs10HOJYlrc= 4 | github.com/cornelk/hashmap v1.0.8/go.mod h1:RfZb7JO3RviW/rT6emczVuC/oxpdz4UsSB2LJSclR1k= 5 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 6 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 7 | github.com/dchest/siphash v1.2.3 h1:QXwFc8cFOR2dSa/gE6o/HokBMWtLUaNDVd+22aKHeEA= 8 | github.com/dchest/siphash v1.2.3/go.mod h1:0NvQU092bT0ipiFN++/rXm69QG9tVxLAlQHIXMPAkHc= 9 | github.com/gen2brain/beeep v0.0.0-20230907135156-1a38885a97fc h1:NNgdMgPX3j33uEAoVVxNxillDPnxT0xbGv8uh4CKIAo= 10 | github.com/gen2brain/beeep v0.0.0-20230907135156-1a38885a97fc/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4= 11 | github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 h1:NRUJuo3v3WGC/g5YiyF790gut6oQr5f3FBI88Wv0dx4= 12 | github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY= 13 | github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 h1:6uJ+sZ/e03gkbqZ0kUG6mfKoqDb4XMAzMIwlajq19So= 14 | github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7/go.mod h1:l+xpFBrCtDLpK9qNjxs+cHU6+BAdlBaxHqikB6Lku3A= 15 | github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7 h1:guBYzEaLz0Vfc/jv0czrr2z7qyzTOGC9hiQ0VC+hKjk= 16 | github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7/go.mod h1:zx/1xUUeYPy3Pcmet8OSXLbF47l+3y6hIPpyLWoR9oc= 17 | github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 h1:micT5vkcr9tOVk1FiH8SWKID8ultN44Z+yzd2y/Vyb0= 18 | github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7/go.mod h1:dD3CgOrwlzca8ed61CsZouQS5h5jIzkK9ZWrTcf0s+o= 19 | github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 h1:XYzSdCbkzOC0FDNrgJqGRo8PCMFOBFL9py72DRs7bmc= 20 | github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55/go.mod h1:6mmzY2kW1TOOrVy+r41Za2MxXM+hhqTtY3oBKd2AgFA= 21 | github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f h1:wrYrQttPS8FHIRSlsrcuKazukx/xqO/PpLZzZXsF+EA= 22 | github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA= 23 | github.com/getlantern/systray v1.2.2 h1:dCEHtfmvkJG7HZ8lS/sLklTH4RKUcIsKrAD9sThoEBE= 24 | github.com/getlantern/systray v1.2.2/go.mod h1:pXFOI1wwqwYXEhLPm9ZGjS2u/vVELeIgNMY5HvhHhcE= 25 | github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= 26 | github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= 27 | github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= 28 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 29 | github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE= 30 | github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10= 31 | github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= 32 | github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= 33 | github.com/jeromehadorn/vss v0.1.0 h1:0EWv9lG/jv1Wzbt5WhwIUMLxDZ5uSh21LkPHUO34w2Y= 34 | github.com/jeromehadorn/vss v0.1.0/go.mod h1:wHwqd/OMHe4Eu0rS/QX4/jKj2sJPtjRf6YrxBhj/EfY= 35 | github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4= 36 | github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= 37 | github.com/lxn/walk v0.0.0-20210112085537-c389da54e794/go.mod h1:E23UucZGqpuUANJooIbHWCufXvOcT6E7Stq81gU+CSQ= 38 | github.com/lxn/win v0.0.0-20210218163916-a377121e959e/go.mod h1:KxxjdtRkfNoYDCUP5ryK7XJJNTnpC8atvtmTheChOtk= 39 | github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ= 40 | github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U= 41 | github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= 42 | github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= 43 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 44 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 45 | github.com/rodolfoag/gow32 v0.0.0-20230512144032-1e896a3c51aa h1:cd9mmDEXO4YxGYTbrhbfEt7btgUlcXFedTMoZ9fA4Ns= 46 | github.com/rodolfoag/gow32 v0.0.0-20230512144032-1e896a3c51aa/go.mod h1:w/ebPUfAcyZMYjstwPIWTEGSahChHx5R3Y+xElrvxDc= 47 | github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= 48 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 49 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 50 | github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= 51 | github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk= 52 | github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o= 53 | github.com/tawesoft/golib/v2 v2.10.0 h1:uvA5Cy+UV6NHrf3Qwg1+2Uvz6eKVW1t+KrJ9gZYSjag= 54 | github.com/tawesoft/golib/v2 v2.10.0/go.mod h1:jGw0nDuOLpji2TW5QfSQLcWnZ4WtS4TizzRuXu3hZ/Y= 55 | golang.org/x/exp v0.0.0-20221208152030-732eee02a75a h1:4iLhBPcpqFmylhnkbY3W0ONLUYYkDAW9xMFLfxgsvCw= 56 | golang.org/x/exp v0.0.0-20221208152030-732eee02a75a/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= 57 | golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= 58 | golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= 59 | golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 60 | golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 61 | golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 62 | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 63 | golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= 64 | golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 65 | golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= 66 | golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= 67 | gopkg.in/Knetic/govaluate.v3 v3.0.0/go.mod h1:csKLBORsPbafmSCGTEh3U7Ozmsuq8ZSIlKk1bcqph0E= 68 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 69 | -------------------------------------------------------------------------------- /icon.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | var ICON = []byte{ 4 | 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x30, 0x30, 0x10, 0x00, 0x01, 0x00, 5 | 0x04, 0x00, 0x68, 0x06, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x28, 0x00, 6 | 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x01, 0x00, 7 | 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 8 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 9 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x28, 0x00, 0x00, 0x02, 10 | 0x58, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x03, 0x97, 0x00, 0x00, 0x00, 11 | 0xad, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x01, 0x05, 12 | 0xf9, 0x00, 0x02, 0x2f, 0xfa, 0x00, 0x01, 0x41, 0xf6, 0x00, 0x01, 0x54, 13 | 0xf2, 0x00, 0x00, 0x5e, 0xed, 0x00, 0x00, 0x66, 0xea, 0x00, 0x01, 0x6d, 14 | 0xe8, 0x00, 0x00, 0x70, 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 15 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 16 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 17 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 18 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 19 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 20 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 22 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 23 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 25 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 26 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 27 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 28 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 31 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 32 | 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xff, 0xfe, 0xff, 0xf0, 0x00, 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 34 | 0x00, 0xff, 0xef, 0xff, 0xff, 0xe0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x00, 35 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 36 | 0x0f, 0xfe, 0xef, 0xff, 0xfe, 0xef, 0xff, 0xfe, 0xef, 0xfe, 0xef, 0xe0, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 38 | 0xfe, 0xef, 0xff, 0xff, 0xef, 0xf0, 0x00, 0xff, 0xff, 0xef, 0xff, 0xef, 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 40 | 0xff, 0xff, 0xff, 0xfe, 0xef, 0x00, 0x00, 0xee, 0xff, 0xfe, 0xff, 0xff, 41 | 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 42 | 0xff, 0xff, 0xff, 0xef, 0xf0, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 43 | 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 44 | 0xee, 0xef, 0xfe, 0xef, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xee, 0xfe, 0xba, 45 | 0x87, 0x78, 0x78, 0x65, 0x41, 0x00, 0x00, 0x00, 0x02, 0x67, 0x77, 0x79, 46 | 0xac, 0xee, 0xef, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xc8, 0x77, 47 | 0x77, 0x77, 0x77, 0x77, 0x74, 0x00, 0x00, 0x01, 0x68, 0x77, 0x77, 0x77, 48 | 0x77, 0x8c, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfa, 0x87, 0x7b, 49 | 0xce, 0xfe, 0xe0, 0x77, 0x74, 0x00, 0x00, 0x16, 0x77, 0x7b, 0xdf, 0xed, 50 | 0xb8, 0x77, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x79, 0xdf, 51 | 0xff, 0xfe, 0xfe, 0x07, 0x74, 0x00, 0x00, 0x67, 0x77, 0x0f, 0xfe, 0xff, 52 | 0xff, 0xa7, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x8e, 0xff, 53 | 0xef, 0xff, 0xff, 0xc7, 0x74, 0x00, 0x03, 0x87, 0x7f, 0xef, 0xff, 0xef, 54 | 0xff, 0xe8, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x77, 0x0f, 0xef, 55 | 0xef, 0xee, 0xff, 0xd7, 0x70, 0x00, 0x06, 0x77, 0x0e, 0xef, 0xff, 0xff, 56 | 0xee, 0xe9, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x77, 0x00, 0xff, 57 | 0xff, 0xff, 0xfe, 0xd7, 0x70, 0x00, 0x07, 0x78, 0xff, 0xff, 0xee, 0xff, 58 | 0xff, 0xf0, 0x77, 0x70, 0x00, 0x00, 0x00, 0x00, 0x07, 0x77, 0x00, 0x0f, 59 | 0xef, 0xff, 0xfe, 0xd7, 0x7a, 0x00, 0x07, 0x8a, 0xef, 0xff, 0xff, 0xfe, 60 | 0xf0, 0x00, 0x07, 0x70, 0x00, 0x00, 0x00, 0x00, 0x77, 0x70, 0x00, 0x00, 61 | 0xff, 0xff, 0xff, 0xd7, 0x7c, 0xf0, 0x77, 0x7b, 0xff, 0xff, 0xef, 0xff, 62 | 0xe0, 0x00, 0x77, 0x70, 0x00, 0x00, 0x00, 0x00, 0x07, 0x77, 0x00, 0x00, 63 | 0x0f, 0xa7, 0x77, 0x77, 0x7c, 0x00, 0x07, 0x7b, 0xef, 0xee, 0xef, 0xff, 64 | 0x00, 0x00, 0x07, 0x70, 0x00, 0x00, 0x00, 0x00, 0x77, 0x70, 0x00, 0xef, 65 | 0xef, 0xa7, 0x77, 0x77, 0x70, 0x00, 0x87, 0x7b, 0xff, 0xff, 0xff, 0xee, 66 | 0xf0, 0x00, 0x77, 0x70, 0x00, 0x00, 0x00, 0x00, 0x07, 0x77, 0x00, 0x0e, 67 | 0xef, 0xff, 0xfe, 0xef, 0x00, 0x00, 0x38, 0x7a, 0xff, 0xff, 0xff, 0xff, 68 | 0xfe, 0x00, 0x07, 0x70, 0x00, 0x00, 0x00, 0x00, 0x77, 0x77, 0xff, 0xff, 69 | 0xff, 0xff, 0xef, 0xf0, 0x00, 0x00, 0x28, 0x80, 0xff, 0xef, 0xff, 0xef, 70 | 0xff, 0xe0, 0x77, 0x70, 0x00, 0x00, 0x00, 0x00, 0x07, 0x77, 0x0e, 0xfe, 71 | 0xff, 0xfe, 0xef, 0x00, 0x00, 0x00, 0x08, 0x77, 0x0e, 0xff, 0xee, 0xef, 72 | 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0xcf, 0xff, 73 | 0xff, 0xef, 0xf0, 0x00, 0x00, 0x00, 0x06, 0x88, 0x80, 0xef, 0xff, 0xff, 74 | 0xee, 0xfc, 0x77, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0x8d, 0xfe, 75 | 0xfe, 0xef, 0x00, 0x00, 0x00, 0x00, 0x03, 0x87, 0x80, 0x0f, 0xff, 0xff, 76 | 0xff, 0xf9, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc7, 0x78, 0xdf, 77 | 0xff, 0xff, 0xd0, 0x01, 0x10, 0x00, 0x00, 0x68, 0x86, 0x00, 0xff, 0xff, 78 | 0xef, 0xa7, 0x7b, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xec, 0x87, 0x7a, 79 | 0xcd, 0xe0, 0x05, 0x68, 0x40, 0x00, 0x00, 0x18, 0x87, 0x87, 0x0e, 0xed, 80 | 0xb9, 0x78, 0xaf, 0xef, 0x00, 0x00, 0x00, 0x00, 0xef, 0xff, 0xda, 0x77, 81 | 0x77, 0x78, 0x87, 0x78, 0x80, 0x00, 0x00, 0x01, 0x67, 0x87, 0x87, 0x77, 82 | 0x77, 0x7b, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xdb, 83 | 0x97, 0x78, 0x88, 0x64, 0x20, 0x00, 0x00, 0x00, 0x02, 0x58, 0x87, 0x78, 84 | 0xab, 0xef, 0xef, 0xef, 0xff, 0x00, 0x00, 0xef, 0xff, 0xff, 0xff, 0xef, 85 | 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 86 | 0xef, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0xff, 0xff, 0xfe, 0xee, 0xef, 87 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 88 | 0x0f, 0xff, 0xff, 0xff, 0xee, 0xe0, 0xff, 0xef, 0xee, 0xef, 0xff, 0xf0, 89 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 90 | 0x00, 0xee, 0xef, 0xef, 0xff, 0xf0, 0x0f, 0x0f, 0xff, 0xff, 0x00, 0x00, 91 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 92 | 0x00, 0x0f, 0xff, 0xef, 0xef, 0x00, 0x00, 0x00, 0xe0, 0xf0, 0x00, 0x00, 93 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 94 | 0x00, 0x00, 0xe0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 95 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 96 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 97 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 98 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 99 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 100 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 101 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 102 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 103 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 104 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 105 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 106 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 107 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 108 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 109 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 110 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 111 | 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 112 | 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xf1, 0xff, 0xff, 0x57, 0xff, 113 | 0x00, 0x00, 0xff, 0x80, 0xff, 0xfe, 0x03, 0xff, 0x00, 0x00, 0xff, 0x00, 114 | 0x3f, 0xfc, 0x01, 0xff, 0x00, 0x00, 0xff, 0x80, 0x3f, 0xf8, 0x03, 0xff, 115 | 0x00, 0x00, 0xff, 0xc0, 0x0f, 0xf0, 0x03, 0xff, 0x00, 0x00, 0xff, 0xe0, 116 | 0x0f, 0xe0, 0x0f, 0xef, 0x00, 0x00, 0xc0, 0x70, 0x07, 0xc0, 0x0c, 0x01, 117 | 0x00, 0x00, 0x80, 0x38, 0x03, 0x80, 0x18, 0x00, 0x00, 0x00, 0x00, 0x1c, 118 | 0x01, 0x00, 0x10, 0x01, 0x00, 0x00, 0xc0, 0x0e, 0x00, 0x00, 0x70, 0x03, 119 | 0x00, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x40, 0x07, 0x00, 0x00, 0xe0, 0x03, 120 | 0x80, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x1f, 121 | 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0xfc, 0x00, 122 | 0x40, 0x00, 0x00, 0x7f, 0x00, 0x00, 0xfe, 0x00, 0x20, 0x02, 0x00, 0x3f, 123 | 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0xf8, 0x80, 124 | 0x04, 0x08, 0x00, 0x3f, 0x00, 0x00, 0xf8, 0xc0, 0x06, 0x00, 0x01, 0x1f, 125 | 0x00, 0x00, 0xf8, 0xe0, 0x03, 0x80, 0x07, 0x9f, 0x00, 0x00, 0xf1, 0xf0, 126 | 0x01, 0x00, 0x07, 0x1f, 0x00, 0x00, 0xf8, 0xf8, 0x03, 0x80, 0x0f, 0x9f, 127 | 0x00, 0x00, 0xf1, 0xc0, 0x07, 0x00, 0x07, 0x1f, 0x00, 0x00, 0xf8, 0xe0, 128 | 0x0e, 0x00, 0x03, 0x9f, 0x00, 0x00, 0xf0, 0x00, 0x1c, 0x10, 0x01, 0x1f, 129 | 0x00, 0x00, 0xf8, 0x80, 0x38, 0x08, 0x00, 0xbf, 0x00, 0x00, 0xfc, 0x00, 130 | 0x70, 0x04, 0x00, 0x1f, 0x00, 0x00, 0xfc, 0x00, 0xe0, 0x06, 0x00, 0x3f, 131 | 0x00, 0x00, 0xf8, 0x00, 0x40, 0x03, 0x00, 0x1f, 0x00, 0x00, 0xf8, 0x01, 132 | 0x80, 0x00, 0x80, 0x0f, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x07, 133 | 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0xc0, 0x04, 134 | 0x00, 0x00, 0x70, 0x01, 0x00, 0x00, 0x80, 0x0c, 0x00, 0x80, 0x38, 0x01, 135 | 0x00, 0x00, 0x00, 0x18, 0x01, 0xc0, 0x1c, 0x01, 0x00, 0x00, 0xa0, 0xf0, 136 | 0x03, 0xe0, 0x0e, 0x03, 0x00, 0x00, 0xf5, 0xe0, 0x07, 0xf0, 0x07, 0x57, 137 | 0x00, 0x00, 0xff, 0xe0, 0x0f, 0xf8, 0x03, 0xff, 0x00, 0x00, 0xff, 0xc0, 138 | 0x1f, 0xf8, 0x01, 0xff, 0x00, 0x00, 0xff, 0x80, 0x3f, 0xfe, 0x00, 0xff, 139 | 0x00, 0x00, 0xff, 0x00, 0x7f, 0xff, 0x01, 0xff, 0x00, 0x00, 0xff, 0xeb, 140 | 0xff, 0xff, 0xaf, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 141 | 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 142 | 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 143 | } 144 | -------------------------------------------------------------------------------- /mail.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "crypto/tls" 5 | "errors" 6 | "fmt" 7 | "html/template" 8 | "net/smtp" 9 | "strings" 10 | "time" 11 | ) 12 | 13 | type unencryptedAuth struct { 14 | smtp.Auth 15 | } 16 | 17 | func (a unencryptedAuth) Start(server *smtp.ServerInfo) (string, []byte, error) { 18 | s := *server 19 | s.TLS = true 20 | return a.Auth.Start(&s) 21 | } 22 | 23 | func setupClient(host, port, username, password string, allowInsecure bool) (*smtp.Client, error) { 24 | var auth smtp.Auth 25 | auth = smtp.PlainAuth("", username, password, host) 26 | if port == "25" { 27 | if !allowInsecure { 28 | return nil, errors.New("sending plain password over unencrypted connection") 29 | } 30 | auth = unencryptedAuth{auth} 31 | } 32 | 33 | var tlsconfig *tls.Config 34 | if port != "25" { 35 | // TLS config 36 | tlsconfig = &tls.Config{ 37 | InsecureSkipVerify: allowInsecure, 38 | ServerName: host, 39 | } 40 | } 41 | 42 | servername := host + ":" + port 43 | 44 | var c *smtp.Client 45 | var err error 46 | if port == "465" { 47 | // Here is the key, you need to call tls.Dial instead of smtp.Dial 48 | // for smtp servers running on 465 that require an ssl connection 49 | // from the very beginning (no starttls) 50 | conn, err := tls.Dial("tcp", servername, tlsconfig) 51 | if err != nil { 52 | return nil, err 53 | } 54 | 55 | c, err = smtp.NewClient(conn, host) 56 | if err != nil { 57 | return nil, err 58 | } 59 | } else { 60 | c, err = smtp.Dial(servername) 61 | if err != nil { 62 | return nil, err 63 | } 64 | if port == "587" { 65 | c.StartTLS(tlsconfig) 66 | } 67 | } 68 | 69 | // Auth 70 | if err = c.Auth(auth); err != nil { 71 | fmt.Println("here", err) 72 | return nil, err 73 | } 74 | 75 | return c, nil 76 | } 77 | 78 | func sendMail(from, to, subject, body string, c *smtp.Client) error { 79 | // Setup headers 80 | headers := make(map[string]string) 81 | headers["From"] = from 82 | recipients := strings.Split(to, ",") 83 | recipientsStr := make([]string, 0) 84 | for i := range recipients { 85 | recipientsStr = append(recipientsStr, fmt.Sprintf("<%s>", recipients[i])) 86 | } 87 | headers["To"] = strings.Join(recipientsStr, ",") 88 | headers["Subject"] = subject 89 | 90 | // Setup message 91 | message := "" 92 | for k, v := range headers { 93 | message += fmt.Sprintf("%s: %s\r\n", k, v) 94 | } 95 | message += "\r\n" + body 96 | 97 | // To && From 98 | if err := c.Mail(from); err != nil { 99 | return err 100 | } 101 | 102 | if err := c.Rcpt(strings.Join(recipientsStr, ",")); err != nil { 103 | return err 104 | } 105 | 106 | // Data 107 | w, err := c.Data() 108 | if err != nil { 109 | return err 110 | } 111 | 112 | _, err = w.Write([]byte(message)) 113 | if err != nil { 114 | return err 115 | } 116 | 117 | err = w.Close() 118 | if err != nil { 119 | return err 120 | } 121 | 122 | return nil 123 | } 124 | 125 | type mailCtx struct { 126 | NewChunks uint64 127 | ReusedChunks uint64 128 | Datastore string 129 | Error error 130 | Hostname string 131 | StartTime time.Time 132 | EndTime time.Time 133 | } 134 | 135 | func (m *mailCtx) Duration() time.Duration { 136 | return m.EndTime.Sub(m.StartTime) 137 | } 138 | 139 | func (m *mailCtx) FromattedDuration() string { 140 | return m.Duration().String() 141 | } 142 | 143 | func (m *mailCtx) ErrorStr() string { 144 | if m.Error != nil { 145 | return m.Error.Error() 146 | } 147 | return "" 148 | } 149 | 150 | func (m *mailCtx) Success() bool { 151 | return m.Error == nil 152 | } 153 | 154 | func (m *mailCtx) Status() string { 155 | if m.Success() { 156 | return "Success" 157 | } 158 | return "Failed" 159 | } 160 | 161 | func (m *mailCtx) buildStr(txt string) (string, error) { 162 | tmpl, err := template.New("mail").Parse(txt) 163 | if err != nil { 164 | return "", err 165 | } 166 | strBuff := &strings.Builder{} 167 | err = tmpl.Execute(strBuff, m) 168 | return strBuff.String(), err 169 | } 170 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "crypto/sha256" 6 | "encoding/binary" 7 | "encoding/hex" 8 | "flag" 9 | "fmt" 10 | "hash" 11 | "io" 12 | "os" 13 | "runtime" 14 | "strings" 15 | "sync/atomic" 16 | "time" 17 | 18 | "github.com/cornelk/hashmap" 19 | "github.com/gen2brain/beeep" 20 | "github.com/getlantern/systray" 21 | "github.com/tawesoft/golib/v2/dialog" 22 | ) 23 | 24 | 25 | 26 | var defaultMailSubjectTemplate = "Backup {{.Status}}" 27 | var defaultMailBodyTemplate = `{{if .Success}}Backup complete ({{.FromattedDuration}}) 28 | Chunks New {{.NewChunks}}, Reused {{.ReusedChunks}}.{{else}}Error occurred while working, backup may be not completed. 29 | Last error is: {{.ErrorStr}}{{end}}` 30 | 31 | var didxMagic = []byte{28, 145, 78, 165, 25, 186, 179, 205} 32 | 33 | type ChunkState struct { 34 | assignments []string 35 | assignments_offset []uint64 36 | pos uint64 37 | wrid uint64 38 | chunkcount uint64 39 | chunkdigests hash.Hash 40 | current_chunk []byte 41 | C Chunker 42 | newchunk *atomic.Uint64 43 | reusechunk *atomic.Uint64 44 | knownChunks *hashmap.Map[string, bool] 45 | } 46 | 47 | type DidxEntry struct { 48 | offset uint64 49 | digest []byte 50 | } 51 | 52 | func (c *ChunkState) Init(newchunk *atomic.Uint64 , reusechunk *atomic.Uint64, knownChunks *hashmap.Map[string, bool] ) { 53 | c.assignments = make([]string, 0) 54 | c.assignments_offset = make([]uint64, 0) 55 | c.pos = 0 56 | c.chunkcount = 0 57 | c.chunkdigests = sha256.New() 58 | c.current_chunk = make([]byte, 0) 59 | c.C = Chunker{} 60 | c.C.New(1024 * 1024 * 4) 61 | c.reusechunk = reusechunk 62 | c.newchunk = newchunk 63 | c.knownChunks = knownChunks 64 | } 65 | 66 | func (c *ChunkState) HandleData(b []byte, client *PBSClient){ 67 | chunkpos := c.C.Scan(b) 68 | 69 | if chunkpos == 0 { 70 | //No break happened, just append data 71 | c.current_chunk = append(c.current_chunk, b...) 72 | } else { 73 | 74 | for chunkpos > 0 { 75 | //Append data until break position 76 | c.current_chunk = append(c.current_chunk, b[:chunkpos]...) 77 | 78 | h := sha256.New() 79 | // TODO: error handling inside callback 80 | h.Write(c.current_chunk) 81 | bindigest := h.Sum(nil) 82 | shahash := hex.EncodeToString(bindigest) 83 | 84 | if _, ok := c.knownChunks.GetOrInsert(shahash, true); !ok { 85 | fmt.Printf("New chunk[%s] %d bytes\n", shahash, len(c.current_chunk)) 86 | c.newchunk.Add(1) 87 | 88 | client.UploadCompressedChunk(c.wrid, shahash, c.current_chunk) 89 | } else { 90 | fmt.Printf("Reuse chunk[%s] %d bytes\n", shahash, len(c.current_chunk)) 91 | c.reusechunk.Add(1) 92 | } 93 | 94 | // TODO: error handling inside callback 95 | binary.Write(c.chunkdigests, binary.LittleEndian, (c.pos + uint64(len(c.current_chunk)))) 96 | // TODO: error handling inside callback 97 | c.chunkdigests.Write(h.Sum(nil)) 98 | 99 | c.assignments_offset = append(c.assignments_offset, c.pos) 100 | c.assignments = append(c.assignments, shahash) 101 | c.pos += uint64(len(c.current_chunk)) 102 | c.chunkcount += 1 103 | 104 | c.current_chunk = make([]byte, 0) 105 | b = b[chunkpos:] //Take remainder of data 106 | chunkpos = c.C.Scan(b) 107 | 108 | } 109 | 110 | //No further break happened, append remaining data 111 | c.current_chunk = append(c.current_chunk, b...) 112 | } 113 | } 114 | 115 | func (c *ChunkState) Eof(client *PBSClient) { 116 | //Here we write the remainder of data for which cyclic hash did not trigger 117 | 118 | if len(c.current_chunk) > 0 { 119 | h := sha256.New() 120 | _, err := h.Write(c.current_chunk) 121 | if err != nil { 122 | panic(err) 123 | } 124 | 125 | shahash := hex.EncodeToString(h.Sum(nil)) 126 | binary.Write(c.chunkdigests, binary.LittleEndian, (c.pos + uint64(len(c.current_chunk)))) 127 | c.chunkdigests.Write(h.Sum(nil)) 128 | 129 | if _, ok := c.knownChunks.GetOrInsert(shahash, true); !ok { 130 | fmt.Printf("New chunk[%s] %d bytes\n", shahash, len(c.current_chunk)) 131 | client.UploadCompressedChunk(c.wrid, shahash, c.current_chunk) 132 | c.newchunk.Add(1) 133 | } else { 134 | fmt.Printf("Reuse chunk[%s] %d bytes\n", shahash, len(c.current_chunk)) 135 | c.reusechunk.Add(1) 136 | } 137 | c.assignments_offset = append(c.assignments_offset, c.pos) 138 | c.assignments = append(c.assignments, shahash) 139 | c.pos += uint64(len(c.current_chunk)) 140 | c.chunkcount += 1 141 | 142 | } 143 | //Avoid incurring in request entity too large by chunking assignment PUT requests in blocks of at most 128 chunks 144 | for k := 0; k < len(c.assignments); k += 128 { 145 | k2 := k + 128 146 | if k2 > len(c.assignments) { 147 | k2 = len(c.assignments) 148 | } 149 | client.AssignChunks(c.wrid, c.assignments[k:k2], c.assignments_offset[k:k2]) 150 | } 151 | 152 | client.CloseDynamicIndex(c.wrid, hex.EncodeToString(c.chunkdigests.Sum(nil)), c.pos, c.chunkcount) 153 | } 154 | 155 | 156 | 157 | func main() { 158 | var newchunk *atomic.Uint64 = new(atomic.Uint64) 159 | var reusechunk *atomic.Uint64 = new(atomic.Uint64) 160 | 161 | cfg := loadConfig() 162 | 163 | if ok := cfg.valid(); !ok { 164 | if runtime.GOOS == "windows" { 165 | usage := "All options are mandatory:\n" 166 | flag.VisitAll(func(f *flag.Flag) { 167 | usage += "-" + f.Name + " " + f.Usage + "\n" 168 | }) 169 | dialog.Error(usage) 170 | } else { 171 | fmt.Println("All options are mandatory") 172 | 173 | flag.PrintDefaults() 174 | } 175 | os.Exit(1) 176 | } 177 | 178 | L := Locking{} 179 | 180 | 181 | lock_ok := L.AcquireProcessLock() 182 | if !lock_ok { 183 | 184 | dialog.Error("Backup jobs need to run exclusively, please wait until the previous job has finished") 185 | os.Exit(2) 186 | } 187 | defer L.ReleaseProcessLock() 188 | if runtime.GOOS == "windows" { 189 | go systray.Run(func() { 190 | systray.SetIcon(ICON) 191 | systray.SetTooltip("PBSGO Backup running") 192 | beeep.Notify("Proxmox Backup Go", "Backup started", "") 193 | }, 194 | func() { 195 | 196 | }) 197 | } 198 | 199 | 200 | insecure := cfg.CertFingerprint != "" 201 | 202 | client := &PBSClient{ 203 | baseurl: cfg.BaseURL, 204 | certfingerprint: cfg.CertFingerprint, //"ea:7d:06:f9:87:73:a4:72:d0:e8:05:a4:b3:3d:95:d7:0a:26:dd:6d:5c:ca:e6:99:83:e4:11:3b:5f:10:f4:4b", 205 | authid: cfg.AuthID, 206 | secret: cfg.Secret, 207 | datastore: cfg.Datastore, 208 | namespace: cfg.Namespace, 209 | insecure: insecure, 210 | manifest: BackupManifest{ 211 | BackupID: cfg.BackupID, 212 | }, 213 | } 214 | hostname, err := os.Hostname() 215 | if err != nil { 216 | fmt.Println("Failed to retrieve hostname:", err) 217 | hostname = "unknown" 218 | } 219 | 220 | begin := time.Now() 221 | if cfg.BackupSourceDir != "" { 222 | err = backup(client, newchunk, reusechunk, cfg.PxarOut, cfg.BackupSourceDir) 223 | } else if cfg.BackupStreamName != "" { 224 | sn := cfg.BackupStreamName 225 | if ! strings.HasSuffix(sn, ".didx" ) { 226 | sn += ".didx" 227 | } 228 | fmt.Printf("Backing up from STDIN to %s", sn) 229 | err = backup_stream(client, newchunk, reusechunk, sn, os.Stdin ) 230 | 231 | }else{ 232 | panic("No backup dir or stream name specified, exiting") 233 | } 234 | 235 | 236 | end := time.Now() 237 | 238 | mailCtx := mailCtx{ 239 | NewChunks: newchunk.Load(), 240 | ReusedChunks: reusechunk.Load(), 241 | Error: err, 242 | Hostname: hostname, 243 | Datastore: cfg.Datastore, 244 | StartTime: begin, 245 | EndTime: end, 246 | } 247 | 248 | mailBodyTemplate := defaultMailBodyTemplate 249 | if cfg.SMTP != nil && cfg.SMTP.Template != nil && cfg.SMTP.Template.Body != "" { 250 | mailBodyTemplate = cfg.SMTP.Template.Body 251 | } 252 | 253 | fmt.Printf("New %d, Reused %d, backup took %s.\n", newchunk.Load(), reusechunk.Load(), end.Sub(begin)) 254 | var msg string 255 | msg, err = mailCtx.buildStr(mailBodyTemplate) 256 | if err != nil { 257 | fmt.Println("Cannot use custom mail body: " + err.Error()) 258 | msg, err = mailCtx.buildStr(defaultMailBodyTemplate) 259 | if err != nil { 260 | // this should never happen 261 | panic(err) 262 | } 263 | } 264 | if runtime.GOOS == "windows" { 265 | systray.Quit() 266 | beeep.Notify("Proxmox Backup Go", msg, "") 267 | } 268 | if cfg.SMTP != nil { 269 | var subject string 270 | 271 | mailSubjectTemplate := defaultMailSubjectTemplate 272 | if cfg.SMTP.Template != nil && cfg.SMTP.Template.Subject != "" { 273 | mailSubjectTemplate = cfg.SMTP.Template.Subject 274 | } 275 | 276 | subject, err = mailCtx.buildStr(mailSubjectTemplate) 277 | if err != nil { 278 | fmt.Println("Cannot use custom mail subject: " + err.Error()) 279 | msg, err = mailCtx.buildStr(defaultMailSubjectTemplate) 280 | if err != nil { 281 | // this should never happen 282 | panic(err) 283 | } 284 | } 285 | client, err := setupClient(cfg.SMTP.Host, cfg.SMTP.Port, cfg.SMTP.Username, cfg.SMTP.Password, cfg.SMTP.Insecure) 286 | if err != nil { 287 | fmt.Println("Cannot connect to mail server: " + err.Error()) 288 | os.Exit(1) 289 | } 290 | defer client.Quit() 291 | for _, ccc := range cfg.SMTP.Mails { 292 | err = sendMail(ccc.From, ccc.To, subject, msg, client) 293 | if err != nil { 294 | fmt.Println("Cannot send email: " + err.Error()) 295 | os.Exit(1) 296 | } 297 | } 298 | } 299 | 300 | } 301 | 302 | func backup_stream(client *PBSClient, newchunk, reusechunk *atomic.Uint64, filename string, stream io.Reader ) error { 303 | knownChunks := hashmap.New[string, bool]() 304 | client.Connect(false) 305 | previousDidx, err := client.DownloadPreviousToBytes(filename) 306 | if err != nil { 307 | return err 308 | } 309 | 310 | fmt.Printf("Downloaded previous DIDX: %d bytes\n", len(previousDidx)) 311 | 312 | if !bytes.HasPrefix(previousDidx, didxMagic) { 313 | fmt.Printf("Previous index has wrong magic (%s)!\n", previousDidx[:8]) 314 | 315 | } else { 316 | //Header as per proxmox documentation is fixed size of 4096 bytes, 317 | //then offset of type uint64 and sha256 digests follow , so 40 byte each record until EOF 318 | previousDidx = previousDidx[4096:] 319 | for i := 0; i*40 < len(previousDidx); i += 1 { 320 | e := DidxEntry{} 321 | e.offset = binary.LittleEndian.Uint64(previousDidx[i*40 : i*40+8]) 322 | e.digest = previousDidx[i*40+8 : i*40+40] 323 | shahash := hex.EncodeToString(e.digest) 324 | fmt.Printf("Previous: %s\n", shahash) 325 | knownChunks.Set(shahash, true) 326 | } 327 | } 328 | 329 | fmt.Printf("Known chunks: %d!\n", knownChunks.Len()) 330 | 331 | streamChunk := ChunkState{} 332 | streamChunk.Init(newchunk, reusechunk, knownChunks) 333 | 334 | streamChunk.wrid, err = client.CreateDynamicIndex(filename) 335 | if err != nil { 336 | return err 337 | } 338 | B := make([]byte, 65536) 339 | for { 340 | 341 | n, err := stream.Read(B) 342 | 343 | b := B[:n] 344 | 345 | streamChunk.HandleData(b, client) 346 | 347 | if err == io.EOF { 348 | break 349 | } 350 | } 351 | 352 | streamChunk.Eof(client) 353 | 354 | client.CloseDynamicIndex(streamChunk.wrid, hex.EncodeToString(streamChunk.chunkdigests.Sum(nil)), streamChunk.pos, streamChunk.chunkcount) 355 | 356 | err = client.UploadManifest() 357 | if err != nil { 358 | return err 359 | } 360 | 361 | return client.Finish() 362 | } 363 | 364 | func backup(client *PBSClient, newchunk, reusechunk *atomic.Uint64, pxarOut string, backupdir string) error { 365 | knownChunks := hashmap.New[string, bool]() 366 | 367 | fmt.Printf("Starting backup of %s\n", backupdir) 368 | 369 | backupdir = createVSSSnapshot(backupdir) 370 | //Remove VSS snapshot on windows, on linux for now NOP 371 | defer VSSCleanup() 372 | 373 | client.Connect(false) 374 | 375 | archive := &PXARArchive{} 376 | archive.archivename = "backup.pxar.didx" 377 | 378 | previousDidx, err := client.DownloadPreviousToBytes(archive.archivename) 379 | if err != nil { 380 | return err 381 | } 382 | 383 | fmt.Printf("Downloaded previous DIDX: %d bytes\n", len(previousDidx)) 384 | 385 | /*f2, _ := os.Create("test.didx") 386 | defer f2.Close() 387 | 388 | f2.Write(previous_didx)*/ 389 | 390 | /* 391 | Here we download the previous dynamic index to figure out which chunks are the same of what 392 | we are going to upload to avoid unnecessary traffic and compression cpu usage 393 | */ 394 | 395 | if !bytes.HasPrefix(previousDidx, didxMagic) { 396 | fmt.Printf("Previous index has wrong magic (%s)!\n", previousDidx[:8]) 397 | 398 | } else { 399 | //Header as per proxmox documentation is fixed size of 4096 bytes, 400 | //then offset of type uint64 and sha256 digests follow , so 40 byte each record until EOF 401 | previousDidx = previousDidx[4096:] 402 | for i := 0; i*40 < len(previousDidx); i += 1 { 403 | e := DidxEntry{} 404 | e.offset = binary.LittleEndian.Uint64(previousDidx[i*40 : i*40+8]) 405 | e.digest = previousDidx[i*40+8 : i*40+40] 406 | shahash := hex.EncodeToString(e.digest) 407 | fmt.Printf("Previous: %s\n", shahash) 408 | knownChunks.Set(shahash, true) 409 | } 410 | } 411 | 412 | fmt.Printf("Known chunks: %d!\n", knownChunks.Len()) 413 | f := &os.File{} 414 | if pxarOut != "" { 415 | f, err = os.Create(pxarOut) 416 | if err != nil { 417 | return err 418 | } 419 | defer f.Close() 420 | } 421 | /**/ 422 | 423 | pxarChunk := ChunkState{} 424 | pxarChunk.Init(newchunk, reusechunk, knownChunks) 425 | 426 | pcat1Chunk := ChunkState{} 427 | pcat1Chunk.Init(newchunk, reusechunk, knownChunks) 428 | 429 | pxarChunk.wrid, err = client.CreateDynamicIndex(archive.archivename) 430 | if err != nil { 431 | return err 432 | } 433 | pcat1Chunk.wrid, err = client.CreateDynamicIndex("catalog.pcat1.didx") 434 | if err != nil { 435 | return err 436 | } 437 | 438 | archive.writeCB = func(b []byte) { 439 | 440 | 441 | if pxarOut != "" { 442 | // TODO: error handling inside callback 443 | f.Write(b) 444 | } 445 | 446 | pxarChunk.HandleData(b, client) 447 | 448 | // 449 | } 450 | 451 | archive.catalogWriteCB = func(b []byte) { 452 | pcat1Chunk.HandleData(b, client) 453 | } 454 | 455 | //This is the entry point of backup job which will start streaming with the PCAT and PXAR write callback 456 | //Data to be hashed and eventuall uploaded 457 | 458 | archive.WriteDir(backupdir, "", true) 459 | 460 | 461 | pxarChunk.Eof(client) 462 | pcat1Chunk.Eof(client) 463 | 464 | 465 | 466 | err = client.UploadManifest() 467 | if err != nil { 468 | return err 469 | } 470 | 471 | return client.Finish() 472 | } 473 | -------------------------------------------------------------------------------- /nop_snapshot.go: -------------------------------------------------------------------------------- 1 | //go:build linux || darwin || freebsd || openbsd 2 | // +build linux darwin freebsd openbsd 3 | 4 | package main 5 | 6 | func createVSSSnapshot(path string) string { 7 | return path 8 | } 9 | 10 | func VSSCleanup() { 11 | } 12 | -------------------------------------------------------------------------------- /pbsapi.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "crypto/sha256" 7 | "crypto/tls" 8 | "crypto/x509" 9 | "encoding/binary" 10 | "encoding/hex" 11 | "encoding/json" 12 | "fmt" 13 | "hash/crc32" 14 | "io" 15 | "net" 16 | "net/http" 17 | "net/url" 18 | "os" 19 | "strings" 20 | "time" 21 | 22 | "github.com/klauspost/compress/zstd" 23 | "golang.org/x/net/http2" 24 | ) 25 | 26 | type IndexCreateResp struct { 27 | WriterID int `json:"data"` 28 | } 29 | 30 | type IndexPutReq struct { 31 | DigestList []string `json:"digest-list"` 32 | OffsetList []uint64 `json:"offset-list"` 33 | WriterID uint64 `json:"wid"` 34 | } 35 | 36 | type DynamicCloseReq struct { 37 | ChunkCount uint64 `json:"chunk-count"` 38 | CheckSum string `json:"csum"` 39 | Size uint64 `json:"size"` 40 | WriterID uint64 `json:"wid"` 41 | } 42 | 43 | type File struct { 44 | CryptMode string `json:"crypt-mode"` 45 | Csum string `json:"csum"` 46 | Filename string `json:"filename"` 47 | Size int64 `json:"size"` 48 | } 49 | 50 | type ChunkUploadStats struct { 51 | CompressedSize int64 `json:"compressed_size"` 52 | Count int `json:"count"` 53 | Duplicates int `json:"duplicates"` 54 | Size int64 `json:"size"` 55 | } 56 | 57 | type Unprotected struct { 58 | ChunkUploadStats ChunkUploadStats `json:"chunk_upload_stats"` 59 | } 60 | 61 | type BackupManifest struct { 62 | BackupID string `json:"backup-id"` 63 | BackupTime int64 `json:"backup-time"` 64 | BackupType string `json:"backup-type"` 65 | Files []File `json:"files"` 66 | Signature interface{} `json:"signature"` 67 | Unprotected Unprotected `json:"unprotected"` 68 | } 69 | 70 | type AuthErr struct { 71 | } 72 | 73 | func (e *AuthErr) Error() string { 74 | return "Authentication error" 75 | } 76 | 77 | type PBSClient struct { 78 | baseurl string 79 | certfingerprint string 80 | apitoken string 81 | secret string 82 | authid string 83 | 84 | datastore string 85 | namespace string 86 | manifest BackupManifest 87 | 88 | insecure bool 89 | 90 | client http.Client 91 | tlsConfig tls.Config 92 | 93 | writersManifest map[uint64]int 94 | } 95 | 96 | var blobCompressedMagic = []byte{49, 185, 88, 66, 111, 182, 163, 127} 97 | var blobUncompressedMagic = []byte{66, 171, 56, 7, 190, 131, 112, 161} 98 | 99 | func (pbs *PBSClient) CreateDynamicIndex(name string) (uint64, error) { 100 | 101 | req, err := http.NewRequest("POST", pbs.baseurl+"/dynamic_index", bytes.NewBuffer([]byte(fmt.Sprintf("{\"archive-name\": \"%s\"}", name)))) 102 | if err != nil { 103 | return 0, err 104 | } 105 | 106 | req.Header.Add("Authorization", fmt.Sprintf("PBSAPIToken=%s:%s", pbs.authid, pbs.secret)) 107 | req.Header.Set("Content-Type", "application/json; charset=UTF-8") 108 | 109 | resp2, err := pbs.client.Do(req) 110 | if err != nil { 111 | fmt.Println("Error making request:", err) 112 | return 0, err 113 | } 114 | 115 | if resp2.StatusCode != http.StatusOK { 116 | resp1, err := io.ReadAll(resp2.Body) 117 | fmt.Println("Error making request:", string(resp1), string(resp2.Proto)) 118 | return 0, err 119 | } 120 | 121 | resp1, err := io.ReadAll(resp2.Body) 122 | var R IndexCreateResp 123 | err = json.Unmarshal(resp1, &R) 124 | if err != nil { 125 | fmt.Println("Error parsing JSON:", err) 126 | return 0, err 127 | } 128 | fmt.Println("Writer id: ", R.WriterID) 129 | defer resp2.Body.Close() 130 | f := File{ 131 | CryptMode: "none", 132 | Csum: "", 133 | Filename: name, 134 | Size: 0, 135 | } 136 | pbs.manifest.Files = append(pbs.manifest.Files, f) 137 | pbs.writersManifest[uint64(R.WriterID)] = len(pbs.manifest.Files) - 1 138 | return uint64(R.WriterID), nil 139 | } 140 | 141 | func (pbs *PBSClient) UploadUncompressedChunk(writerid uint64, digest string, chunkdata []byte) error { 142 | outBuffer := make([]byte, 0) 143 | outBuffer = append(outBuffer, blobUncompressedMagic...) 144 | checksum := crc32.Checksum(chunkdata, crc32.IEEETable) 145 | outBuffer = binary.LittleEndian.AppendUint32(outBuffer, checksum) 146 | outBuffer = append(outBuffer, chunkdata...) 147 | 148 | q := &url.Values{} 149 | q.Add("digest", digest) 150 | q.Add("encoded-size", fmt.Sprintf("%d", len(outBuffer))) 151 | q.Add("size", fmt.Sprintf("%d", len(chunkdata))) 152 | q.Add("wid", fmt.Sprintf("%d", writerid)) 153 | 154 | req, err := http.NewRequest("POST", pbs.baseurl+"/dynamic_chunk?"+q.Encode(), bytes.NewBuffer(outBuffer)) 155 | if err != nil { 156 | return err 157 | } 158 | 159 | resp2, err := pbs.client.Do(req) 160 | if err != nil { 161 | fmt.Println("Error making request:", err) 162 | return err 163 | } 164 | 165 | if resp2.StatusCode != http.StatusOK { 166 | resp1, err := io.ReadAll(resp2.Body) 167 | fmt.Println("Error making request:", string(resp1), string(resp2.Proto)) 168 | return err 169 | } 170 | return nil 171 | } 172 | 173 | func (pbs *PBSClient) UploadCompressedChunk(writerid uint64, digest string, chunkdata []byte) error { 174 | outBuffer := make([]byte, 0) 175 | outBuffer = append(outBuffer, blobCompressedMagic...) 176 | compressedData := make([]byte, 0) 177 | 178 | //opt := zstd.WithEncoderLevel(zstd.SpeedFastest) 179 | w, _ := zstd.NewWriter(nil) 180 | compressedData = w.EncodeAll(chunkdata, compressedData) 181 | checksum := crc32.Checksum(compressedData, crc32.IEEETable) 182 | //binary.Write(outBuffer, binary.LittleEndian, checksum) 183 | outBuffer = binary.LittleEndian.AppendUint32(outBuffer, checksum) 184 | 185 | //fmt.Printf("Appended checksum %08x , len: %d\n", checksum, len(outBuffer)) 186 | 187 | outBuffer = append(outBuffer, compressedData...) 188 | 189 | if len(compressedData) > len(chunkdata) { 190 | pbs.UploadUncompressedChunk(writerid, digest, chunkdata) 191 | return nil 192 | } 193 | //fmt.Printf("Compressed: %d , Orig: %d\n", len(compressedData), len(chunkdata)) 194 | 195 | q := &url.Values{} 196 | q.Add("digest", digest) 197 | q.Add("encoded-size", fmt.Sprintf("%d", len(outBuffer))) 198 | q.Add("size", fmt.Sprintf("%d", len(chunkdata))) 199 | q.Add("wid", fmt.Sprintf("%d", writerid)) 200 | 201 | req, err := http.NewRequest("POST", pbs.baseurl+"/dynamic_chunk?"+q.Encode(), bytes.NewBuffer(outBuffer)) 202 | 203 | resp2, err := pbs.client.Do(req) 204 | if err != nil { 205 | fmt.Println("Error making request:", err) 206 | return err 207 | } 208 | 209 | if resp2.StatusCode != http.StatusOK { 210 | resp1, err := io.ReadAll(resp2.Body) 211 | fmt.Println("Error making request:", string(resp1), string(resp2.Proto)) 212 | return err 213 | } 214 | 215 | return nil 216 | } 217 | 218 | func (pbs *PBSClient) AssignChunks(writerid uint64, digests []string, offsets []uint64) error { 219 | indexput := &IndexPutReq{ 220 | WriterID: writerid, 221 | DigestList: digests, 222 | OffsetList: offsets, 223 | } 224 | 225 | jsondata, err := json.Marshal(indexput) 226 | if err != nil { 227 | return err 228 | } 229 | 230 | req, err := http.NewRequest("PUT", pbs.baseurl+"/dynamic_index", bytes.NewBuffer(jsondata)) 231 | if err != nil { 232 | return err 233 | } 234 | req.Header.Set("Content-Type", "application/json; charset=UTF-8") 235 | resp2, err := pbs.client.Do(req) 236 | if err != nil { 237 | fmt.Println("Error making request:", err) 238 | return err 239 | } 240 | defer resp2.Body.Close() 241 | return nil 242 | } 243 | 244 | func (pbs *PBSClient) CloseDynamicIndex(writerid uint64, checksum string, totalsize uint64, chunkcount uint64) error { 245 | finishreq := &DynamicCloseReq{ 246 | WriterID: writerid, 247 | CheckSum: checksum, 248 | Size: totalsize, 249 | ChunkCount: chunkcount, 250 | } 251 | jsonpayload, err := json.Marshal(finishreq) 252 | if err != nil { 253 | return err 254 | } 255 | req, err := http.NewRequest("POST", pbs.baseurl+"/dynamic_close", bytes.NewBuffer(jsonpayload)) 256 | if err != nil { 257 | return err 258 | } 259 | req.Header.Add("Authorization", fmt.Sprintf("PBSAPIToken=%s:%s", pbs.authid, pbs.secret)) 260 | req.Header.Set("Content-Type", "application/json; charset=UTF-8") 261 | 262 | resp2, err := pbs.client.Do(req) 263 | if err != nil { 264 | fmt.Println("Error making request:", err) 265 | return err 266 | } 267 | 268 | f := &pbs.manifest.Files[pbs.writersManifest[writerid]] 269 | 270 | f.Csum = checksum 271 | f.Size = int64(totalsize) 272 | 273 | defer resp2.Body.Close() 274 | return nil 275 | } 276 | 277 | func (pbs *PBSClient) UploadBlob(name string, data []byte) error { 278 | out := make([]byte, 0) 279 | out = append(out, blobUncompressedMagic...) 280 | 281 | checksum := crc32.ChecksumIEEE(data) 282 | out = binary.LittleEndian.AppendUint32(out, checksum) 283 | out = append(out, data...) 284 | 285 | q := &url.Values{} 286 | q.Add("encoded-size", fmt.Sprintf("%d", len(out))) 287 | q.Add("file-name", name) 288 | 289 | req, _ := http.NewRequest("POST", pbs.baseurl+"/blob?"+q.Encode(), bytes.NewBuffer(out)) 290 | 291 | resp2, err := pbs.client.Do(req) 292 | if err != nil { 293 | fmt.Println("Error making request:", err) 294 | return err 295 | } 296 | 297 | if resp2.StatusCode != http.StatusOK { 298 | resp1, err := io.ReadAll(resp2.Body) 299 | fmt.Println("Error making request:", string(resp1), string(resp2.Proto)) 300 | return err 301 | } 302 | 303 | return nil 304 | } 305 | 306 | func (pbs *PBSClient) UploadManifest() error { 307 | manifestBin, err := json.Marshal(pbs.manifest) 308 | if err != nil { 309 | return err 310 | } 311 | return pbs.UploadBlob("index.json.blob", manifestBin) 312 | } 313 | 314 | func (pbs *PBSClient) Finish() error { 315 | req, err := http.NewRequest("POST", pbs.baseurl+"/finish", nil) 316 | req.Header.Add("Authorization", fmt.Sprintf("PBSAPIToken=%s:%s", pbs.authid, pbs.secret)) 317 | if err != nil { 318 | return err 319 | } 320 | resp2, err := pbs.client.Do(req) 321 | if err != nil { 322 | fmt.Println("Error making request:", err) 323 | if err != nil { 324 | return err 325 | } 326 | } 327 | defer resp2.Body.Close() 328 | return nil 329 | } 330 | 331 | func (pbs *PBSClient) Connect(reader bool) { 332 | pbs.writersManifest = make(map[uint64]int) 333 | pbs.tlsConfig = tls.Config{ 334 | InsecureSkipVerify: pbs.insecure, 335 | } 336 | if pbs.insecure { 337 | pbs.tlsConfig.VerifyPeerCertificate = func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error { 338 | // Extract the peer certificate 339 | if len(rawCerts) == 0 { 340 | return fmt.Errorf("no certificates presented by the peer") 341 | } 342 | peerCert, err := x509.ParseCertificate(rawCerts[0]) 343 | if err != nil { 344 | return fmt.Errorf("failed to parse certificate: %v", err) 345 | } 346 | 347 | // Calculate the SHA-256 fingerprint of the certificate 348 | expectedFingerprint := strings.ReplaceAll(pbs.certfingerprint, ":", "") 349 | calculatedFingerprint := sha256.Sum256(peerCert.Raw) 350 | 351 | // Compare the calculated fingerprint with the expected one 352 | if hex.EncodeToString(calculatedFingerprint[:]) != expectedFingerprint { 353 | return fmt.Errorf("certificate fingerprint does not match (%s,%s)", expectedFingerprint, hex.EncodeToString(calculatedFingerprint[:])) 354 | } 355 | 356 | // If the fingerprint matches, the certificate is considered valid 357 | return nil 358 | } 359 | } 360 | 361 | pbs.manifest.BackupTime = time.Now().Unix() 362 | pbs.manifest.BackupType = "host" 363 | if pbs.manifest.BackupID == "" { 364 | hostname, _ := os.Hostname() 365 | pbs.manifest.BackupID = hostname 366 | } 367 | pbs.client = http.Client{ 368 | Transport: &http2.Transport{ 369 | 370 | DialTLSContext: func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) { 371 | 372 | //This is one of the trickiest parts, GO http2 library does not support starting with http1 and upgrading to 2 after 373 | //So to achieve that the function to create SSL socket has been hijacked here 374 | //Here an http 1.1 request to authenticate, start the backup and require upgrade to HTTP2 is done then the socket is passed to 375 | // http2.Transport handler 376 | conn, err := tls.Dial(network, addr, &pbs.tlsConfig) 377 | if err != nil { 378 | return nil, err 379 | } 380 | q := &url.Values{} 381 | q.Add("backup-time", fmt.Sprintf("%d", pbs.manifest.BackupTime)) 382 | q.Add("backup-type", pbs.manifest.BackupType) 383 | q.Add("store", pbs.datastore) 384 | if pbs.namespace != "" { 385 | q.Add("ns", pbs.namespace) 386 | } 387 | 388 | q.Add("backup-id", pbs.manifest.BackupID) 389 | q.Add("debug", "1") 390 | conn.Write([]byte("GET /api2/json/backup?" + q.Encode() + " HTTP/1.1\r\n")) 391 | conn.Write([]byte("Authorization: " + fmt.Sprintf("PBSAPIToken=%s:%s", pbs.authid, pbs.secret) + "\r\n")) 392 | if !reader { 393 | conn.Write([]byte("Upgrade: proxmox-backup-protocol-v1\r\n")) 394 | } else { 395 | conn.Write([]byte("Upgrade: proxmox-backup-reader-protocol-v1\r\n")) 396 | } 397 | conn.Write([]byte("Connection: Upgrade\r\n\r\n")) 398 | fmt.Printf("Reading response to upgrade...\n") 399 | buf := make([]byte, 0) 400 | for !strings.HasSuffix(string(buf), "\r\n\r\n") && !strings.HasSuffix(string(buf), "\n\n") { 401 | //fmt.Println(buf) 402 | b2 := make([]byte, 1) 403 | nbytes, err := conn.Read(b2) 404 | if err != nil || nbytes == 0 { 405 | fmt.Println("Connection unexpectedly closed") 406 | return nil, err 407 | } 408 | buf = append(buf, b2[:nbytes]...) 409 | 410 | //fmt.Println(string(b2)) 411 | } 412 | lines := strings.Split(string(buf), "\n") 413 | 414 | if len(lines) > 0 { 415 | toks := strings.Split(lines[0], " ") 416 | if len(toks) > 1 && toks[1] != "101" { 417 | fmt.Println("Unexpected response code: " + strings.Join(toks[1:], " ")) 418 | return nil, &AuthErr{} 419 | } 420 | } 421 | 422 | fmt.Printf("Upgraderesp: %s\n", string(buf)) 423 | fmt.Println("Successfully upgraded to HTTP/2.") 424 | return conn, nil 425 | }, 426 | }, 427 | } 428 | 429 | } 430 | 431 | func (pbs *PBSClient) DownloadPreviousToBytes(archivename string) ([]byte, error) { //In the future also download to tmp if index is extremely big... 432 | q := &url.Values{} 433 | 434 | q.Add("archive-name", archivename) 435 | 436 | req, err := http.NewRequest("GET", pbs.baseurl+"/previous?"+q.Encode(), nil) 437 | req.Header.Add("Authorization", fmt.Sprintf("PBSAPIToken=%s:%s", pbs.authid, pbs.secret)) 438 | if err != nil { 439 | return nil, err 440 | } 441 | resp2, err := pbs.client.Do(req) 442 | if err != nil { 443 | fmt.Println("Error making request:", err) 444 | return nil, err 445 | } 446 | defer resp2.Body.Close() 447 | 448 | ret, err := io.ReadAll(resp2.Body) 449 | 450 | if err != nil { 451 | return nil, err 452 | } 453 | 454 | return ret, nil 455 | 456 | } 457 | -------------------------------------------------------------------------------- /pxar.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/binary" 6 | "fmt" 7 | "math/bits" 8 | "os" 9 | "sort" 10 | 11 | // "io/ioutil" 12 | "path/filepath" 13 | 14 | "github.com/dchest/siphash" 15 | ) 16 | 17 | const ( 18 | PXAR_ENTRY uint64 = 0xd5956474e588acef 19 | PXAR_ENTRY_V1 uint64 = 0x11da850a1c1cceff 20 | PXAR_FILENAME uint64 = 0x16701121063917b3 21 | PXAR_SYMLINK uint64 = 0x27f971e7dbf5dc5f 22 | PXAR_DEVICE uint64 = 0x9fc9e906586d5ce9 23 | PXAR_XATTR uint64 = 0x0dab0229b57dcd03 24 | PXAR_ACL_USER uint64 = 0x2ce8540a457d55b8 25 | PXAR_ACL_GROUP uint64 = 0x136e3eceb04c03ab 26 | PXAR_ACL_GROUP_OBJ uint64 = 0x10868031e9582876 27 | PXAR_ACL_DEFAULT uint64 = 0xbbbb13415a6896f5 28 | PXAR_ACL_DEFAULT_USER uint64 = 0xc89357b40532cd1f 29 | PXAR_ACL_DEFAULT_GROUP uint64 = 0xf90a8a5816038ffe 30 | PXAR_FCAPS uint64 = 0x2da9dd9db5f7fb67 31 | PXAR_QUOTA_PROJID uint64 = 0xe07540e82f7d1cbb 32 | PXAR_HARDLINK uint64 = 0x51269c8422bd7275 33 | PXAR_PAYLOAD uint64 = 0x28147a1b0b7c1a25 34 | PXAR_GOODBYE uint64 = 0x2fec4fa642d5731d 35 | PXAR_GOODBYE_TAIL_MARKER uint64 = 0xef5eed5b753e1555 36 | ) 37 | 38 | var catalog_magic = []byte{145, 253, 96, 249, 196, 103, 88, 213} 39 | 40 | const ( 41 | IFMT uint64 = 0o0170000 42 | IFSOCK uint64 = 0o0140000 43 | IFLNK uint64 = 0o0120000 44 | IFREG uint64 = 0o0100000 45 | IFBLK uint64 = 0o0060000 46 | IFDIR uint64 = 0o0040000 47 | IFCHR uint64 = 0o0020000 48 | IFIFO uint64 = 0o0010000 49 | 50 | ISUID uint64 = 0o0004000 51 | ISGID uint64 = 0o0002000 52 | ISVTX uint64 = 0o0001000 53 | ) 54 | 55 | type MTime struct { 56 | secs uint64 57 | nanos uint32 58 | padding uint32 59 | } 60 | type PXARFileEntry struct { 61 | hdr uint64 62 | len uint64 63 | mode uint64 64 | flags uint64 65 | uid uint32 66 | gid uint32 67 | mtime MTime 68 | } 69 | 70 | type PXARFilenameEntry struct { 71 | hdr uint64 72 | len uint64 73 | } 74 | 75 | type GoodByeItem struct { 76 | hash uint64 77 | offset uint64 78 | len uint64 79 | } 80 | 81 | type GoodByeBST struct { 82 | self *GoodByeItem 83 | left *GoodByeBST 84 | right *GoodByeBST 85 | } 86 | 87 | func (B *GoodByeBST) AddNode(i *GoodByeItem) { 88 | if i.hash < B.self.hash { 89 | if B.left == nil { 90 | B.left = &GoodByeBST{ 91 | self: i, 92 | } 93 | } else { 94 | B.left.AddNode(i) 95 | } 96 | } 97 | if i.hash > B.self.hash { 98 | if B.right == nil { 99 | B.right = &GoodByeBST{ 100 | self: i, 101 | } 102 | } else { 103 | B.right.AddNode(i) 104 | } 105 | } 106 | } 107 | 108 | func pow_of_2(e uint64) uint64 { 109 | return 1 << e 110 | } 111 | 112 | func log_of_2(k uint64) uint64 { 113 | return 8*8 - uint64(bits.LeadingZeros64(k)) - 1 114 | } 115 | 116 | func make_bst_inner(input []GoodByeItem, n uint64, e uint64, output *[]GoodByeItem, i uint64) { 117 | if n == 0 { 118 | return 119 | } 120 | p := pow_of_2(e - 1) 121 | q := pow_of_2(e) 122 | var k uint64 123 | if n >= p-1+p/2 { 124 | k = (q - 2) / 2 125 | } else { 126 | v := p - 1 + p/2 - n 127 | k = (q-2)/2 - v 128 | } 129 | 130 | (*output)[i] = input[k] 131 | 132 | make_bst_inner(input, k, e-1, output, i*2+1) 133 | make_bst_inner(input[k+1:], n-k-1, e-1, output, i*2+2) 134 | } 135 | 136 | func ca_make_bst(input []GoodByeItem, output *[]GoodByeItem) { 137 | n := uint64(len(input)) 138 | make_bst_inner(input, n, log_of_2(n)+1, output, 0) 139 | } 140 | 141 | type PXAROutCB func([]byte) 142 | 143 | type PXARArchive struct { 144 | //Create(filename string, writeCB PXAROutCB) 145 | //AddFile(filename string) 146 | //AddDirectory(dirname string) 147 | writeCB PXAROutCB 148 | catalogWriteCB PXAROutCB 149 | buffer bytes.Buffer 150 | pos uint64 151 | archivename string 152 | 153 | catalog_pos uint64 154 | } 155 | 156 | //This function will flush the internal buffer and update position 157 | //WriteCB for pxar stream will be called. 158 | //It is useful when we building a data structure and we need to keep a specific offset and output it only at the end 159 | 160 | func (a *PXARArchive) Flush() { 161 | 162 | b := make([]byte, 64*1024) 163 | for { 164 | count, _ := a.buffer.Read(b) 165 | if count <= 0 { 166 | break 167 | } 168 | a.writeCB(b[:count]) 169 | a.pos = a.pos + uint64(count) 170 | } 171 | //fmt.Printf("Flush %d bytes\n", count) 172 | } 173 | 174 | func (a *PXARArchive) Create() { 175 | a.pos = 0 176 | a.catalog_pos = 8 177 | } 178 | 179 | type CatalogDir struct { 180 | Pos uint64 //Points to next table so parent has always to be written before children 181 | Name string 182 | } 183 | 184 | type CatalogFile struct { 185 | Name string 186 | MTime uint64 187 | Size uint64 188 | } 189 | 190 | func append_u64_7bit(a []byte, v uint64) []byte { 191 | x := a 192 | for { 193 | if v < 128 { 194 | x = append(x, byte(v&0x7f)) 195 | break 196 | } 197 | x = append(x, byte(v&0x7f)|byte(0x80)) 198 | v = v >> 7 199 | } 200 | return x 201 | } 202 | 203 | //PXAR format, documentation had many missing bits i had to figure out 204 | /* 205 | Suppose we have 206 | abc 207 | file.txt 208 | ced 209 | file2.txt 210 | file3.txt 211 | 212 | First entry is always without filename 213 | 214 | PXAR_ENTRY(DIR) 215 | PXAR_FILENAME(file.txt) 216 | PXAR_ENTRY(file, attributes etc) 217 | PXAR_PAYLOAD(file.txt) 218 | PXAR_FILENAME(ced) 219 | PXAR_FILENAME(file2.txt) 220 | PXAR_ENTRY(file,attributes etc) 221 | PXAR_PAYLOAD(file2.txt) 222 | PXAR_FILENAME(file3.txt) 223 | PXAR_ENTRY(file,attributes etc) 224 | PXAR_PAYLOAD(file3.txt) 225 | PXAR_GOODBYE( relative to ced 226 | will have entries sorted using casync algorithms below 227 | for sip hash of "file2.txt" and "file3.txt", offset is relative to PXAR_GOODBYE header offset 228 | last special entry with fixed hash and not sorted 229 | ) 230 | PXAR_GOODBYE(relative to abc or top dir ) 231 | will have entries sorted using casync algorithms below 232 | for sip hash of "file.txt" and "ced", offset is relative to PXAR_GOODBYE header offset 233 | last special entry with fixed hash and not sorted 234 | ) 235 | 236 | */ 237 | 238 | func (a *PXARArchive) WriteDir(path string, dirname string, toplevel bool) CatalogDir { 239 | //fmt.Printf("Write dir %s at %d\n", path, a.pos) 240 | files, err := os.ReadDir(path) 241 | if err != nil { 242 | return CatalogDir{} 243 | } 244 | 245 | fileInfo, err := os.Stat(path) 246 | if err != nil { 247 | fmt.Printf("Failed to stat %s\n", path) 248 | return CatalogDir{} 249 | } 250 | 251 | //Avoid writing filename entry on root 252 | if !toplevel { 253 | fname_entry := &PXARFilenameEntry{ 254 | hdr: PXAR_FILENAME, 255 | len: uint64(16) + uint64(len(dirname)) + 1, 256 | } 257 | 258 | binary.Write(&a.buffer, binary.LittleEndian, fname_entry) 259 | 260 | a.buffer.WriteString(dirname) 261 | a.buffer.WriteByte(0x00) 262 | } else { 263 | if a.catalogWriteCB != nil { 264 | a.catalogWriteCB(catalog_magic) 265 | a.catalog_pos = 8 266 | } 267 | } 268 | 269 | a.Flush() 270 | 271 | dir_start_pos := a.pos 272 | 273 | entry := &PXARFileEntry{ 274 | hdr: PXAR_ENTRY, 275 | len: 56, 276 | mode: IFDIR | 0o777, 277 | flags: 0, 278 | uid: 1000, //This is fixed because this project for now targeting windows , on which execute, traverse etc permissions don't exist 279 | gid: 1000, 280 | mtime: MTime{ 281 | secs: uint64(fileInfo.ModTime().Unix()), 282 | nanos: 0, 283 | padding: 0, 284 | }, 285 | } 286 | binary.Write(&a.buffer, binary.LittleEndian, entry) 287 | 288 | a.Flush() 289 | 290 | goodbyteitems := make([]GoodByeItem, 0) 291 | catalog_files := make([]CatalogFile, 0) 292 | catalog_dirs := make([]CatalogDir, 0) 293 | 294 | for _, file := range files { 295 | startpos := a.pos 296 | if file.IsDir() { 297 | 298 | D := a.WriteDir(filepath.Join(path, file.Name()), file.Name(), false) 299 | catalog_dirs = append(catalog_dirs, D) 300 | goodbyteitems = append(goodbyteitems, GoodByeItem{ 301 | offset: startpos, 302 | hash: siphash.Hash(0x83ac3f1cfbb450db, 0xaa4f1b6879369fbd, []byte(file.Name())), 303 | len: a.pos - startpos, 304 | }) 305 | } else { 306 | F := a.WriteFile(filepath.Join(path, file.Name()), file.Name()) 307 | 308 | catalog_files = append(catalog_files, F) 309 | goodbyteitems = append(goodbyteitems, GoodByeItem{ 310 | offset: startpos, 311 | hash: siphash.Hash(0x83ac3f1cfbb450db, 0xaa4f1b6879369fbd, []byte(file.Name())), 312 | len: a.pos - startpos, 313 | }) 314 | } 315 | } 316 | 317 | //Here we can write AFTER the recursion so leaves get written first 318 | //We need to write leaves first because otherwise we won't know offsets 319 | oldpos := a.catalog_pos 320 | tabledata := make([]byte, 0) 321 | tabledata = append_u64_7bit(tabledata, uint64(len(catalog_files)+len(catalog_dirs))) 322 | for _, d := range catalog_dirs { 323 | tabledata = append(tabledata, 'd') 324 | tabledata = append_u64_7bit(tabledata, uint64(len(d.Name))) 325 | tabledata = append(tabledata, []byte(d.Name)...) 326 | tabledata = append_u64_7bit(tabledata, oldpos-d.Pos) 327 | } 328 | 329 | for _, f := range catalog_files { 330 | tabledata = append(tabledata, 'f') 331 | tabledata = append_u64_7bit(tabledata, uint64(len(f.Name))) 332 | tabledata = append(tabledata, []byte(f.Name)...) 333 | tabledata = append_u64_7bit(tabledata, f.Size) 334 | tabledata = append_u64_7bit(tabledata, f.MTime) 335 | } 336 | 337 | catalog_outdata := make([]byte, 0) 338 | catalog_outdata = append_u64_7bit(catalog_outdata, uint64(len(tabledata))) 339 | catalog_outdata = append(catalog_outdata, tabledata...) 340 | 341 | if a.catalogWriteCB != nil { 342 | a.catalogWriteCB(catalog_outdata) 343 | 344 | } 345 | 346 | a.catalog_pos += uint64(len(catalog_outdata)) 347 | 348 | a.Flush() 349 | 350 | //Sort goodbyeitems by sip hash to build later kinda of heap 351 | 352 | sort.Slice(goodbyteitems, func(i, j int) bool { 353 | return goodbyteitems[i].hash < goodbyteitems[j].hash 354 | }) 355 | 356 | goodbyteitemsnew := make([]GoodByeItem, len(goodbyteitems)) 357 | 358 | //Make casync binary search tree structure out of the sorted array 359 | 360 | ca_make_bst(goodbyteitems, &goodbyteitemsnew) 361 | 362 | goodbyteitems = goodbyteitemsnew 363 | 364 | a.Flush() 365 | goodbye_start := a.pos 366 | 367 | binary.Write(&a.buffer, binary.LittleEndian, PXAR_GOODBYE) 368 | goodbyelen := uint64(16 + 24*(len(goodbyteitems)+1)) 369 | binary.Write(&a.buffer, binary.LittleEndian, goodbyelen) 370 | 371 | for _, gi := range goodbyteitems { 372 | gi.offset = a.pos - gi.offset 373 | binary.Write(&a.buffer, binary.LittleEndian, gi) 374 | } 375 | 376 | gi := &GoodByeItem{ 377 | offset: goodbye_start - dir_start_pos, 378 | len: goodbyelen, 379 | hash: 0xef5eed5b753e1555, 380 | } 381 | 382 | binary.Write(&a.buffer, binary.LittleEndian, gi) 383 | 384 | a.Flush() 385 | 386 | if toplevel { 387 | //We write special pointer to root dir here 388 | 389 | tabledata := make([]byte, 0) 390 | tabledata = append_u64_7bit(tabledata, uint64(1)) 391 | tabledata = append(tabledata, 'd') 392 | tabledata = append_u64_7bit(tabledata, uint64(len(a.archivename))) 393 | tabledata = append(tabledata, []byte(a.archivename)...) 394 | tabledata = append_u64_7bit(tabledata, a.catalog_pos-oldpos) 395 | catalog_outdata := make([]byte, 0) 396 | catalog_outdata = append_u64_7bit(catalog_outdata, uint64(len(tabledata))) 397 | catalog_outdata = append(catalog_outdata, tabledata...) 398 | ptr := make([]byte, 0) 399 | ptr = binary.LittleEndian.AppendUint64(ptr, a.catalog_pos) 400 | if a.catalogWriteCB != nil { 401 | a.catalogWriteCB(catalog_outdata) 402 | a.catalogWriteCB(ptr) 403 | } 404 | } 405 | 406 | return CatalogDir{ 407 | Name: dirname, 408 | Pos: oldpos, 409 | } 410 | } 411 | 412 | // On pxar first item and consquently entry point must always be WriteDir , because toplevel is always a directory 413 | // So backing up single file is not possible 414 | func (a *PXARArchive) WriteFile(path string, basename string) CatalogFile { 415 | //fmt.Printf("Write file %s at %d\n", path, a.pos) 416 | fileInfo, err := os.Stat(path) 417 | if err != nil { 418 | fmt.Printf("Failed to stat %s\n", path) 419 | return CatalogFile{} 420 | } 421 | 422 | file, err := os.Open(path) 423 | 424 | if err != nil { 425 | fmt.Printf("Failed to open %s\n", path) 426 | return CatalogFile{} 427 | } 428 | 429 | defer file.Close() 430 | 431 | fname_entry := &PXARFilenameEntry{ 432 | hdr: PXAR_FILENAME, 433 | len: uint64(16) + uint64(len(basename)) + 1, 434 | } 435 | 436 | binary.Write(&a.buffer, binary.LittleEndian, fname_entry) 437 | 438 | a.buffer.WriteString(basename) 439 | a.buffer.WriteByte(0x00) 440 | 441 | entry := &PXARFileEntry{ 442 | hdr: PXAR_ENTRY, 443 | len: 56, 444 | mode: IFREG | 0o777, 445 | flags: 0, 446 | uid: 1000, 447 | gid: 1000, 448 | mtime: MTime{ 449 | secs: uint64(fileInfo.ModTime().Unix()), 450 | nanos: 0, 451 | padding: 0, 452 | }, 453 | } 454 | binary.Write(&a.buffer, binary.LittleEndian, entry) 455 | 456 | binary.Write(&a.buffer, binary.LittleEndian, PXAR_PAYLOAD) 457 | filesize := uint64(fileInfo.Size()) + 16 //File size + header size 458 | binary.Write(&a.buffer, binary.LittleEndian, filesize) 459 | 460 | a.Flush() 461 | 462 | readbuffer := make([]byte, 1024*64) 463 | 464 | for { 465 | nread, err := file.Read(readbuffer) 466 | if nread <= 0 { 467 | break 468 | } 469 | if err != nil { 470 | panic(err.Error()) 471 | } 472 | a.buffer.Write(readbuffer[:nread]) 473 | a.Flush() 474 | } 475 | 476 | a.Flush() 477 | 478 | return CatalogFile{ 479 | Name: basename, 480 | MTime: uint64(fileInfo.ModTime().Unix()), 481 | Size: uint64(fileInfo.Size()), 482 | } 483 | } 484 | -------------------------------------------------------------------------------- /stub_locking.go: -------------------------------------------------------------------------------- 1 | //go:build linux || darwin || freebsd || openbsd 2 | // +build linux darwin freebsd openbsd 3 | 4 | package main 5 | 6 | type Locking struct { 7 | mutexid uintptr 8 | } 9 | 10 | func (l *Locking) AcquireProcessLock() bool { 11 | return true 12 | } 13 | 14 | func (l *Locking) ReleaseProcessLock() { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /win_locking.go: -------------------------------------------------------------------------------- 1 | //go:build windows 2 | // +build windows 3 | package main 4 | 5 | import "github.com/rodolfoag/gow32" 6 | import "syscall" 7 | 8 | const MutexName = "proxmoxbackupclient_go" 9 | 10 | 11 | type Locking struct { 12 | mutexid uintptr 13 | } 14 | 15 | func (l *Locking) AcquireProcessLock() bool { 16 | mutexid , err := gow32.CreateMutex(MutexName) 17 | if err != nil { 18 | if exitcode := int(err.(syscall.Errno)); exitcode == gow32.ERROR_ALREADY_EXISTS { 19 | return false 20 | } 21 | panic(err) 22 | } 23 | l.mutexid = mutexid 24 | return true 25 | } 26 | 27 | func (l * Locking) ReleaseProcessLock() { 28 | gow32.ReleaseMutex(l.mutexid) 29 | } -------------------------------------------------------------------------------- /win_snapshot.go: -------------------------------------------------------------------------------- 1 | //go:build windows 2 | // +build windows 3 | 4 | package main 5 | 6 | import ( 7 | "fmt" 8 | "os" 9 | "os/user" 10 | "path/filepath" 11 | 12 | vss "github.com/jeromehadorn/vss" 13 | ) 14 | 15 | func SymlinkSnapshot(symlinkPath string, id string, deviceObjectPath string) (string, error) { 16 | 17 | snapshotSymLinkFolder := symlinkPath + "\\" + id + "\\" 18 | 19 | snapshotSymLinkFolder = filepath.Clean(snapshotSymLinkFolder) 20 | os.RemoveAll(snapshotSymLinkFolder) 21 | if err := os.MkdirAll(snapshotSymLinkFolder, 0700); err != nil { 22 | return "", fmt.Errorf("failed to create snapshot symlink folder for snapshot: %s, err: %s", id, err) 23 | } 24 | 25 | os.Remove(snapshotSymLinkFolder) 26 | 27 | fmt.Println("Symlink from: ", deviceObjectPath, " to: ", snapshotSymLinkFolder) 28 | 29 | if err := os.Symlink(deviceObjectPath, snapshotSymLinkFolder); err != nil { 30 | return "", fmt.Errorf("failed to create symlink from: %s to: %s, error: %s", deviceObjectPath, snapshotSymLinkFolder, err) 31 | } 32 | 33 | return snapshotSymLinkFolder, nil 34 | } 35 | 36 | func getAppDataFolder() (string, error) { 37 | // Get information about the current user 38 | currentUser, err := user.Current() 39 | if err != nil { 40 | return "", err 41 | } 42 | 43 | // Construct the path to the application data folder 44 | appDataFolder := filepath.Join(currentUser.HomeDir, "AppData", "Roaming", "PBSBackupGO") 45 | 46 | // Create the folder if it doesn't exist 47 | err = os.MkdirAll(appDataFolder, os.ModePerm) 48 | if err != nil { 49 | return "", err 50 | } 51 | 52 | return appDataFolder, nil 53 | } 54 | 55 | func createVSSSnapshot(path string) string { 56 | 57 | path, _ = filepath.Abs(path) 58 | volName := filepath.VolumeName(path) 59 | volName += "\\" 60 | subPath := path[len(volName):] //Strp C:\, 3 chars or whatever it is 61 | 62 | appDataFolder, err := getAppDataFolder() 63 | if err != nil { 64 | fmt.Println("Error:", err) 65 | return path 66 | } 67 | 68 | sn := vss.Snapshotter{} 69 | snapid, err := os.ReadFile(filepath.Join(appDataFolder, "temp_snapshot_id.txt")) 70 | if err == nil { 71 | snapid_str := string(snapid) 72 | 73 | fmt.Printf("Found leftover snapshot, deleting it...\n") 74 | 75 | sn.DeleteSnapshot(snapid_str) 76 | 77 | os.Remove(filepath.Join(appDataFolder, "temp_snapshot_id.txt")) 78 | } 79 | 80 | fmt.Printf("Creating VSS Snapshot...") 81 | snapshot, err := sn.CreateSnapshot(volName, 180, true) 82 | if err != nil { 83 | panic(err) 84 | } 85 | fmt.Printf("Snapshot created: %s\n", snapshot.Id) 86 | 87 | f, err := os.Create(filepath.Join(appDataFolder, "temp_snapshot_id.txt")) 88 | if err != nil { 89 | sn.DeleteSnapshot(snapshot.Id) 90 | panic(err) 91 | } 92 | 93 | f.WriteString(snapshot.Id) 94 | f.Close() 95 | 96 | _, err = SymlinkSnapshot(filepath.Join(appDataFolder, "VSS"), snapshot.Id, snapshot.DeviceObjectPath) 97 | 98 | if err != nil { 99 | sn.DeleteSnapshot(snapshot.Id) 100 | os.Remove(filepath.Join(appDataFolder, "temp_snapshot_id.txt")) 101 | panic(err) 102 | } 103 | 104 | return filepath.Join(appDataFolder, "VSS", snapshot.Id, subPath) 105 | 106 | } 107 | 108 | func VSSCleanup() { 109 | appDataFolder, err := getAppDataFolder() 110 | if err != nil { 111 | fmt.Println("Error:", err) 112 | return 113 | } 114 | sn := vss.Snapshotter{} 115 | snapid, err := os.ReadFile(filepath.Join(appDataFolder, "temp_snapshot_id.txt")) 116 | if err == nil { 117 | snapid_str := string(snapid) 118 | 119 | fmt.Printf("Found leftover snapshot, deleting it...\n") 120 | 121 | sn.DeleteSnapshot(snapid_str) 122 | 123 | os.Remove(filepath.Join(appDataFolder, "temp_snapshot_id.txt")) 124 | } 125 | } 126 | --------------------------------------------------------------------------------