Preface

Before we begin, note that I stopped taking backups with Duplicacy after performance issues began to manifest with my server. These problems are specific to my server and shouldn’t be a cause on your server, unless you have underpowered hardware like me. This is a kind of a log should I decide to come back to this method later.

What is Duplicacy?

Duplicacy is a backup/restore tool for servers. They have a free CLI version and a paid GUI version. For all intents and purposes the CLI version does the job really well and should be the only one you need unless you’re extremely scared of the terminal.

Steps to install

Note: Thanks to this Reddit post for the general instructions.

Now, UnRAID boots off of USB drives, which means that if you just blindly copy your duplicacy executable to a system folder, the changes will be lost on next boot, you will be extremely unhappy and things will break. So we need to make duplicacy persistent.

  1. Navigate to your USB drive on your UnRAID server.
cd /boot/config/plugins
  1. Download the duplicacy executable.
wget -O duplicacy https://github.com/gilbertchen/duplicacy/releases/download/v2.1.2/duplicacy_linux_x64_2.1.2

Now it’s very certain that there is a new version by the time you are reading this article. Simply go to the releases tab on GitHub, right click on duplicacy_linux_x64_xxx where xxx is the version number, and select “Copy link location” (may vary depending on browser). Then paste it after wget -O duplicacy.

  1. Make the necessary changes in your go file to copy over the executable on every boot. Type the following two lines at the end of /boot/config/go:
# Copy duplicacy
ln -s /boot/config/plugins/duplicacy /usr/local/bin/

This should symlink the executable to an executable location every time UnRAID starts up.

You’re done! Reboot the machine and make sure you can run duplicacy in your terminal.

Setting up Duplicacy

This part varies wildly depending on which cloud hosting provider you decide to go with. Previously, I used Backblaze B2. Some notes:

  • You can actually set up duplicacy in the root folder of your shares, /mnt/user/*. This way, duplicacy stores all the configuration and other details in /mnt/user/.duplicacy/*.

Once you’re done initing your cloud provider, run duplicacy backup for the first time.

Automating it

But you’re no peasant and you won’t run that command every single time you want to back up the server, right? So let’s automate it with User Scripts.

Download User Scripts (plenty of guides online) on your UnRAID server. You can use Community Applications for it. Once you’re there, create a script with the following:

#!/bin/bash

# https://stackoverflow.com/a/185473/1388019
lockfile="/tmp/duplicacy.lock"

if [ -e ${lockfile} ] && kill -0 `cat ${lockfile}`; then
    echo "duplicacy already running"
    exit
fi

# make sure the lockfile is removed when we exit and then claim it
trap "rm -f ${lockfile}; exit" INT TERM EXIT
echo $$ > ${lockfile}

# run the backup with default settings
cd /mnt/user
/usr/local/bin/duplicacy -log backup -threads 2 -stats

# clean up lockfile
rm -f ${lockfile}

Let’s go over this line by line. On the first couple of lines, from the line that starts with lockfile to echo $$, we set up a lockfile. In case User Scripts fuck up and run the script twice (by the way, you should never run duplicacy at the same time unless you want an ensemble of problems), the lockfile prevents the script from running twice.

Then the two lines after that start the backup, with 2 threads. Adjust to match your CPU.

Save it with an appropriate name and description, set a schedule, and let her rip in the background! The backup is now completely automated!

Deleting old backups

By the way, Duplicacy will not automatically delete old backups. To do that, you must prune your backup set.

Make another script in User Scripts:

#!/bin/bash

# https://stackoverflow.com/a/185473/1388019
lockfile="/tmp/duplicacy.lock"

if [ -e ${lockfile} ] && kill -0 `cat ${lockfile}`; then
    echo "duplicacy already running"
    exit
fi

# make sure the lockfile is removed when we exit and then claim it
trap "rm -f ${lockfile}; exit" INT TERM EXIT
echo $$ > ${lockfile}

cd /mnt/user
# Delete any backups older than 120 days. Adjust if required
duplicacy prune -exhaustive -exclusive -keep 0:120

# clean up lockfile
rm -f ${lockfile}

Hmm, seems very similar to the first script, except we run duplicacy prune here. This deletes any previous data backups older than 120 days (you can adjust the date). Useful if your cloud provider is charging you an arm and leg for the service.

To uninstall

If for some reason you’re like me and want to try the greener pasture, uninstalling duplicacy is very simple.

  1. Delete the executable over at /boot/config/plugins/duplicacy.
  2. Edit the go file over at /boot/config/go. Remove the two lines that we added above.
  3. Delete configuration files if required. Go to your source directory (for me it’s /mnt/user) and then type rm -rf .duplicacy. (NOTE THAT THIS IS DESTRUCTIVE!)

Once that’s done, reboot your UnRAID server and you should be on your way!

Conclusion

Any questions? Shoot me an email. Thanks for reading!