Installing BackupPC on OpenWRT

A Tech article with View Comments posted 9 July 2009.
Tags: , , , ,

I wanted to have a backup server for my church that would automatically take backups when computers came on to our new wireless network. BackupPC immediately sprang to mind, but it only runs on Linux. How could I get a Linux server into the church in a very low cost way? Answer: An Asus wireless router running OpenWRT.

Installing OpenWRT is not for beginners. What follows is not a step-by-step guide to every keystroke, but rather an overview that gets you past the particular hurdles of getting OpenWRT installed on the router, getting it to boot off the hard drive, and installing BackupPC and its dependencies. Please know what you’re doing before you get started.

I bought:

  1. Asus WL-500gP wireless router. It has two USB 2.0 ports in addition to easy JTAG access if I ever get in trouble.
  2. An external Hitachi 640G USB2.0 hard drive.

Together, the two parts set me back about $160. I decided to install OpenWRT, a distribution of Linux designed for wireless routers, and BackupPC, software that automates the backups.

  1. Install OpenWRT as normal. I recommend installing the latest generic openwrt-brcm-2.4-squashfs.trx firmware. For me, that was Kamikaze 8.09.1. It was necessary to use tftp to install the firmware.
  2. Configure the router to pivot_root to the USB hard drive on boot. Follow the “How do I boot from the USB device (prep)” and “Boot Configuration (Kamikaze)” guides on this wiki page. You don’t need to do anything related to hotplug. The page is outdated when it comes to adding the script to /etc/init.d/rcS, just modify your existing file to include the first three lines of the code on the wiki.
    • My /etc/init.d/pivotroot:
      1. #!/bin/sh
      2. # change this to your boot partition
      3. boot_dev="/dev/scsi/host0/bus0/target0/lun0/part1"
      4. # install needed modules for usb and the ext3 filesystem
      5. # **NOTE** for usb2.0 replace "uhci" with "ehci-hcd"
      6. # **NOTE** for ohci chipsets replace "uhci" with "usb-ohci"
      7. for module in usbcore ehci-hcd scsi_mod sd_mod usb-storage jbd ext2 ext3 ; do {
      8.         insmod $module
      9. }; done
      10. # this may need to be higher if your disk is slow to initialize
      11. sleep 4s
      12. # mount the usb stick
      13. mount "$boot_dev" /mnt
      14. # if everything looks ok, do the pivot root
      15. [ -x /mnt/sbin/init ] && {
      16.         mount -o move /proc /mnt/proc && \
      17.         pivot_root /mnt /mnt/mnt && {
      18.                 mount -o move /mnt/dev /dev
      19.                 mount -o move /mnt/tmp /tmp
      20.                 mount -o move /mnt/jffs /jffs 2>&-
      21.                 mount -o move /mnt/sys /sys 2>&-
      22.         }
      23. }
    • My /etc/init.d/rcS:
      1. #!/bin/sh
      2. # Copyright (C) 2006 OpenWrt.org
      3. if test $2 == "boot" ; then
      4.   /etc/init.d/pivotroot
      5. fi
      6.  
      7. run_scripts() {
      8.  for i in /etc/rc.d/$1*; do
      9.   [ -x $i ] && $i $2 2>&1
      10.  done | $LOGGER
      11. }
      12.  
      13. LOGGER="cat"
      14. [ -x /usr/bin/logger ] && LOGGER="logger -s -p 6 -t sysinit"
      15.  
      16. if [ "$1" = "S" ]; then
      17.  run_scripts "$1" "$2" &
      18. else
      19.  run_scripts "$1" "$2"
      20. fi
  3. Set up a swap file. You’re going to need the extra memory, especially when doing large batches with rsync. The basic shape of this is below for a 256M swap file. You might want to use the LuCI interface to make this permanent (or edit /etc/config/fstab).
    1. opkg install swap-utils
    2. dd if=/dev/zero of=/swap.file bs=1024 count=262144
    3. mkswap /swap.file
    4. swapon /swap.file
  4. Tweak opkg to not install to flash anymore. Comment out option overlay_root /jffs from /etc/opkg.conf. Otherwise you’ll have several hundred gigabytes of free space, but opkg will still refuse to use it.
  5. Install BackupPC dependencies from packages. You’re going to need a whole heap of samba and Perl.
    1. opkg update
    2. opkg install perl samba-client samba-server
    3. # Helpful symlink for perl
    4. ln -s /usr/bin/perl /bin/perl
    5. # Install all perlbase packages
    6. opkg list | grep -o -E perlbase-\\w+ | xargs opkg install
  6. Download and unzip BackupPC
  7. Install (yet more) BackupPC dependencies manually. Both CPAN and CPANPLUS are irretrievably broken on this platform, so run BackupPC-3.1.0/configure.pl and install what isn’t there by extracting the contents of /lib of whatever CPAN module you’re installing to /usr/lib/perl5/5.10.
    • If it asks you repeatedly to install Pod::Usage and you have already, type this in the shell: perl -MPod::Usage and figure out what’s still missing when it dies.
  8. Install BackupPC. Finally configure.pl will start asking you questions and let you install. Go for it. You probably want to have it run as the root user.
  9. Configure BackupPC to start on boot. The initializing scripts provided in BackupPC-3.1.0/init.d aren’t bad, and the one for Slackware is the best. Here’s what landed in my /etc/init.d/backuppc (Modified from the Slackware script). After copying this to your router, run /etc/init.d/backuppc enable to get the service to start automatically.
    1. #!/bin/sh /etc/rc.common
    2. # Startup init script for BackupPC for OpenWrt
    3.  
    4. START=95
    5. STOP=10
    6.  
    7. start() {
    8.     /usr/local/BackupPC/bin/BackupPC -d
    9. }
    10.  
    11. stop() {
    12.     /usr/bin/pkill -f "/usr/local/BackupPC/bin/BackupPC -d"
    13. }
    14.  
    15. restart() {
    16.     stop
    17.     start
    18. }
    19.  
    20. reload() {
    21.     /usr/bin/pkill -f -HUP "/usr/local/BackupPC/bin/BackupPC -d"
    22. }
  10. Set up BackupPC admin interface. Here are some general steps to shoehorn it onto the router:
    1. Copy BackupPC-3.1.0/cgi-bin/BackupPC_Admin to /www/cgi-bin
    2. Edit /etc/BackupPC/config.pl to set $Conf{CgiAdminUsers}='*'; This option does eliminate password requirements on BackupPC, which is appropriate for my purposes. If it’s not for yours, configure Busybox’s httpd to set $REMOTE_USER.
    3. Copy .css and .js from BackupPC-3.1.0/conf and .png and .gif files from BackupPC-3.1.0/images to /www.
    4. Drop a link to the BackupPC admin interface in /www/index.html, and get rid of the meta refresh in the head of that file.
  11. Configure BackupPC. This is up to you. BackupPC is a complex package that needs to be customized to your particular installation. Go wild!

View Comments to “Installing BackupPC on OpenWRT”

  1. Ted,
    I'm stuck on your step 7 with perl dependencies. Do you know how you managed to install that? When I copy it over from another install it complains about compilation and needing a “loadable object”.

  2. Which loadable object is it complaining about? It has been a while, but if I remember correctly, getting all the perlbase-* packages installed should ensure that no other compiled code is needed. But paste the error into a comment and I'll help you puzzle it through if I can.

  3. Well…
    DynaLoader::bootstrap for File::RsyncP::Digest (auto/File/RsyncP/Digest/Digest.so)
    Can't load '/usr/lib/perl5/5.10/auto/File/RsyncP/Digest/Digest.so' for module File::RsyncP::Digest: File not found at /usr/lib/perl5/5.10/DynaLoader.pm line 166.
    at -e line 0

    I'm pretty sure I know what the problem is. I copied over this rsyncp module from another ARM install and it is linked to glibc and not ulibc for openwrt. This rsyncp module seems to really need its binary counterpart. Are you possibly not using rsync for backuppc? What do you have in your /usr/lib/perl5/5.10/auto/File/ directory?

  4. I may very well have circumvented this issue. I was using Samba, not rsync, when I was setting this up, and I vaguely remember having to comment something rsync-related out, which I failed to document in this article. You may have to build it from source, and that could get somewhat tricky. I think that rsync builds cleanly on ARM with ulibc, so with some luck and the proper build environment, you shouldn't have too much trouble. Alternatively, you could try a different backup method. Sorry I can't be of more help.

  5. Ted I thank you for sharing your work with the world, it makes the world a better place. I've documented my instructions in case anyone else tries to dive into the rsyncp-cross-compiling rabbit hole: http://wiki.xkyle.com/BackupPC_On_Openwrt

  6. I'm impressed that you got it to cross compile. I may end up using your work myself. Thank you!

Leave a Reply

blog comments powered by Disqus