Use rclone to make backup to google Drive

I finally decided that I need to make a daily backup of my two rasperry pi’s. One of them hosts my domoticz setup and the other one is used primarily as a dhcp /pihole server. So I think that it is save to say that a bit of a backup solution is ideal. I created the following bash file which is run using crontab. I use rclone to clone it to my google drive. A tutorial on how to install rclone, and a tutorial to create your own client_id for rclone google drive (please do this!). The file is self explanatory.


#!/bin/bash

#################
# backup script #
#################

backup_path_local= "/home/pi/bckp/"
backup_path_remote = "drive:domoticzpi"
retention = 6

# Controleren of we gebruiker root zijn!
if [[ ! $(whoami) =~ "root" ]]; then
echo ""
echo "*****************************************"
echo "*** Dit script moet draaien als root! ***"
echo "*****************************************"
echo ""
exit
fi

#stop domoticz
sudo service domoticz.sh stop
pihole disable

#zip
filename=$backup_path_local$HOSTNAME.$(date +%Y%m%d).tar


tar -cvf $filename "/home/pi/domoticz" "/etc/pihole"

#copy file to drive
sudo /usr/bin/rclone copy $filename "drive:backups/"$HOSTNAME


# bring up services
sudo service domoticz.sh start
sudo pihole enable

# remove the temporary file

rm $filename

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.