So after perusing the demise of
Grive and the various flaky alternative methods of accessing Google Drive from an RPi, it occurred to me that I had the makings of a more optimal solution right in front of me.
The Netgear gigabit router I use for our private subnet has the ability to host a USB storage device using SMB protocol, something I imagine most routers are capable of doing these days. I've never had a compelling need to use it, but this is the perfect application for it.
I had a 4GB USB2 key that has been idle for months, so I plugged that into the router and within seconds it was available on the network. I left it totally wide open as there's no reason to protect it with user credentials.
Then from my W7U system I created a folder on the drive for each of my RPi systems using their system names (rpints, bpints, raspi1 and raspi2).
Next, on each RPi I created a local folder under the existing /media root to associate the mount point for the SMB drive.
For example, on system
rpints:
Code:
$ sudo mkdir -p /media/readyshare/rpints
Next, on each RPi I added an entry to
/etc/fstab
Code:
//192.168.1.251/USB_Storage/rpints /media/readyshare/rpints cifs user=guest,domain=CORP,password=,sec=ntlm
Note that you must have a trailing CR/NL in the fstab file; it'll ***** about it if there isn't a blank line at the end of the file.
The IP address is the LAN address for the router (aka the "gateway" IP address) and the rest of that first path drills down to the target folder on the SMB drive. That will obviously vary - for example Netgear uses "\\readyshare\USB_Storage" as the drive root where I'm sure Cisco does something different. The second path is the corresponding local mount point.
cifs is the file access method; the user, domain name and (null) password paramters seem to be required even if the SMB drive requires no privileges; and
sec is the security mode parameter, set to
ntlm.
With the fstab file changes the SMB drive will automatically mount on boot, but the drive can be mounted manually at this point:
If the mount didn't fail the drive should be available via the mount point defined in the fstab file.
And you can list the contents of the SMB folder:
Code:
pi@rpints ~ $ ls -l /media/readyshare/rpints/
total 20208
-rwxr----- 1 root root 18874368 Jun 19 21:34 ibdata1
-rwxr--r-- 1 root root 1812480 Jun 19 21:34 tempdata.db
pi@rpints ~ $
Those are copies of my R'Pints and temperature logger data files sitting in the SMB drive folder.
So with that all set up, an automated backup process for select files can be constructed.
In this example, I'll save a copy of the R'Pints data file and the temperature logger data file from system
rpints to its folder on the SMB drive.
I created a bash script at
/home/pi/backup.sh
Code:
sudo service mysql stop
cp /var/lib/mysql/ibdata1 /media/readyshare/rpints
cp /var/www/tempdata.db /media/readyshare/rpints
sudo service mysql start
This script stops MySQL, copies the R'Pints data file and my logger data file to the SMB drive folder, then starts MySQL again and exits.
After writing out the script, be sure to set it to
executable for owner and group.
Finally, I added a command to root's crontab to run the script every night at 12:05 AM:
Code:
$ sudo crontab -e -u root
Code:
5 0 * * * /home/pi/backup.sh > /dev/null 2>&1
Et voila! Automated critical file backups!
Cheers!
[edit] This requires
cifs-utils which I believe is part of the standard Debian distributions these days, but it's easy to check to see if it's already installed:
Code:
$ dpkg -s cifs-utils
Package: cifs-utils
Status: install ok installed
If it hasn't been installed, do this:
Code:
$ sudo apt-get update
$ sudo apt-get install cifs-utils