Expand lifespan of SD-card or SSD drive
Posted: Thursday 10 February 2022 11:55
If you use the 'data' section in dzVents scripts or use executeShellCommand in your scripts with a callback, then data is (frequently) written to the default path /home/pi/domoticz/scripts/dzVents/data.
This method save write cycles to the SD-card or SSD drive.
You should have rsync installed or change the rsync command to the cp command
You might have to do some small changes if you run Domoticz as a different user.
First create a tmpfs at boot of this path in /etc/fstab with
Size of 1 Mb should be enough.
Then create a backup directory with
Now create a service that does the job with
and paste the following code
Execute the following commands
Now you are done and have a 1M ramdrive for the Domoticz data which will be saved to the backup dir if you shutdown or reboot the system and will be copied back from that backup dir to the data dir at boot of the system.
This method save write cycles to the SD-card or SSD drive.
You should have rsync installed or change the rsync command to the cp command
You might have to do some small changes if you run Domoticz as a different user.
First create a tmpfs at boot of this path in /etc/fstab with
Code: Select all
tmpfs /home/pi/domoticz/scripts/dzVents/data tmpfs rw,size=1M 0 0
Then create a backup directory with
Code: Select all
mkdir /home/pi/domoticz/scripts/dzVents/data_backup
Code: Select all
sudo nano /lib/systemd/system/ramdisk-sync.service
Code: Select all
[Unit]
Before=umount.target
[Service]
Type=oneshot
User=root
ExecStartPre=/bin/chown -Rf pi:pi /home/pi/domoticz/scripts/dzVents/data/
ExecStart=/usr/bin/rsync -ar /home/pi/domoticz/scripts/dzVents/data_backup/ /home/pi/domoticz/scripts/dzVents/data/
ExecStop=/usr/bin/rsync -ar /home/pi/domoticz/scripts/dzVents/data/ /home/pi/domoticz/scripts/dzVents/data_backup/
ExecStopPost=/bin/chown-Rf pi:pi /home/pi/domoticz/scripts/dzVents/data_backup
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Code: Select all
sudo systemctl daemon-reload
sudo systemctl enable ramdisk-sync.service
sudo systemctl start ramdisk-sync.service
sudo reboot