Skip to content

Instantly share code, notes, and snippets.

@matushorvath
Last active February 25, 2025 04:03
Show Gist options
  • Save matushorvath/dd7148c201ceae03ddebc1b4bbef4d20 to your computer and use it in GitHub Desktop.
Save matushorvath/dd7148c201ceae03ddebc1b4bbef4d20 to your computer and use it in GitHub Desktop.
Kopia as Windows Service

Pre-requisites:

  1. Install Kopia. In this example, I have installed KopiaUI to C:\Program Files\KopiaUI.
  2. Download Shawl from https://github.com/mtkennerly/shawl.
  3. Place shawl.exe in a suitable directory. In this example, shawl was placed to C:\Program Files\Shawl\shawl.exe.
  4. Create a directory to store Kopia data files. In this example, we are using C:\ProgramData\kopia

First, we will set up Kopia and check that it's working as a regular application:

  1. Create a htpasswd file, with a user called kopia and a secure password. Place the file in C:\ProgramData\kopia\htpasswd. Creating a htpasswd file on Windows is not very straightforward. If you have access to a Linux system, you can generate it there and copy it to your Windows machine

    $ htpasswd -c ./htpasswd kopia
  2. Start Kopia for the first time, with a --tls-generate-cert parameter:

    C:\>kopia server start --tls-cert-file C:\ProgramData\kopia\kopia.cert --tls-key-file C:\ProgramData\kopia\kopia.key --htpasswd-file C:\ProgramData\kopia\htpasswd --address https://0.0.0.0:51515 --tls-generate-cert

    This will generate a TLS certificate in C:\ProgramData\kopia.

    If you have Windows Firewall enabled, it should now pop up with a window asking you to allow network access for Kopia. This is needed for Kopia web-based UI to be accessible from other machines; if you don't need that, you can ignore the Firewall pop-up and close it.

  3. Open your web browser, navigate to https://localhost:51515. The TLS certificate will be self-signed, so your browser will warn you about it not being secure. This is expected, you can safely ignore the warning and add an exception.

    You should be able to log in with the kopia user and the password you stored in the htpasswd file, and then see the Kopia UI in your browser.

  4. Stop Kopia by pressing Ctrl+C.

Next we will configure Shawl to run Kopia as a Windows service.

  1. Start a command line as Administrator. You need to have Administrator rights to install and maintain Windows services.

  2. Add Kopia as a Windows service using Shawl:

    C:\>"C:\Program Files\Shawl\shawl.exe" add --cwd C:\ProgramData\kopia --log-dir C:\ProgramData\kopia\logs --name Kopia -- "C:\Program Files\KopiaUI\resources\server\kopia.exe" server start --tls-cert-file kopia.cert --tls-key-file kopia.key --htpasswd-file htpasswd --address https://0.0.0.0:51515

    (add --enable-actions to the command line if you wish to enable actions)

  3. Configure the service to start automatically during boot, and then start it immediately.

    C:\>sc config Kopia start=auto
    C:\>sc start Kopia
  4. Check if the service is running:

    C:\>sc query Kopia
    
    SERVICE_NAME: Kopia
            TYPE               : 10  WIN32_OWN_PROCESS
            STATE              : 4  RUNNING
                                    (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
            WIN32_EXIT_CODE    : 0  (0x0)
            SERVICE_EXIT_CODE  : 0  (0x0)
            CHECKPOINT         : 0x0
            WAIT_HINT          : 0x0
  5. Open your web browser, again navigate to https://localhost:51515. You should be able to log in to Kopia running as a Windows service. Now proceed to configure Kopia using the web UI as usual.

  6. (Optional) Reboot your computer and verify that Kopia starts automatically as a service.

(consider this text public domain)

@matushorvath
Copy link
Author

@abjoseph

  1. I did not run that command. I guess the way I ran that command, it probably launched another instance of the kopia server and performed the command (so it did not connect to the instance it was already running). But that's literally just a guess, I don't know enough about kopia to understand what the "repository connect server" command does.
  2. I copied the command line from the web UI. On most pages there is the small yellow button that reveals a command line, see attached screenshot.
    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment