Automated Backups Using dhcpd On Ubuntu

This tutorial shows how to set up automated backups of Linux hosts through dhcp using Ubuntu.

I will use following software:

  • dhcp3
  • custom scripts


1 On The Server

1.1 Configure dhcp3

In /etc/dhcp3/dhcps.conf add:

on commit {
  execute (


1.2 Create

sudo vi /etc/dhcp3/

case "$1" in
  sudo -u backup /etc/dhcp3/ $2
exit 0


1.3 Create

sudo vi /etc/dhcp3/

nohup rsync -azuvb [email protected]$1:/home /backup/$1 &

and add the /backup folder:

sudo mkdir /backup


1.4 Add The User backup

sudo useradd backup

sudo chown backup:backup /backup

Create the private/public ssh keys:

ssh-keygen -t rsa

Copy the public key to all hosts you want to back up:

ssh-copy-id -i ~/.ssh/id_rsa [email protected][host]

Replace [host] with your hostname(s) or ip address(es).


1.5 Configure sudo

sudo visudo

and add a line like this:

dhcpd ALL=(backup)NOPASSWD: /etc/dhcp3/, /etc/dhcp3/


1.6 Configure AppArmor

sudo vi /etc/apparmor.d/usr.sbin.dhcpd3

Change the part that looks like:

/etc/dhcp3/ r,
/etc/dhcp3/** r,
/etc/dhcpd.conf r,
/etc/dhcpd_ldap.conf r,


/etc/dhcp3/ r,
/etc/dhcp3/** r,
/etc/dhcp3/ Uxr,
/etc/dhcpd.conf r,
/etc/dhcpd_ldap.conf r,


1.7 Restart Services

sudo /etc/init.d/apparmor restart

sudo /etc/init.d/dhcp3-server restart


On The Client

2.1 Add The User backup

sudo useradd backup

sudo usermod -G root


2.2 Test The Setup

sudo dhclient [interface]

where interface is the one you want to renew

You should now have a backup of your clients on the server.

Share this page:

Suggested articles

1 Comment(s)

Add comment



isn't there a problem, if the ip addresse is assigned, but the booting system hasn't started the sshd? maybe there should be a delay in the before executing the rsync process.