Lowering SD-card wear?

Hi,

I am running HASS in a Ubuntu Server 16.04 VM on my homeserver (Intel NUC running VMware ESXi).
However i am looking at lowering my energy bill and maybe want to go the RPi route instead of a fully blown homeserver to achieve this lowering of my energy bill.

But what i am concerned about, is the wear of the SD-card when used in a RPi. Are there any precautions needed to be done to prevent this? For example the OZW_Log.txt is getting written very often.

Anyone some good ideas about this? Write that kind of logs to a ramdrive, or adding a USB-stick to write the stuff to? (which is also flashmedia and will wear?)

While no help to you actual question, might I recommend looking at the oDroid XU4 and using eMMC instead of a SD Card? From what I understand, eMMC is faster and has better longevity than a SD Card (I could be wrong about the longevity, but I know eMMC is faster in my XU4).

Alternatively, have you considered a SLC SD card?

I’m using a Pine A64 2GB for HA currently, but considering switching to my oDroid XU4 primarily because of the eMMC. Not to mention the XU4 is half the size of the Pine.

Good luck!

I run 4 RPi’s around the house running all sorts such as Apache with multiple virtual hosts, Transmission, Squid, Home Assistant, MiniDLNA and Inlfuxdb. I have never had any issues with SD wear with the longest running Pi having used the same SD card for 4 years.

That being said, I would take two things into consideration. SD cards are cheap, top of the range Samsung EVO of Sandisk extreme can be had for around £10-£15 so buy big - at least 16GB, maybe 32GB. The bigger the card the more the room the wear leveller has to use. And secondly backup regularly (I personally do this weekly via a cron job over SSH to a USB hard disk) because if an SD card does fail it is then only the very low cost of a new card and half hour to image it to get the PI back online.

2 Likes

Being new to pi, can you tell me how you scheduled that and how it saves full backup of your pi?

I wouldn’t be too concerned about lifespan. Enterprise Cisco routers used to run from PCMCIA cards and last for years. http://www.apotelyt.com/photo-memory/sd-card-reliability

My prod instance is running on a Cubieboard with the same SD card for almost 20 months now. Well, the NAND would be an option but that one is not supported by all distributions for installation.

I have a cron job that runs the following script at 2 am in the morning. Have redacted IP and port number:

rm /*.timestamp
ds=$(date +"%F_%T")
f="Last_Backup_$ds.timestamp"
touch /$f
rsync -aAX --delete --rsync-path="sudo rsync" --exclude-from 'exclude.list' -e "ssh -p port " / user@ip-address:/remote/backup/location

Exclude.list
/dev/*
/proc/*
/sys/*
/tmp/*
/run/*
/mnt/*
/media/*
/lost+found

Thanks, but the oDroid is crazy expensive (i see prices of 99EUR+). For that amount of money i can let my NUC run a few months :stuck_out_tongue:

The conclusion of this topic seems that wear isn’t a common problem. But i think a best practice would be to redirect OZW_Log.txt to /dev/null, because i don’t look in that often anyway and thus is writing without no reason to the SD-card.

I use a MariaDB instance on my Synology NAS to offload the HASS database (recorder) to. I think that helps reduce the wear quite a bit, even if it’s a non-issue. :slight_smile:

EDIT: today, I also modified the file /srv/hass/hass_venv/lib/python3.4/site-packages/libopenzwave-0.3.1-py3.4-linux-armv7l.egg/config/options.xml to disable logging by changing

<Option name="logging" value="true" />

to

<Option name="logging" value="false" />

As a result, the file OZW_Log.txt is still created but remains empty.

I have my database stored on an external harddrive hooked up to my Pi, which I also use to store all of my camera footage from my security system running MotionEye on the same Pi.

I just had my card fail on me 3 days ago, but what saved me, is that I have a live, bootable backup of my SD card that is updated at midnight every night. So I have a backup SD card in a tiny reader stuck in one of the USB ports, and at midnight, it mounts the partitions and rsync’s only the changes between the 2 cards.

When my card failed 3 days ago, I shutdown the Pi, popped out the backup SD from the reader and put it into my Pi in place of the dead one and I was backup and running with my full Home Assistant setup in a few minutes, without any loss of data. I have upgraded both my primary and backup to use 32 GB cards, mainly because they are cheap and I have a lot of other projects I am running on the same Pi and could use the extra space.

So once my card fails, I swap it with the backup and put another brand new 32GB in the card reader so that the initial backup starts over again.

Here is the github for the script:

https://github.com/billw2/rpi-clone

I have 2 copies of the script…

1 unaltered that asks questions, such as verification if you want to overwrite the SD card, etc, and if you want to unmount after the backup. That way I can run a manual backup if I want, in cases when I make a lot of changes and want to make sure those changes are backed up without having to wait till midnight.

and

1 that I edited to mark out the prompts so that I can run it automated with a cron job.

This is the best option for a backup, because it backs up the live running system, and is a fully bootable backup, so the backup card is ready to be booted on a moments notice should anything happen to your primary card.

UPDATE**

I forgot a couple of extra things:

  1. I try to boot from the back up at least once every couple weeks, just to ensure that it is still a good booting copy.

  2. I also run a separate script that creates a .img of my current running system every other day, again, without shutting down, so if for some reason my live backup SD card will not boot, I have a .img that I can dd to a new card just like you would the noobs .img or a raspbian .img, so I can just copy it to a new SD card and be back up and running again without no more than 1 day behind on data. I have it set to be limited to 3 backups, so I only have 3 .img files at a time and it removes the oldest one before backuping up a new one.

Here is where you can get the script for creating .img files:
https://www.linux-tips-and-tricks.de/en/raspberry/303-pi-creates-automatic-backups-of-itself

There is a LOT of information on that page, so read through it at your leisure, but it is necessary to understand exactly how the script works and how to use it.

5 Likes

Here’s my backup now:


I have shared directory on my Windows machine and make encrypted backup with rsnapshot (=rsync) with it every night.

@jbardi Would you mind sharing your altered version of rip-clone please as I too would like to run it as a cron job, and would save me digging through the code if it’s already been done.

Thanks!

As of HA 0.76, the options.xml file that has the logging true/false flag is in ~/.homeassistant/options.xml

1 Like

Hi @jbardi, I had an SD failure on my Hass.io install of Home Assistant and despite having saved backup snapshots I lost a lot of data and spent a day rebuilding my system on a fresh card. As a consequence, I’ve been looking at better ways to backup and restore in the event of future failure and came across your script.

Unfortunately, I’m not a techy/developer but I do manage to stumble my way through getting things working and therefore, wondered if you have any thoughts on how I may go about implementing your scripts of on a Hass.io build?

I have the HA database hosted externally using MariaDB 10 on a NAS - no SD card issues yet and HA runs much faster also.

How much power does your NUC use? I don’t own one but people often claim they use very little power.

I find this helps reduce size and activity by the database by 95%.

recorder:
  db_url:   mysql+pymysql://hass:[email protected]/HOMEBASE
  exclude:
    event_types:
      - service_removed
      - service_executed
      - platform_discovered
      - homeassistant_start
      - homeassistant_stop      
      - feedreader
      - service_registered
      - call_service
      - component_loaded
      - logbook_entry
      - system_log_event
      - automation_triggered
      - script_started
      - timer_out_of_sync