Pectojin / duplicati-client

A command line client for controlling the Duplicati Server
GNU Lesser General Public License v2.1
75 stars 20 forks source link

Duplicati Client

The Duplicati Client connects to Duplicati servers remotely or locally and helps manage them easily through the command-line.

A note on maintenance status

I don't really use duplicati anymore, so maintaining this tool has low priority for me. I probably won't add new features or fix unimportant bugs. I might help out with troubleshooting issues, but I won't make promises.

To my knowledge the tool works fine on all platforms it has been used on, and it is fairly feature complete, so this isn't a declaration of deprecation.. It is just a formal statement about my reprioritization.

Table of contents

Why use Duplicati Client?

Duplicati ships with a CommandLine tool that is capable of doing various actions like backups, restores, and verifying backend data.

However, the Duplicati CommandLine is a separate program. It does not communicate with the Duplicati Server that you interact with when using the web UI.

This plays out in various ways when trying to manually initiate a backup using the CommandLine tool and the Duplicati server not updating it's metadata or even showing that a backup is happening.

Additionally, the CommandLine is stateless in the sense that you need to provide all the relevant information each time you want to run a command. This can be daunting if you just want to initiate a backup run on an existing backup.

The Duplicati Client is a cross platform command-line tool that allows you to interact with the Duplicati Server as if you were using the web UI. It interacts with the same REST API as the web UI, which means it will behave the same and can be used from practically any machine that the web UI can be used from.

Furthermore, this tool makes it easy to write custom scripts for use in cron jobs or ad-hoc tasks. You can simply call the Client from your script or cron job as most options can be provided inline by the script. Even if your Duplicati Server is password protected your scripts can easily log in by using a parametersfile.

External libraries used

Currently the script relies on multiple external libraries:

requests
PyYaml
python-dateutil

Installation

From source

Clone the repo

git clone https://github.com/pectojin/duplicati-client

The client runs on Python 3 and requires the above dependencies

pip3 install -r requirements.txt

For convenience you can symlink the client

sudo ln -s /location/of/git/repo/duplicati_client.py /usr/bin/duc

On UNIX it should automatically attempt to use Python on your system so now you can just call

duc

And you're good to go.

Windows self contained binary

For installation of the Windows self contained binary package I recommend copying it to C:\Program Files\Duplicati Client and then adding that path to your environment variable path so that you can call duplicati_client from anywhere in your CLI.

GNU/Linux and macOS self contained binaries

Self contained binaries are also available for Linux and macOS.

These are useful if you cannot or will not install the 3rd party dependencies on your system, or if you experience compatibility problems with your current Python installation.

I recommend copying the binary package to /opt/duplicati_client on Linux and /Applications/Duplicati Client on macOS. Then symlink the duplicati_client binary

sudo ln -s /location/of/duplicati_client /usr/bin/duc

Usage

To begin log into a server:

duc login https://my.duplicati.server

Then you can list resources

duc list backups

Get info

duc get backup 1

Run a backup job

duc run 1

Logout when you're done

duc logout

Supported commands

list      list all resources of a given type
get       display breif information on one or many resources
describe  display detailed information on a specific resource
set       set values on resources
run       run a backup job
abort     abort a task
create    create a resource on the server from a YAMl or JSON file
update    update a resource on the server from a YAMl or JSON file
delete    delete a resource on the server
export    export a backup from the server to YAMl or JSON format
repair    repair a database
vacuum    vacuum a database
verify    verify remote backup data
compact   compact remote backup data
dismiss   dismiss notifications
logs      display the logs for a given job
login     log into a Duplicati server
logout    end the current server session
status    print information about the current session
version   print version number
config    print the config
verbose   change between normal and verbose mode
precise   change between short and precise time format
params    import parameters from a YAML file
pause     pause Duplicati server
resume    resume paused Duplicati server

Setting the server password

It's possible to configure a server password using the set password command.

duc set password

It will prompt for the new password and configure it on the server. You can also provide it inline using --password or using a parameters file.

You can disable the password using --disable

duc set password --disable

Additionally, the set password command will remove the password-protection prompt ("If your machine is in a multi-user environment..."), so if you just want to pre-configure a system to remove that message you can make the --disable call to remove this message.

Parameters file

Using the command params you can specify a parameters file. With this file you can provide most of the optional CLI arguments without having to specify them inline when calling your commands.

The parameters file is set once using the params command and then automatically loaded on each call.

You must create the parameters file yourself. An example of a parameters file:

password: verysecretpassword
verbose: True

Then specify that you want to use a parameters file

duc params ~/.config/duplicati-client/parameters.yml

This will load your password, set verbose mode, and allow insecure connections by default when you run a command.

Loaded 3 parameters from ~/.config/duplicati-client/parameters.yml

Then, if you're connecting to a different server, simply override the default password by adding the --password argument in the CLI.

duc login localhost --password=othersecretpassword

Verbose is an exception to this rule. It applies session wide and can only be toggled by calling the verbose command, which is nonsensical if you have a parameters file enabling it again.

If you need to disable your parameters file, run

duc params --disable

Export backups

The export command enables building backup configuration files through the CLI. The Duplicati client will pull the necessary information on the selected backup and construct a configuration file. The configuration file can be exported in either YAML or JSON depending on preference

duc export backup [id]

By default the client will export YAML, but you can manually specify either with --output. Additionally you can specify the output path with --output-path. You can also opt to export all backup configs using --all.

The resulting file can then be used to create new backup jobs with the import command. Notice that the JSON output is identical to exporting from the Duplicati Web UI, so if you need interoperability use JSON. The YAML file is only understood by this client for now.

Default options defined in settings are not exported with the job configuration.

Create and update backups

The Create command allows creating backup jobs from a configuration file. Either a JSON file, as exported from the Duplicati Web UI, or a YAML/JSON file exported from this client. Input files are automatically converted into the JSON format that the Duplicati server requires, so it does not matter which format you import from.

duc create backup [path_to_file]

By default metadata will not be imported, but if you'd like to retain the metadata use --import-metadata

The Update command allows updating an existing job from a configuration file.

duc update backup [backup_id] [path_to_file]

Duplicati does not currently allow to update a backup configuration without also overwriting the metadata. If your config file was exported a long time ago with old metadata you may not be interested in this.

Apply the --strip-metadata option to remove the metadata before updating the backup config. This way no metadata will be displayed until the backup job has had a chance to run and provide the correct metadata.

Encrypted configuration files are currently not supported.

A note on versioning

duplicati-client will maintain a 0.x release status until Duplicati leaves beta. It's just not logical to make a "stable release" of a tool that interacts with product with no stable release. With that being said the Duplicati API has never broken duplicati-client with changes.

Every 0.x change indicates a larger change in user interface or addition of features.

0.x.x changes indicates small bug fixes and changes that shouldn't be noticable. Every "unit" of change increments this value, so a change from 0.x.1 to 0.x.5 indicates 4 separate logical units of change.

Building releases

Releases are built in a fairly simple manner using a script for each platform located in the scripts/ folder:

scripts/general_build.sh  scripts/linux_build.sh  scripts/macos_build.sh  scripts/windows_build.sh

All of the scripts rely on python and the packages declared in build-requirements.txt. Furthermore a comprimise has been made for the windows packaging using cygwin instead of writing a windows native script.

After setting up the dependencies simply run the script and the release packages can be found in script/releases:

% cd scripts
% bash ./general_build.sh

Build version: 0.6.3
Creating release folder and copying files...
Packing release into a zip archive...
Done!
% ls releases
duplicati_client_0.6.3_general  duplicati_client_0.6.3_general.zip

PyInstaller takes care of bundling the application and all dependencies into a single binary that can be run without python installed.