Home / Community / Blog

To backup embedded systems, such as Android phone or OpenWRT router you can use tar command in conjunction with ssh. As I mentioned before this method is almost successful with Android. Now example with Gargoyle router - called device.

Similar to Android devices OpenWRT's tar doesn't support --totals option, so I've prepared wrapper (see below) because it is necessary for BackupPC.

You will need:

  1. Copy your generated earlier id_rsa.pub to /etc/dropbear/authorized_keys on device. To be able to login without password.
  2. Login to device manually for the first time (to add it to known_hosts):

    sudo -u backuppc /usr/bin/ssh -q -x -n -l root router
    

    as you can see I logged as root to device named router. Alternatively you can manually edit known_hosts.

  3. On device create file (ie. /root/tar_totals.bash) to emulate --totals option behaviour:

    root@router:~# cat /root/tar_totals.bash
    tar $*
    echo "Total bytes written: 10240 (10KiB, 3.6MiB/s)" >&2
    

    and of course make it executable:

    chmod u+x /root/tar_totals.bash
    

    (this what I can't do on Android)

  4. Define host in BackupPC with settings:

    $Conf{BackupFilesExclude} = {};
    $Conf{BackupFilesOnly} = {
      '/' => [
        'etc'
      ]
    };
    $Conf{TarClientCmd} = '$sshPath -q -x -n -l root $host $tarPath -c -v -f - -C $shareName+';
    $Conf{TarClientPath} = '/root/tar_totals.bash';
    $Conf{TarShareName} = [
      '/'
    ];
    $Conf{XferMethod} = 'tar';
    

    as you can see only /etc is copied, and I use wrapper instead of tar command.

Now you can backup it. Of course in log you will have:

Running: /usr/bin/ssh -q -x -n -l root router /root/tar_totals.bash -c -v -f - -C / ./etc
full backup started for directory / Xfer PIDs are now 23732,23731
Total bytes written: 10240 (10KiB, 3.6MiB/s)
(...)

where you can see fake transfer summary.

Unfortunately on Android device you cannot set file as executable:

HWVTR:/storage/emulated/0/ssh $ chmod u+x tar_totals.bash
chmod: chmod 'tar_totals.bash' to 100760: Operation not permitted

Just my blog...

Mon Tue Wed Thu Fri Sat Sun
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31