New duply-with-powernap post / some old uncommitted changes
[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 TARGET='s3+http://<my-bucket-name>
12
13 Also on the AWS side, I set up a lifecycle rule to archive the backups to Glacier after 7 days.
14
15 I did run into some issues getting the backups to work together with `powernap`_, which is configured to put the system to sleep after a few minutes of keyboard inactivity.
16
17 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. The other problem was the backup was scheduled for the middle of the night when the system would normally already be asleep.
18
19 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.
20
21 In order 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...)
22
23 The final /usr/local/bin/duply-nightly script is below
24
25 .. code-block:: bash
26
27 #!/bin/sh +x
28
29 /usr/bin/logger "Running nightly backup from $0
30
31 # Disable powernap during the backup
32 service powernap stop
33
34 /usr/bin/duply nightly backup
35
36 # Wakeup the system at 3:00am tomorrow
37 echo 0 > /sys/class/rtc/rtc0/wakealarm
38 echo `date '+%s' -d '3am next day'` > /sys/class/rtc/rtc0/wakealarm
39
40 # Enable powernap again.
41 service powernap start
42
43 The cron job that kicks on /usr/local/bin/duply-nightly is below
44
45 .. code-block:: bash
46
47 SHELL=/bin/sh
48 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
49
50 5 3 * * * root env HOME=<myhomedir> /usr/local/bin/duply-nightly > /var/log/duply-nightly.log
51
52 .. _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/
53 .. _powernap: https://launchpad.net/powernap
54 .. _an RTC wakeup: http://www.linux.com/learn/docs/672849-wake-up-linux-with-an-rtc-alarm-clock