Regular backup script

My V Low Write EMONCMS is working well and is almost at its completed stage so my thoughts turn to backups for when the inevitable SD Card problems occur. I would like to find a way of backing the data up so I can use a combination of an image restore onto a new card with a restore of the data from a attached USB stick.

Is there a way of automating a data backup to USB stick? I'm thinking maybe 3 folders on the stick called "newest", "older" and "oldest" and get the script to:

delete everything in the "oldest" folder then
move all "older" files to the "oldest" folder
move all "newest" files to the "older" folder
backup the current data to the "newest" folder

That way I have at least 2 backups to work from in case the pi crashes half way through backing up

Can I simply copy the whole of /home/pi/data together with its subs and be good to go or is it more complicated than that? I'm running VLow Write 8.5 but may move to V9.x when I have time to try upgrading again from the EMONPI image

Jon's picture

Re: Regular backup script

Kevin - I created a backup script for similar reasons (SD failure & eventual upgrade to v9.x).  Enclosed is the script I use.  It is not an image backup, but it is automated via the enclosed script and a cron entry. And it does backup to a USB stick.  

I cannot answer the question about what to backup (i.e., just the /home/pi/data together with its subs).  Someone with more experience will need to answer.  Currently I backup most everything on my emonPi.

The script:

  • mounts the USB stick
  • creates a new folder for each backup.  The folder is named with the current date and time.  
    • (You’ll need to change this part to a three folder backup script).  
  • does a mySQL backup
  • does an incremental backup of most all files on the emonPi
    • each new run backs up the files that change
    • all of the non-changed files are hard linked to the original backup
    • the excluded folders are listed in “exclude_from_list.txt” file
  • unmounts the USB stick
  • The first backup takes a l-o-n-g time.  Any incremental backup takes about 2-3 minutes.  

Full disclosure - This is the first Bash script I have written.  Suggestions for changes or corrections are welcome!

sheppy's picture

Re: Regular backup script

Jon,

Thanks very much, I'll give it a try. Folders with date / time are a lot more elegant than what I was thinking. I'll likely just add in a delete folder older than x days command to keep the stick from filling up, although I might just leave it as is and use a larger USB stick

Cheers

Kevin

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.