Duplicacy pre/post scripts environment variables

Hello,

I recently purchased duplicacy web, switching from Duplicati and found out I can run pre/post scripts before and after my backup jobs. I need these scripts since I use ZFS, to create a ZFS snapshot and then change the backup directory to that snapshot mount to backup. Then the post script removes the snapshot.

Duplicati, in it’s pre post scripts have built in environment variables, specifically the variable “DUPLICATI__LOCALPATH”. This allows you to tell Duplicati to actually backup from a different directory after the backup has started, allowing the configuration to keep the original location of the files, making restores among other operations more convenient.

Does Duplicacy have similar options for me to configure so that I can use ZFS snapshots with duplicacy web? I have posted an example script I used with Duplicati below.

Thank you,

[root@server /]# cat /mnt/ssd/bin/duplicati_snapshot_create_mount
#!/usr/bin/env bash

ZFS_FS_NAME=$1
ZFS_SNAPSHOT_NAME=$2
MOUNT_PATH="/mnt/tmp/snapshot"

if [[ ! -z "$(ls -A $MOUNT_PATH)" ]]; then
    printf "[ERROR] The backup mount directory, $MOUNT_PATH is not empty.\n"
    exit 1
fi
if [[ -z "$(zfs list | grep $ZFS_FS_NAME)" ]]; then
    printf "[ERROR] The ZFS filesystem $ZFS_FS_NAME does not exist.\n"
    exit 1
fi
if [[ ! -z "$(zfs list -t snapshot | grep "$ZFS_FS_NAME@$ZFS_SNAPSHOT_NAME")" ]]; then
    printf "[ERROR] The ZFS snapshot $ZFS_SNAPSHOT_NAME already exists.\n"
    exit 1
fi

zfs snapshot -r "$ZFS_FS_NAME@$ZFS_SNAPSHOT_NAME"
mount -t zfs "$ZFS_FS_NAME@$ZFS_SNAPSHOT_NAME" "$MOUNT_PATH"
echo "--localpath=\"$MOUNT_PATH\""

if [[ -z "$(ls -A $MOUNT_PATH)" ]]; then
    printf "[ERROR] Snapshot was created but failed to mount. (empty directory)\n"
    exit 1
fi

printf "[INFO] Snapshot was created and mounted. Ready for duplicati.\n"

exit 0

Two options.

  1. In the .duplicacy/preferences file the key repository points to the repository root. So, in the pre-script you could point that to your mount point for snapshot. (Not sure whether it reads that file before executing scripts or after though; so it might not work. Then you can just mount the snapshot to the same mount point instead and permanently save the mount point path in the prefs file)
  2. You can set current directory to the snapshot mount point and instead pass -pref-dir argument to duplicacy pointing to the folder where the configuration is stored, leaving “repository” default, which is “current directory”

Thanks for the suggestions. Unfortunately as you mentioned, the first method does not work at all. The second method is not fun when you want to do restores through the GUI.

@gchen do you have a feature request section for the paid duplicacy webgui? I’d like to request the feature to have scripts per job, rather than per repository, since sometimes each job has to be handled differently (different script) based on what’s being backed up.

As I said in the email I’ll add per-schedule scripts. I think this is the best solution.

A wrapper script could modify the .duplicacy/preferences file before/after running the CLI. The CLI -comment option could be used to pass the path to the snapshot to the wrapper script.