Headless Installation of Duplicati on Amazon Linux
This page has built upon (aka "steals shamelessly") the work of others, and is not quite complete. However it should help as a guide to getting Duplicati working on Amazon Linux, and possibly Centos as well. It's definitely not perfect, it may have gaping security holes as I've run everything as root, and right now the service starts and stops ok but the "stop" says "failed" even though it works. Maybe someone else can help with that. It's definitely a work in progress.
On my t2.nano Duplicati takes around 100MB of RAM, of my 500MB of physical RAM and 500MB of swap. I already run Nginx, MySQL, PHP, fail2ban, and maybe a couple of other small things, so memory is quite tight. Initially I scheduled Duplicati to start 5 minutes before the scheduled backups, then stop a little while after the backups should finish. Now I've disabled the web server and I have cron running Duplicati from the command line - with the command line parameters worked out using the very useful web interface "export command line" function. It uses the same amount of RAM when it's running, but it's cleaner.
If you ever have the choice of Amazon Linux or Ubuntu, choose Ubuntu. More packages are easily available, and they're more up to date.
I'm not 100% sure this is required, but I had an EPEL and I wasn't sure which version of mono would be installed.
cd /etc/yum.repos.d vi (anything that has epel in the title) (set enabled to 0)
This should be done as per the documentation by here. Watch for comments at the bottom as versions change. I've copied the key steps in here in case the page disappears.
sudo yum update -y
echo "======= INSTALLING RPM FOR MONO ======="
sudo mkdir -p /tmp/mono_dependencies
cd /tmp/mono_dependencies
sudo wget https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Everything/x86_64/os/Packages/l/libpng15-1.5.27-1.fc25.x86_64.rpm
sudo yum install -y libpng15-1.5.27-1.fc25.x86_64.rpm
echo "======= INSTALLING MONO ============"
sudo yum install -y yum-utils
sudo rpm --import "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"
sudo yum-config-manager --add-repo http://download.mono-project.com/repo/centos/
sudo yum clean all
sudo yum makecache
#sudo yum install -y mono-complete
sudo yum install -y mono-core # I used mono-core only
sudo rm -rf /tmp/mono_deps
echo "======= TESTING MONO ============"
cd ~
echo "using System; public class HelloWorld { static public void Main () { Console.WriteLine (\"ヅ Hello from Mono (hello.exe). Installation complete! ヅ\"); } }" > hello.cs
mcs hello.cs
mono hello.exe
Follow the guide for the Headless Debian or Ubuntu Install, starting from the section "Setup directories and grab a copy of Duplicati", but stop when you get to "Add Duplicati to systemd for automatic startup on system boot".
Here's what I typed, in case that page changes
- mkdir /usr/lib/duplicati
- cd /usr/lib/duplicati
- wget https://github.com/duplicati/duplicati/releases/download/v2.0.3.9-2.0.3.9_canary_2018-06-30/duplicati-2.0.3.9_canary_2018-06-30.zip
- unzip duplicati-2.0.3.9_canary_2018-06-30.zip
- rm duplicati-2.0.3.9_canary_2018-06-30.zip
- Add the following as /usr/bin/duplicati-cli
#!/bin/bash
INSTALLDIR=/usr/lib/duplicati
export LD_LIBRARY_PATH="${INSTALLDIR}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export MONO_PATH=$MONO_PATH:${INSTALLDIR}
EXE_FILE=${INSTALLDIR}/Duplicati.CommandLine.exe
APP_NAME=Duplicati.CommandLine
exec -a "$APP_NAME" mono "$EXE_FILE" "$@"
- Add the following as /usr/bin/duplicati-server
#!/bin/bash
INSTALLDIR=/usr/lib/duplicati
export LD_LIBRARY_PATH="${INSTALLDIR}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export MONO_PATH=$MONO_PATH:${INSTALLDIR}
EXE_FILE=${INSTALLDIR}/Duplicati.Server.exe
APP_NAME=DuplicatiServer
exec -a "$APP_NAME" mono "$EXE_FILE" "$@"
- chmod 755 /usr/bin/duplicati-cli
- chmod 755 /usr/bin/duplicati-server
- Add the following as /etc/default/duplicati
# Defaults for duplicati initscript
# sourced by /etc/init.d/duplicati
#
# This is a POSIX shell fragment
#
# Additional options that are passed to the Daemon.
DAEMON_OPTS="--webservice-port=8200 --webservice-interface=any"
The configuration given above will have Duplicati accept connections to the webinterface from anywhere. If you want to run a more restrictive setup, edit the --webservice-interface setting accordingly.
First ensure your AWS Security Group is open on port 8200, but only to your own IP address, so others can't log into your Duplicati
Run this command
/usr/bin/duplicati-server --webservice-port=8200 --webservice-interface=any
In your web browser visit your server on port 8200: eg http://1.2.3.4:8200
- vi /etc/init.d/duplicati
- Copy the script below
- hit the key a
- right mouse click to paste
- type ":w" to save (don't type the speech marks)
- type ":q!" to exit
- chmod a+x /etc/init.d/duplicati
- Start the service with "service duplicati start"
- Stop the service with "service duplicati stop"
#!/bin/bash
#
# /etc/init.d/duplicati
#
# chkconfig: 2345 13 87
# description: Duplicati backup startup script
# Source function library.
. /etc/init.d/functions
DUP_DIR=/usr/lib/duplicati
PIDFILE=$DUP_DIR/pid
start() {
echo "Starting Duplicati: "
if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
echo "duplicati already running: $PID"
exit 2;
else
daemon --pidfile="$PIDFILE" /usr/bin/duplicati-server --webservice-port=8200 --webservice-interface=any &
sleep 1
ps -ef | grep -v grep | grep mono-sgen | awk '{ print $2 }' > /usr/lib/duplicati/pid
touch /var/lock/subsys/duplicati
echo "done"
return 0
fi
}
stop() {
PID=`cat $PIDFILE`
echo "Shutting down Duplicati with PID $PID: "
kill $PID
rm -f /var/lock/subsys/duplicati
rm -f $PIDFILE
echo "Service Stopped"
# return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: {start|stop|status|restart}"
exit 1
;;
esac
exit 0