Duplicity scp/ssh backup on raspberry Pi

[wp_ad_camp_1]
I want to use duplicity to backup my cloud server on Linode (You can use AWS as well or any other provider through which you can scp/ssh). Why I want to use duplicity is also because or partial backups, since the first backup will be full and all continuous ones will be only for the difference in files.

Why Raspberry pi? It’s cheap, low power and very portable :)d

So let’s proceed with the setup.

Prerequisites:

  • gpg
  • duplicity
  • ssh keys

Installation and configuration:

Before anythign else, it is highly recomended your Raspberry Pi is up to date and that you run:
sudo apt-get update

For installation of duplicity, after the update, it should run fairly smoothly with the following command:
sudo apt-get install duplicity

In case you want encryption which I highly recommend, setting up GPG keys is recommended and supported by Duplicity. For that we first need to install GPG with:
sudo apt-get install gnupg

Perfect, now we have the proper tool installed and need to generate appropriate key with all the info you will be required in the command prompt. Run this command and follow the instructions, and most importantly note them down somewhere! You don’t want to lose your password.

gpg --gen-key

At one point you will encounter “Not enough random bytes available. Please do some other work to give
the OS a chance to collect more entropy!”
And i simply didn’t have enough entropy.
But if you want to know how big your entropy is you can check with cating:

cat /proc/sys/kernel/random/entropy_avail

For me it was 34. After that I have installed:

sudo apt-get install rng-tools

And it increased to over 1000. which is absolutely great. After that the GPG key got automatically generated. Do however note, that you need to run this entropy related commands in parallel to your terminal in another window.

When running gpg –list-key you should be able to see now your newly created gpg key.

Then let’s try it with:
duplicity full ssh:root:password@IPofHOST// home/pi/backup
This will fail. I just wished to demonstrate this so other people don’t need to investigate through the same problem, that is that duplicity can’t use remote as source.

As a solution I am mounting remote to be a fake local mount with:
apt-get install sshfs

After that we will run:

mkdir -p /mnt/remote &&
sshfs root:password@IPofHOST:/ /mnt/remote

This will mount it locally and you can therefore specify your local backup paths for Duplicity

The mentioned tool has a range of commands, but one of them that you could potentially use for that would be then:

duplicity /home/directory file://some/other/directory

Reference:
http://go2linux.garron.me/scp-duplicity-secure-backup/

By |March 1st, 2017|Categories: ALL, How to, The Code|

About the Author:

Senior lead developer currently working in Java, architecture design, mix of tech from Front-end in JS and templating to chef,rundeck etc. For fun and challenge I am writing different blog posts from stories to poems, programming tutorials and many more. Currently working on my Masters degree on a part-time basis.