Additional changes to duply-with-powernap post / git add/rm'ing older uncommitted...
[pwan.org.git] / content / hints / duply-with-powernap.rst
1 Duply with a powernapping system
2 #################################
3
4 :date: 2015-02-17
5 :tags: hints,ubuntu,duply,powernap
6 :category: hints
7 :author: Jude N
8
9 I've started `backing up one of my systems to S3`_. The instructions from the Phusion blog worked almost perfectly, except my TARGET line was
10
11 .. code-block:: bash
12
13 TARGET='s3+http://<my-bucket-name>'
14
15 Also on the AWS side, I set up a lifecycle rule to archive the backups to Glacier after 7 days.
16
17 I did run into some issues getting the backups to work together with `powernap`_, which was configured to put the system to sleep after a few minutes of inactivity.
18
19 Powernap was causing a problem on two fronts. First, the system was going to sleep mid-backup since full backups take longer than the powernap inactivity timeout. Second, the backups were scheduled for the middle of the night when the system would normally already be asleep.
20
21 To get around the mid-backup sleep issue, I made a /usr/local/bin/duply-nightly script which shuts down powernap before calling duply and restarted it afterwards.
22
23 To get around the system-already-asleep issue, I'm using `an RTC wakeup`_ in /usr/local/bin/duply-nightly to set the system to wake a few minutes before the cron job kicks off (but not early enough for powernap to put the system to bed again...)
24
25 The first night I ran the backup, I had to prime the /sys/class/rtc/rtc0/wakalarm time manually, but since then the script has
26 set the wakeup time for the next day
27
28 The final /usr/local/bin/duply-nightly script is below
29
30 .. code-block:: bash
31
32 #!/bin/sh +x
33
34 /usr/bin/logger "Running nightly backup from $0"
35
36 # Disable powernap during the backup
37 service powernap stop
38
39 /usr/bin/duply nightly backup
40
41 # Wakeup the system at 3:00am tomorrow
42 echo 0 > /sys/class/rtc/rtc0/wakealarm
43 echo `date '+%s' -d '3am next day'` > /sys/class/rtc/rtc0/wakealarm
44
45 # Enable powernap again.
46 service powernap start
47
48 The cron job that kicks on /usr/local/bin/duply-nightly is below
49
50 .. code-block:: bash
51
52 SHELL=/bin/sh
53 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
54
55 5 3 * * * root env HOME=<myhomedir> /usr/local/bin/duply-nightly > /var/log/duply-nightly.log
56
57 .. _backing up one of my systems to S3: http://blog.phusion.nl/2013/11/11/duplicity-s3-easy-cheap-encrypted-automated-full-disk-backups-for-your-servers/
58 .. _powernap: https://launchpad.net/powernap
59 .. _an RTC wakeup: http://www.linux.com/learn/docs/672849-wake-up-linux-with-an-rtc-alarm-clock