ecdye / zram-config

A complete zram-config utility for swap, directories, and logs to reduce SD, NAND and eMMC block wear.
MIT License
412 stars 53 forks source link

Add ability to sync files to disk periodically #72

Closed Jack20947 closed 2 years ago

Jack20947 commented 2 years ago

At the moment zram-config merges the content of the upper overlay in RAM to the hdd (or SD card) only if the service is stopped manually or during shutdown. There may be many use-case where the machine is not restarted for many days, for example a raspberry pi that is used for pihole, vpn, and so on. And in this case, if a power interruption happens, the log is lost. Is it possible to add a functionality that copy the RAM overlay to the hdd periodically? (once a day for example)

ecdye commented 2 years ago

Possible too, yes, it is certainly a feature that could be useful.

I would like to remind you that the real solution to this problem is to purchase a UPS (Uninterruptible Power Supply) and plug your Pi into it if the data you are putting in zram is important enough to warrant the need of a periodic backup solution.

ecdye commented 2 years ago

After a closer look at the code, this would likely require a restart of zram to accomplish the desired outcome of syncing the data to the disk. This is because of the way the overlayfs operates and when syncing it is ideal to unmount the overlayed directory necessitating a stop of the zram process.

As a result of this, my current recommendation until such a time that there have been real official tools created for overlayfs (unlikely) is to use a service like cron to restart zram-config as often as you would like.

Jack20947 commented 2 years ago

Ok thanks. Also https://github.com/azlux/log2ram uses a cron to rsync the content of the ram to the disk. so I suppose it can be done without restarting the service. (I'm not using ram2log because I can't use the zram as swap with it).

ecdye commented 2 years ago

LogToRam can do that because it does not use the overlayfs system that zram-config uses. As I mentioned earlier, the overlayfs is what really prevents me from doing the same thing in zram-config.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ecdye commented 2 years ago

There may actually be a way to do this after some research. I will report back with my findings.