Home / Community / Blog

Once, after server crash, I've noticed I've BackupPC shows no backups for some clients. Fortunately /BackupPC/pc/*/ still contains those backups.

To fix a corrupted backups file you should:

  • Stop BackupPC
/etc/init.d/backuppc stop
  • Run BackupPC_fixupBackupSummary script as backuppc user
sudo -u backuppc /usr/share/backuppc/bin/BackupPC_fixupBackupSummary
  • Start BackupPC
/etc/init.d/backuppc start

Now I can see all backups on Host Summary page.

To backup running QEMU/KVM machine I use script made by Daniel Berteaud. I've installed it in this way:

cd /usr/local/sbin/
wget "http://gitweb.firewall-services.com/?p=virt-backup;a=blob_plain;f=virt-backup;hb=HEAD" -O virt-backup-0.2.17-1.pl
ln -s virt-backup-0.2.17-1.pl virt-backup
chmod u+x virt-backup-0.2.17-1.pl

as you can see current version is 0.2.17-1

There is also a fork of virt-backup: github.com/vazhnov/virt-backup.pl - it's based on some earlier version.

Example command to backup centos-test machine (name shown by virsh list) to /mnt/backups directory.

virt-backup --action=dump --no-snapshot --compress --shutdown --shutdown-timeout=300 --vm=centos-test --backupdir=/mnt/backups

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

After you manage to ssh to your android device. You can set it up to backup with BackupPC.

Since rsync command is not available You can use tar. In configuration you have to set:

$Conf{XferMethod} = 'tar';

change path to tar:

$Conf{TarClientPath} = 'tar';

and command to execute:

$Conf{TarClientCmd} = '$sshPath -q -x -n -p 2222 $host env LC_ALL=C $tarPath -c -v -f - -C $shareName+';

as you can see I've removed -l root and --totals.

Complete config is:

$Conf{XferMethod} = 'tar';
$Conf{TarClientPath} = 'tar';
$Conf{TarShareName} = [
  '/storage/emulated/0/DCIM/Camera/'
];
$Conf{TarClientCmd} = '$sshPath -q -x -n -p 2222 $host env LC_ALL=C $tarPath -c -v -f - -C $shareName+';

There are still some problems because backup is ended with an error:

Running: /usr/bin/ssh -q -x -n -p 2222 huawei_p10 env LC_ALL=C tar -c -v -f - -C /storage/emulated/0/DCIM/Camera .
full backup started for directory /storage/emulated/0/DCIM/Camera
Xfer PIDs are now 19406,19405
(...)
tarExtract: Done: 0 errors, 0 filesExist, 0 sizeExist, 0 sizeExistComp, 78 filesTotal, 227795841 sizeTotal
Backup aborted ()
Not saving this as a partial backup since it has fewer files than the prior one (got 78 and 0 files versus 1814)

You can backup android phone/tabled (device) with rsync installed on some host and SimpleSSHD installed on device.

First you have to check if you can ssh to device:

To login first time You have to run SimpleSSHD and press START to run it in foreground. From some host login to device using command:

sudo -u backuppc /usr/bin/ssh 192.168.1.241 -p 2222

enter password displayed in SimpleSSHD windows on device, you will see something like this:

no authorized_keys, generating single-use password
--------
yrGAex8s
--------

As you can see my device has address 192.168.1.241 and server is using his default port 2222. You don't have to provide any user name (ie. -l someuser).

Now you can backup device manually using rsync:

rsync --update -e 'ssh -p 2222' -azv \
192.168.1.241:/storage/emulated/0/DCIM/Camera/ /data/myPhoneBackup/

Another approach is to use Rsync Wrapper by Letscorp (I didn't tested it yet).

The main target is to make android device be able to backup using BackupPC.

The easiest way to restore files from BackupPC is web interface, but if You are desperated to use command-line style You can try this:

su backuppc -c "/opt/BackupPC/bin/BackupPC_tarCreate -h myLaptop \
-n 23 -s / etc" > /tmp/etc.tar

where:

  • backuppc (after su) - name of user BackupPC is running as
  • /opt/BackupPC/bin - path where BackupPC is installed
  • myLaptop - name of host in BackupPC (usually DNS name)
  • 23 - backup number you want to restore (can be relative ex: -1)
  • / - is share name
  • etc - directory you want to restore (relative to share name)
  • /tmp/etc.tar - file with restored files

Of course usually You will compress this file:

su backuppc -c "/opt/BackupPC/bin/BackupPC_tarCreate -h myLaptop \
-n 23 -s / etc" | gzip > /tmp/etc.tgz

Detailed information on BacpupPC documentation page.

To allow backuppc user to send emails I've to change permissions to /etc/msmtprc file:

chmod a+r /etc/msmtprc

Now I can send email as backuppc, but there is a problem with logging:

root@NAS:~# sudo -u backuppc /usr/sbin/sendmail jaqb@mydomain.com
subject:test
from:backuppc@nas
this is a test

sendmail: cannot log to /var/log/frontview/msmtp.log: \
          cannot open: Permission denied
sendmail: log info was: host=mail.mydomain.com tls=on auth=on \
          user=jaqb from=jaqb@mydomain.com \
          recipients=jaqb@mydomain.com mailsize=90 smtpstatus=250 \
          smtpmsg='250 2.0.0 Ok: queued as E29FC1665F31' exitcode=EX_OK

(after "this is a test") you have to press Ctrl-D (end of file).

If you have to rename host in BackupPC you have to:

  1. Stop BackupPC service:
    systemctl stop backuppc
    
  2. Change the host name in host file (/etc/backuppc/hosts) to new name
  3. Rename the pl file in pc folder (/etc/backuppc/pc), ie:
    cd /etc/backuppc/pc
    mv oldname.pl newname.pl
    
  4. Rename directory in the backup location (I my case backup is storing in the location /data/BackupPC)
    cd /data/BackupPC/pc/
    mv oldname newname
    
  5. Start BackupPC service
    systemctl start backuppc
    
  6. Pray
  7. Check if it works

Sometimes you have to run command as user who cannot login (shell set to /bin/false, /usr/sbin/nologin or something like this) in example for testing BackupPC where backuppc user usually cannot login but you have to run ssh command manually for the first time to add host to known_hosts.

Instead of ugly copping known_host file you can run:

sudo -u backuppc /usr/bin/ssh -l username remotehost

I think it's nicer way.

After installation (as you can see it is based on Debian)

apt-get install backuppc

I have to modify attributes:

chmod u+s /usr/share/backuppc/cgi-bin/index.cgi

Because of error:

File::RsyncP module doesn't exist

I had to install manually missing Perl module:

apt-get install libfile-rsyncp-perl

To login without password I've generated keys (as root):

ssh-keygen

and copy id_rsa.pub to .ssh/authorized_keys on host I would like to backup.

Now I can ssh to that host without password (on Windows machine You have to allow Public Key exchange).

It's time to do the same for backuppc user. By default it has bash set to /bin/false so I done it manually:

mkdir -p /home/backuppc/.ssh
cp id_rsa known_hosts /home/backuppc/.ssh
chown -r backuppc /home/backuppc/.ssh

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