auto snapshots with zfs plugin

    • OMV 2.x

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • auto snapshots with zfs plugin


      i was waiting for btrfs support in openmediavault but it does not seem under way
      so i am switching my NAS from ext4 to ZFS which seems to be quite stable to what i hear

      (actually i have EXT4 drive and in parallel a copy of dataset with ZFS)

      up to now i am happy about the transfer

      I have one question about the usage of snapshot
      i have seen how to create a snapshot

      but i would like to know if there is any easy way in the ZFS plugin to create the snapshot automatically on schedule (maybe in the beta version)
      also to check errors it is necessary to launch some check/repaire command on a regular base ?
    • xavierlun wrote:

      maybe a nice feature of the ZFS plugin would be an interface to create those task easily

      I have been considering this, but it's extremely difficult to create a "general and intuitive" interface that at the same time needs to be specific... For now I won't add any such feature (and rather point to cron), but if someone can come up with a nice solution and send a pull request on GitHub I'm definitely willing to consider it.
    • nicjo814 wrote:

      That creates the proper cron jobs I guess?
      In cron tab added following

      Source Code

      1. # autosnapshot
      2. 0 */1 * * * root /usr/local/sbin/autosnapshot >/dev/null 2>&1



      1. #!/bin/sh
      2. #
      3. # Part of NAS4Free (
      4. # Copyright (c) 2012-2015 The NAS4Free Project <>.
      5. # All rights reserved.
      6. #
      7. TAG="Auto Snapshot"
      8. NOW=`/bin/date +%s`
      9. NOWHM=`/bin/date -j -f "%s" $NOW "+%H00"`
      10. autosnapshot_config="/var/etc/autosnapshot.conf"
      11. cat $autosnapshot_config | while read _type _path _name _recursive _timeday _timewday _timehour _timemin _lifetime _lifetimesec; do
      12. if [ -z "${_type}" ]; then continue; fi
      13. if [ "${_type}" != "daily" ]; then continue; fi
      14. #echo "$_type $_path $_name $_recursive $_timehour $_lifetime"
      15. if [ "$NOWHM" != "${_timehour}" ]; then continue; fi
      16. # current snapshot name
      17. name=`/bin/date -j -f "%s" $NOW "+${_name}"`
      18. if [ -z $name ]; then continue; fi;
      19. snapshot="${_path}@${name}"
      20. # oldest snapshot name
      21. TODAY=`date -j -f "%s" $NOW +%F`
      22. TODAYEPOCH=`date -j -f "%F %T" "$TODAY 12:00:00" +%s`
      23. DELEPOCH=`/bin/expr $TODAYEPOCH - ${_lifetimesec}`
      24. DELDAY=`date -j -f "%s" $DELEPOCH +%F`
      25. delname=`/bin/date -j -f "%F %H%M" "$DELDAY $NOWHM" "+${_name}"`
      26. if [ -z $delname ]; then continue; fi;
      27. delsnapshot="${_path}@${delname}"
      28. opt=""
      29. if [ "${_recursive}" = "true" ]; then
      30. opt="$opt -r"
      31. fi
      32. cmd="/sbin/zfs snapshot $opt $snapshot"
      33. delcmd="/sbin/zfs destroy $opt $delsnapshot"
      34. /usr/bin/logger -t "$TAG" "$cmd"
      35. eval "$cmd >/dev/null 2>&1"
      36. if [ ${_lifetimesec} -ne 0 ]; then
      37. /usr/bin/logger -t "$TAG" "$delcmd"
      38. eval "$delcmd >/dev/null 2>&1"
      39. fi
      40. done
      Display All


      Source Code

      1. ​daily data auto-%Y%m%d-%H0000 false * * 2000 0000 30d 2678400

      The post was edited 1 time, last by ab5031 ().

    • weebnuts wrote:

      any update on adding this to the GUI?
      There has been no progress in adding this to the gui.
      omv 4.1.23 arrakis | 64 bit | 4.15 proxmox kernel | omvextrasorg 4.1.15 plugins source code and issue tracker - github

      Please read this before posting a question and this and this for docker questions.
      Please don't PM for support... Too many PMs!
    • I have an issue with autocleaning snapshots.

      Cronjob creates daily snapshot:

      Source Code

      1. /sbin/zfs snapshot -r Storage/backup@backup_`date +"%F"`

      Cronjob to check age of snapshot and deletes it after 30 days:

      Source Code

      1. /sbin/zfs list -t snapshot -o name | /bin/grep Storage/backup@backup_ | /usr/bin/sort -r | /usr/bin/tail -n +30 | /usr/bin/xargs -n 1 /sbin/zfs destroy -r

      running this job gives me

      Source Code

      1. error #0:
      2. OMV\ExecException: Failed to execute command 'export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin; export LANG=C; export SHELL=/bin/sh; sudo --shell --non-interactive --user=root -- /sbin/zfs list -t snapshot -o name | /bin/grep Storage/backup@backup_ | /usr/bin/sort -r | /usr/bin/tail -n +30 | /usr/bin/xargs -n 1 /sbin/zfs destroy -r 2>&1' with exit code '123': missing dataset argument
      3. usage:
      4. destroy [-fnpRrv] <filesystem|volume>
      5. destroy [-dnpRrv] <filesystem|volume>@<snap>[%<snap>][,...]
      6. destroy <filesystem|volume>#<bookmark>
      7. For the property list, run: zfs set|get
      8. For the delegated permission list, run: zfs allow|unallow in /usr/share/openmediavault/engined/rpc/
      9. Stack trace:
      10. #0 /usr/share/php/openmediavault/rpc/ OMVRpcServiceCron->{closure}('/tmp/bgstatusO5...', '/tmp/bgoutputb9...')
      11. #1 /usr/share/openmediavault/engined/rpc/ OMV\Rpc\ServiceAbstract->execBgProc(Object(Closure))
      12. #2 [internal function]: OMVRpcServiceCron->execute(Array, Array)
      13. #3 /usr/share/php/openmediavault/rpc/ call_user_func_array(Array, Array)
      14. #4 /usr/share/php/openmediavault/rpc/ OMV\Rpc\ServiceAbstract->callMethod('execute', Array, Array)
      15. #5 /usr/sbin/omv-engined(536): OMV\Rpc\Rpc::call('Cron', 'execute', Array, Array, 1)
      16. #6 {main}
      Display All

      is the missing argument because of there are no snapshots older than 30 days or is there another syntax mistake?
      Chaos is found in greatest abundance wherever order is being sought.
      It always defeats order, because it is better organized.
      Terry Pratchett