User Tools

Site Tools


Schedule WeeWx Backup

If like me you feel you need to backup your weewx data regularly, then this is how I do it.

You need a NAS or something like that, that's always on.

Create a share on the NAS, with permissions for everyone.

Create a directory in /mnt (on the RPi) where we are going to mount this new share. Now mount this share:

mount -t nfs <ip address of nas>:/share/on-nas /mnt/directory-on-rpi

example: (in my case)

mount -t nfs /mnt/nas2/weewx

so now you could copy a random file to /mnt/nas2/weewx/ using the RPi and then check the NAS to see if it's copied over OK. If it hasn't then check permissions and paths etc.

Now we need to get the RPi to mount the share at boot up otherwise when the power is cycled it won't be available to work with the scheduler cron.

so edit /etc/fstab and add to the bottom:        /mnt/nas2/weewx         nfs     _netdev,defaults,user,auto,noatime,intr   0 0

mod as required for you.

I found that the share didn't get mount on boot because the network came up after the fstab was done.

To try and sort this I edit /etc/rc.local and added before the exit 0:

mount -a

Now we need to make a script to do the backup job, create a file in root home

cd ~

now put this code into it:

rsync -a /var/lib/weewx/ /mnt/nas2/weewx/
rsync -a /etc/weewx/ /mnt/nas2/weewx/

save that and make it executable:

chmod +x

Now assuming the backup folder on NAS is empty, we can try our script manually to check it works


OK if that worked, then the NAS should have the backup files in it.

Now we want to schedule this to run once an hour (or whatever you want).

I run it at 3 mins past the hour, becuase I don't want to disturb the RPi when it's busy doing the website updates.

We need to set cron to run the script:

crontab -e

At the bottom of the page, put this line:

3   *   *   *   * /root/

Mod as required for your situation.

Then wait and check it's doing the job properly

backup-weewx.txt · Last modified: 1980/01/01 00:49 by chris