Cloudron+ZFS?
-
ZFS is a next-gen filesystem that uses a Copy-on-Write (CoW) storage strategy to provide very useful features such as instant volume snapshots that only consume space proportional to the changes since the previous snapshot, and similarly support "0-storage-consumption" clones of volumes. Naturally, snapshots are the primary vehicle for backups in a ZFS environment. I see one thread asking about ZFS back in 2019, but I didn't see a cogent argument for Cloudron+ZFS. I think ZFS volumes as Cloudron app data volumes would be a match made in heaven.
Sorry for submitting a whole blog post
there's a TL;DR at the end.
ZFS Snapshots
There are various [1] excellent [2] explanations for ZFS snapshots and volumes you can find online, but this one is mine: When a new block of data is written in a ZFS volume the new data and the state of the filesystem after the write does not overwrite the existing block and filesystem, but is instead written to an unused location. Subsequent reads and writes see the the old filesystem masked/shadowed by the new data. Eventually these shadowed blocks can be reclaimed and written to again, but until then they still contain the full state of the filesystem at the time before they were shadowed. If the operator desires to save a particular state (aka take a backup) that's easy: just keep a pointer to it and don't let the data it references be reclaimed -- ZFS calls this a "snapshot". Snapshots are incredibly cheap to create in both time and space, since all it does is tell the system not to reclaim the blocks referenced by it. You don't write to a snapshot -- they are read-only -- but you can create a "cloned" volume based on a particular snapshot. Again, the new clone is very cheap to create and doesn't consume any storage itself until something writes data to it, masking the snapshot with the new data. One might think this system is conceptually similar to the way Docker's overlay2 filesystem driver works -- perhaps if it were much more mature and operationalized.
Cloudron + ZFS
With this knowledge of how ZFS snapshots work, their applicability as an underlying implementation for Cloudron's model of app data volumes becomes clear: Each app gets its own ZFS volume for /data. Backups are just snapshots of the volume and become instant, causing no interruption or degradation to app or system functionality. Restores are a cloned volume based on an existing snapshot and no longer require any extra space to initially create. App upgrades can be attempted and reverted immediately if needed. Since backups are cheap and truly incremental, it becomes viable to create them very frequently, potentially as often as every 10 minutes. This could even work for storage volumes hosting e.g. PostgreSQL database.
You may guess (correctly) that I think ZFS is friggin awesome and could be a good fit for Cloudron, but I admit that this very simplified presentation of the benefits leaves a lot of open questions and caveats unanswered as it applies to the Cloudron ecosystem. I explore some of these below.
The ZFS project
ZFS is typically a FreeBSD filesystem (see Wikipedia for a less truncated history), but ZFS-on-Linux (ZoL) project first made ZFS viable as a Linux filesystem in 2014 when it was first released as a package in Ubuntu 14.04. Late last year the project merged with the FreeBSD base, rebranded to OpenZFS in a combined code repository that supports many OSes, and (fwiw) released their first major versions going from v0.8.6 to 2.0.0 and then version 2.0.4 just last month.
Caveats & open questions
- Cloudron would surely not migrate everyone to ZFS by default (at least not this decade..) and the current simple backup strategy is too valuable in simple installations to ever just dispense with, which means ZFS would have to become a new option, with the maintenance and support burden that implies.
- In some situations ZFS could save storage space compared to a "normal" filesystem, but it would definitely complicate the storage space calculations since snapshots consume space until they are released. The main issue is that this storage consumption is not directly "visible" where an unknowing user might look (e.g. as files on a mount point) which could cause some confusion. Note, OpenZFS recommends maintaining at least 10% free space.
- A big feature of Cloudron backups is seamless remote backups, which are certainly possible -- elegant even -- for ZFS snapshots, but this would require some additional fleshing out before it could substitute in for the current fully featured backup and restore system.
- It gives users additional footguns to shoot themselves with. For example: the ZFS deduplication feature sounds great, but it requires more resources that one might think and probably shouldn't be enabled before careful consideration.
- There are surely other caveats.
Any others you can think of?
ZFS technology for Linux systems appears to be converging in 2021, and I think Cloudron's app backup and restore model would lend beautifully to being supported directly by ZFS. What do you think? Anyone using ZFS on Cloudron or otherwise?
TL;DR: yo I think ZFS is dope and could integrate nicely with Cloudron. hbu?
@infogulch Ubuntu offers ZFS as an experimental option during installation on the Focal Fossa 20.04 LTS release. If you e.g. setup a Virtual Machine with ZFS, and try and install Cloudron, you receive the following error message:
Error: Cloudron requires '/' to be ext4
I suppose the same thing will happen if you chose btrfs for the file system.
-
@infogulch Ubuntu offers ZFS as an experimental option during installation on the Focal Fossa 20.04 LTS release. If you e.g. setup a Virtual Machine with ZFS, and try and install Cloudron, you receive the following error message:
Error: Cloudron requires '/' to be ext4
I suppose the same thing will happen if you chose btrfs for the file system.
@LoudLemur removing this restriction would be useful.
-
@infogulch Ubuntu offers ZFS as an experimental option during installation on the Focal Fossa 20.04 LTS release. If you e.g. setup a Virtual Machine with ZFS, and try and install Cloudron, you receive the following error message:
Error: Cloudron requires '/' to be ext4
I suppose the same thing will happen if you chose btrfs for the file system.
@LoudLemur We use the overlay2 device driver in Docker. In the past, this device driver did not support btrfs atleast. See https://git.cloudron.io/cloudron/box/-/issues/364 . You can remove the check in the cloudron-setup script and see what happens.
-
There is a zfs storage driver that I think is relevant here: https://docs.docker.com/storage/storagedriver/zfs-driver/
-
Thanks for this interesting discussion. I am struggling with backup due to the volume (350/400GB) and wonder if having ZFS+snapshots would be better (faster, easier and more reliable) than Cloudron's way (tar or rsync)?
The new box is a Hetzner dedi with 2x 3TB and a 512GB NVMe. Instead of sRAID1 I am now pondering ZFS mirror with daily snapshots send to the Storagebox and perhaps part of the NVMe as a ZIL log.
I am keen to hear any thoughts and experience you may have folks
-
Thanks for this interesting discussion. I am struggling with backup due to the volume (350/400GB) and wonder if having ZFS+snapshots would be better (faster, easier and more reliable) than Cloudron's way (tar or rsync)?
The new box is a Hetzner dedi with 2x 3TB and a 512GB NVMe. Instead of sRAID1 I am now pondering ZFS mirror with daily snapshots send to the Storagebox and perhaps part of the NVMe as a ZIL log.
I am keen to hear any thoughts and experience you may have folks
@3246 that would auto dedupe at a file level, but the main issue is that backups would make it worse due to the tar and compression. Uncompressed you'd save way more space as most files would not change much.
That's why newer tech storage appliances tend to dedupe at a multiple of 4k bytes to be able to dedupe even more regardless of file type or compression type.
Otherwise one could play with storing rapidly or increasingly changing data differently than more static app data, which is exactly that Cloudron does, separating the two.
-
Thanks for this interesting discussion. I am struggling with backup due to the volume (350/400GB) and wonder if having ZFS+snapshots would be better (faster, easier and more reliable) than Cloudron's way (tar or rsync)?
The new box is a Hetzner dedi with 2x 3TB and a 512GB NVMe. Instead of sRAID1 I am now pondering ZFS mirror with daily snapshots send to the Storagebox and perhaps part of the NVMe as a ZIL log.
I am keen to hear any thoughts and experience you may have folks
@3246 I have a similar amount of data - pointing Cloudron‘s backup to a local drive via rsync and then pushing this snapshot via restic (and rclone) to Onedrive (via cron) works great. It’s encrypted, de-duped and mountable. Backup results are sent via email. If that’s interesting, i could share my setup.
-
@3246 I have a similar amount of data - pointing Cloudron‘s backup to a local drive via rsync and then pushing this snapshot via restic (and rclone) to Onedrive (via cron) works great. It’s encrypted, de-duped and mountable. Backup results are sent via email. If that’s interesting, i could share my setup.
@necrevistonnezr Please do.
-
@necrevistonnezr Please do.
@robi
I useTools
- rclone: https://rclone.org/docs/
- restic: https://restic.readthedocs.io/en/stable/030_preparing_a_new_repo.html#other-services-via-rclone
- ssmtp: https://wiki.archlinux.org/title/SSMTP
Installation
- Install tools above via apt
- afterwards update to latest version (repo versions are old):
sudo restic self-update && sudo rclone selfupdate
Setup rclone
- Enter an interactive setup process via
rclone config
- in my case I use Onedrive as it has 1TB of space coming with my Office 365 subscription
- for the rest of this summary, we assume you gave it the repository name "REPOSITORY"
- details at https://rclone.org/commands/rclone_config/
Setup restic
- set up a backup repository
restic -r rclone:REPOSITORY init
- for a subfolder on onedrive just use
restic -r rclone:REPOSITORY:subfolder init
- save password that you gave the repository in file
/home/USER/resticpw
- details at https://restic.readthedocs.io/en/latest/030_preparing_a_new_repo.html#other-services-via-rclone
Setup SSMTP
- for receiving backup results, otherwise not needed
- See https://wiki.archlinux.org/title/SSMTP
Cloudron Backup settings
- Provider: mountpoint
- Location:
/media/CloudronBackup
(<-- obviously adjust to your settings) - this creates a snapshot at
/media/CloudronBackup/snapshot
for the current backup - Storage Format: rsync
- Adjust schedule and retention to your liking
Backup, Prune and Check scripts
restic-cron-backup.sh
#!/bin/bash d=$(date +%Y-%m-%d) if pidof -o %PPID -x “$0”; then echo “$(date “+%d.%m.%Y %T”) Exit, already running.” exit 1 fi restic -r rclone:REPOSITORY:subfolder backup /media/CloudronBackup/snapshot -p=/home/USER/resticpw restic -r rclone:REPOSITORY:subfolder forget --keep-monthly 12 --keep-weekly 5 --keep-daily 14 -p=/home/USER/resticpw restic -r rclone:REPOSITORY:subfolder check --read-data-subset=2% -p=/home/USER/resticpw exit
First line does the backup (incremental, encrypted), second line is the backup retention, third line checks a random 2 % of all data for errors
restic-cron-prune.sh
#!/bin/bash d=$(date +%Y-%m-%d) if pidof -o %PPID -x “$0”; then echo “$(date “+%d.%m.%Y %T”) Exit, already running.” exit 1 fi restic -r rclone:REPOSITORY:subfolder prune -p=/home/USER/resticpw exit
removes unused data from the repository, I run this once a week
restic-cron-check.sh
#!/bin/bash d=$(date +%Y-%m-%d) if pidof -o %PPID -x “$0”; then echo “$(date “+%d.%m.%Y %T”) Exit, already running.” exit 1 fi restic -r rclone:REPOSITORY:subfolder check --read-data -p=/home/USER/resticpw exit
checks all data for errors, I run this once a week
Crontab
30 2 * * * sh /home/USER/restic-cron-backup.sh | mailx -s "Restic Backup Results" server@mydomain.com 1 5 1 * * sh /home/USER/restic-cron-prune.sh | mailx -s "Restic Prune Results" server@mydomain.com 1 8 1 * * sh /home/USER/restic-cron-check.sh | mailx -s "Restic Full Check Results" server@mydomain.com
Backup daily at 2:30, prune and check once a week. Receive results to specified mail
Mount backups
Just to be complete: You can mount restic backups locally like
restic -r rclone:REPOSITORY:subfolder mount /media/resticmount/ -p=/home/USER/resticpw && cd /media/resticmount
obviously adjust/media/resticmount/
to your settings; allows you to browse and copy from full snapshots for each backup -
@robi
I useTools
- rclone: https://rclone.org/docs/
- restic: https://restic.readthedocs.io/en/stable/030_preparing_a_new_repo.html#other-services-via-rclone
- ssmtp: https://wiki.archlinux.org/title/SSMTP
Installation
- Install tools above via apt
- afterwards update to latest version (repo versions are old):
sudo restic self-update && sudo rclone selfupdate
Setup rclone
- Enter an interactive setup process via
rclone config
- in my case I use Onedrive as it has 1TB of space coming with my Office 365 subscription
- for the rest of this summary, we assume you gave it the repository name "REPOSITORY"
- details at https://rclone.org/commands/rclone_config/
Setup restic
- set up a backup repository
restic -r rclone:REPOSITORY init
- for a subfolder on onedrive just use
restic -r rclone:REPOSITORY:subfolder init
- save password that you gave the repository in file
/home/USER/resticpw
- details at https://restic.readthedocs.io/en/latest/030_preparing_a_new_repo.html#other-services-via-rclone
Setup SSMTP
- for receiving backup results, otherwise not needed
- See https://wiki.archlinux.org/title/SSMTP
Cloudron Backup settings
- Provider: mountpoint
- Location:
/media/CloudronBackup
(<-- obviously adjust to your settings) - this creates a snapshot at
/media/CloudronBackup/snapshot
for the current backup - Storage Format: rsync
- Adjust schedule and retention to your liking
Backup, Prune and Check scripts
restic-cron-backup.sh
#!/bin/bash d=$(date +%Y-%m-%d) if pidof -o %PPID -x “$0”; then echo “$(date “+%d.%m.%Y %T”) Exit, already running.” exit 1 fi restic -r rclone:REPOSITORY:subfolder backup /media/CloudronBackup/snapshot -p=/home/USER/resticpw restic -r rclone:REPOSITORY:subfolder forget --keep-monthly 12 --keep-weekly 5 --keep-daily 14 -p=/home/USER/resticpw restic -r rclone:REPOSITORY:subfolder check --read-data-subset=2% -p=/home/USER/resticpw exit
First line does the backup (incremental, encrypted), second line is the backup retention, third line checks a random 2 % of all data for errors
restic-cron-prune.sh
#!/bin/bash d=$(date +%Y-%m-%d) if pidof -o %PPID -x “$0”; then echo “$(date “+%d.%m.%Y %T”) Exit, already running.” exit 1 fi restic -r rclone:REPOSITORY:subfolder prune -p=/home/USER/resticpw exit
removes unused data from the repository, I run this once a week
restic-cron-check.sh
#!/bin/bash d=$(date +%Y-%m-%d) if pidof -o %PPID -x “$0”; then echo “$(date “+%d.%m.%Y %T”) Exit, already running.” exit 1 fi restic -r rclone:REPOSITORY:subfolder check --read-data -p=/home/USER/resticpw exit
checks all data for errors, I run this once a week
Crontab
30 2 * * * sh /home/USER/restic-cron-backup.sh | mailx -s "Restic Backup Results" server@mydomain.com 1 5 1 * * sh /home/USER/restic-cron-prune.sh | mailx -s "Restic Prune Results" server@mydomain.com 1 8 1 * * sh /home/USER/restic-cron-check.sh | mailx -s "Restic Full Check Results" server@mydomain.com
Backup daily at 2:30, prune and check once a week. Receive results to specified mail
Mount backups
Just to be complete: You can mount restic backups locally like
restic -r rclone:REPOSITORY:subfolder mount /media/resticmount/ -p=/home/USER/resticpw && cd /media/resticmount
obviously adjust/media/resticmount/
to your settings; allows you to browse and copy from full snapshots for each backup@necrevistonnezr beautiful
Funny how you have to prune cuz it forgets.
-
@necrevistonnezr beautiful
Funny how you have to prune cuz it forgets.
-
@robi
I useTools
- rclone: https://rclone.org/docs/
- restic: https://restic.readthedocs.io/en/stable/030_preparing_a_new_repo.html#other-services-via-rclone
- ssmtp: https://wiki.archlinux.org/title/SSMTP
Installation
- Install tools above via apt
- afterwards update to latest version (repo versions are old):
sudo restic self-update && sudo rclone selfupdate
Setup rclone
- Enter an interactive setup process via
rclone config
- in my case I use Onedrive as it has 1TB of space coming with my Office 365 subscription
- for the rest of this summary, we assume you gave it the repository name "REPOSITORY"
- details at https://rclone.org/commands/rclone_config/
Setup restic
- set up a backup repository
restic -r rclone:REPOSITORY init
- for a subfolder on onedrive just use
restic -r rclone:REPOSITORY:subfolder init
- save password that you gave the repository in file
/home/USER/resticpw
- details at https://restic.readthedocs.io/en/latest/030_preparing_a_new_repo.html#other-services-via-rclone
Setup SSMTP
- for receiving backup results, otherwise not needed
- See https://wiki.archlinux.org/title/SSMTP
Cloudron Backup settings
- Provider: mountpoint
- Location:
/media/CloudronBackup
(<-- obviously adjust to your settings) - this creates a snapshot at
/media/CloudronBackup/snapshot
for the current backup - Storage Format: rsync
- Adjust schedule and retention to your liking
Backup, Prune and Check scripts
restic-cron-backup.sh
#!/bin/bash d=$(date +%Y-%m-%d) if pidof -o %PPID -x “$0”; then echo “$(date “+%d.%m.%Y %T”) Exit, already running.” exit 1 fi restic -r rclone:REPOSITORY:subfolder backup /media/CloudronBackup/snapshot -p=/home/USER/resticpw restic -r rclone:REPOSITORY:subfolder forget --keep-monthly 12 --keep-weekly 5 --keep-daily 14 -p=/home/USER/resticpw restic -r rclone:REPOSITORY:subfolder check --read-data-subset=2% -p=/home/USER/resticpw exit
First line does the backup (incremental, encrypted), second line is the backup retention, third line checks a random 2 % of all data for errors
restic-cron-prune.sh
#!/bin/bash d=$(date +%Y-%m-%d) if pidof -o %PPID -x “$0”; then echo “$(date “+%d.%m.%Y %T”) Exit, already running.” exit 1 fi restic -r rclone:REPOSITORY:subfolder prune -p=/home/USER/resticpw exit
removes unused data from the repository, I run this once a week
restic-cron-check.sh
#!/bin/bash d=$(date +%Y-%m-%d) if pidof -o %PPID -x “$0”; then echo “$(date “+%d.%m.%Y %T”) Exit, already running.” exit 1 fi restic -r rclone:REPOSITORY:subfolder check --read-data -p=/home/USER/resticpw exit
checks all data for errors, I run this once a week
Crontab
30 2 * * * sh /home/USER/restic-cron-backup.sh | mailx -s "Restic Backup Results" server@mydomain.com 1 5 1 * * sh /home/USER/restic-cron-prune.sh | mailx -s "Restic Prune Results" server@mydomain.com 1 8 1 * * sh /home/USER/restic-cron-check.sh | mailx -s "Restic Full Check Results" server@mydomain.com
Backup daily at 2:30, prune and check once a week. Receive results to specified mail
Mount backups
Just to be complete: You can mount restic backups locally like
restic -r rclone:REPOSITORY:subfolder mount /media/resticmount/ -p=/home/USER/resticpw && cd /media/resticmount
obviously adjust/media/resticmount/
to your settings; allows you to browse and copy from full snapshots for each backup@necrevistonnezr amazing! Thank you for sharing
I am pondering a similar approach and currently back up to a secondary internal drive via rsync without encryption, although the backup drive is using LUKS.
I wonder if using rclone crypt instead of encrypting the files via restic would gain any advantages (e.g. maximum file / folder names, depth, speed)?
Cloudron > rsync to local drive > rclone/crypt via restic > remote
-
@necrevistonnezr amazing! Thank you for sharing
I am pondering a similar approach and currently back up to a secondary internal drive via rsync without encryption, although the backup drive is using LUKS.
I wonder if using rclone crypt instead of encrypting the files via restic would gain any advantages (e.g. maximum file / folder names, depth, speed)?
Cloudron > rsync to local drive > rclone/crypt via restic > remote
Just reading up on restic and encryption, etc and may just skip the rclone part as I am looking to either go to Wasabi or Hetzner Storagebox.
However, I kinda like the crypt part and am looking for any comparisons between rclone/crypt with restic and restic w/ encryption in terms of time it takes to backup and any drawbacks.
-
Just reading up on restic and encryption, etc and may just skip the rclone part as I am looking to either go to Wasabi or Hetzner Storagebox.
However, I kinda like the crypt part and am looking for any comparisons between rclone/crypt with restic and restic w/ encryption in terms of time it takes to backup and any drawbacks.
@3246 said in Cloudron+ZFS?:
Just reading up on restic and encryption, etc and may just skip the rclone part as I am looking to either go to Wasabi or Hetzner Storagebox.
However, I kinda like the crypt part and am looking for any comparisons between rclone/crypt with restic and restic w/ encryption in terms of time it takes to backup and any drawbacks.
Just to be clear: The encryption (as well as deduplication, the repository, data integrity checks, etc.) is completely handled by restic. rclone is just the "transporter tool" that copies data to providers that the restic does not handle (restic out-of-the-box currently handles SFTP, REST-Server, Minio, Wasabi, etc. see https://restic.readthedocs.io/en/stable/030_preparing_a_new_repo.html).
-
@3246 said in Cloudron+ZFS?:
Just reading up on restic and encryption, etc and may just skip the rclone part as I am looking to either go to Wasabi or Hetzner Storagebox.
However, I kinda like the crypt part and am looking for any comparisons between rclone/crypt with restic and restic w/ encryption in terms of time it takes to backup and any drawbacks.
Just to be clear: The encryption (as well as deduplication, the repository, data integrity checks, etc.) is completely handled by restic. rclone is just the "transporter tool" that copies data to providers that the restic does not handle (restic out-of-the-box currently handles SFTP, REST-Server, Minio, Wasabi, etc. see https://restic.readthedocs.io/en/stable/030_preparing_a_new_repo.html).
@necrevistonnezr thank you. Is the encryption always part of restic or optional? It looks like it's baked-in the way repos are build, right?
-
@necrevistonnezr thank you. Is the encryption always part of restic or optional? It looks like it's baked-in the way repos are build, right?
@3246 Yes. There is discussions about it (see https://github.com/restic/restic/issues/1018) but that's actually on of the features of restic: It's encryption done right.
And being able to mount the repositories and directly access them is just fantastic. -
@3246 Yes. There is discussions about it (see https://github.com/restic/restic/issues/1018) but that's actually on of the features of restic: It's encryption done right.
And being able to mount the repositories and directly access them is just fantastic.@necrevistonnezr very interesting. Thank you for sharing that link too. I'll give it a try without the rclone step soon
-
I cribbed off the scripts kindly provided by @necrevistonnezr and am using restic straight to a Hetzner Storagebox.
The first upload is running:
[23:53] 0.59% 427 files 4.571 GiB, total 1344856 files 772.976 GiB, 0 errors ETA 66:59:14
Not quite sure where the 772GB are coming from as the directory is much smaller?
390G /mnt/local_backups/rsync/2022-05-03-130134-941 1.4G /mnt/local_backups/rsync/snapshot
-
All these posts about backing up locally and then to somewhere else are really useful, but a bit hidden away in this thread about something pretty tenuously related.
Methinks @staff should move some of them into a new thread of their own
-
I cribbed off the scripts kindly provided by @necrevistonnezr and am using restic straight to a Hetzner Storagebox.
The first upload is running:
[23:53] 0.59% 427 files 4.571 GiB, total 1344856 files 772.976 GiB, 0 errors ETA 66:59:14
Not quite sure where the 772GB are coming from as the directory is much smaller?
390G /mnt/local_backups/rsync/2022-05-03-130134-941 1.4G /mnt/local_backups/rsync/snapshot
@3246 Are you backing up
/snapshot/
or the parent directory?
/snapshot/
is sufficient for a daily backup as it holds the current status of all files - versioning etc. is done by restic.
Also, how did you calculate these dirsizes?