1. Server setup
1.1 Initial setup
Initial steps :
– OpenVPN server
– OpenVPN client
– Rsync server
Then we are ready for this step !
1.2 Directories
Create folders for our daily backups for “bart” :
sudo mkdir -p /var/backups/raspberry/bart/daily/{1..7}
Create folders for our weekly backups for “bart” :
sudo mkdir -p /var/backups/raspberry/bart/weekly/{0..53}
Adjust permissions :
sudo chown -R nobody:nogroup /var/backups/raspberry/
The server is ready !
2. Client setup
Once the Rsync server is up and running, let’s see how we could backup essential files from our Pi called “bart”.
2.1 Files selection
First, let’s create a file that lists all the files that we want to backup :
sudo vi ~/backupFilesList
In our exemple, here are the files that we’ll backup :
/home/pi/domoticz/domoticz.db /etc/ipsec.conf /etc/rc.local
2.2 Test
Daily backup test:
Test the daily backup using the ISO day number :
sudo rsync -vr --delete --files-from=/home/pi/backupFilesList / rsync://10.8.0.1/raspberry/bart/daily/$(date '+%u')/
The output should looks like this :
sending incremental file list etc/ipsec.conf etc/rc.local home/pi/domoticz/domoticz.db sent 3,770 bytes received 4,606 bytes 16,752.00 bytes/sec total size is 558,460 speedup is 66.67
Weekly backup test:
Test the weekly backup using the week number :
sudo rsync -vr --delete --files-from=/home/pi/backupFilesList / rsync://10.8.0.1/raspberry/bart/weekly/$(date '+%V')/
The output should looks like this :
sending incremental file list etc/ etc/ipsec.conf etc/rc.local home/ home/pi/ home/pi/domoticz/ home/pi/domoticz/domoticz.db sent 559,027 bytes received 112 bytes 74,551.87 bytes/sec total size is 558,460 speedup is 1.00
The files should be on the server !
2.3 CRON
Edit the cron table :
sudo crontab -u root -e
And add the following lines :
#Daily backup 0 4 * * * rsync -vr --delete --files-from=/home/pi/backupFilesList / rsync://10.8.0.1/raspberry/bart/daily/$(date '+\%u')/ #Monthly backup 0 5 1 * * rsync -vr --delete --files-from=/home/pi/backupFilesList / rsync://10.8.0.1/raspberry/bart/weekly/$(date '+\%V')/
You’re done. The backup monitoring will be done on the server side, using Zabbix.