Giter Site home page Giter Site logo

gestur1976 / zfs-autosnap Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 34 KB

ZFS-autosnap is a Bash script for managing ZFS dataset snapshots on a Linux system with ZFS filesystems. The script automatically creates snapshots for each dataset in a given ZFS pool and monitors the free space available. If the free space drops below a specified threshold, the script deletes the oldest snapshots until the free space is reached.

License: GNU General Public License v3.0

Shell 100.00%
backup zfs zfs-autosnapshot-rotation zfs-snapshots zfsonlinux

zfs-autosnap's Introduction

ZFS-AutoSnap

zfs-autosnap is a Bash script for managing ZFS dataset snapshots on a Linux system with ZFS filesystems. The script automatically creates snapshots for each dataset in a given ZFS pool and monitors the free space available. If the free space drops below a specified threshold, the script deletes the oldest snapshots until the free space is above this threshold.

Features

  • Automatic Snapshot Creation: Creates a snapshot for every dataset in the specified ZFS pool.
  • Space Monitoring and Management: Monitors the available space and deletes old snapshots if space falls below a certain threshold.
  • Configurable Free Space Threshold: Allows for a custom threshold for minimum free space; defaults to 200 GB if not specified.
  • Logging: Logs all operations to a file for audit and review.

Requirements

Installation

  1. Clone the repository to your local machine.
  2. Make the script executable:
chmod +x zfs-autosnap.sh
  1. Copy the script for example to /usr/local/bin
sudo cp zfs-autosnap.sh /usr/local/bin/

Usage

Run the script with the pool name as the first parameter and the minimum free space in GB as an optional second parameter.

zfs-autosnap.sh poolname [min_free_space_gb] [days_to_keep_snapshots] [days_to_keep_intradiary_snapshots]

If the second parameter is omitted, the script defaults to ensuring a minimum of 200 GB of free space. If the third parameter is omitted, the script defaults to keeping 30 days of snapshots. If the fourth parameter is omitted, the script defaults to keeping 7 days of intradiary snapshots.

Examples:

zfs-autosnap.sh tank 1000 60 14 # Deletes snapshots older than 60 days or when 1000 GB threshold is reached and deletes all intradiary snapshots older than 14 days.
zfs-autosnap.sh tank 1000 60    # Deletes snapshots older than 60 days or when 1000 GB threshold is reached and deletes all intradiary snapshots older than 7 days.
zfs-autosnap.sh tank 300        # Deletes snapshots older than 30 days or when 300 GB threshold is reached and deletes all intradiary snapshots older than 7 days.
zfs-autosnap.sh tank            # Deletes snapshots older than 30 days or when 200 GB threshold is reached and deletes all intradiary snapshots older than 7 days.

If the second parameter is omitted, the script defaults to ensuring a minimum of 200 GB of free space.

Configuration

To run this script as a cron job, edit your crontab with crontab -e and add a line like the following:

*/15 * * * * /path/to/zfs-autosnap.sh poolname 200 60 7 > /dev/null 2>&1

This example will run the script every 15 minutes, ensuring that poolname has at least 200 GB of free space and 7 days of intradiary snapshots.

Log File

The script writes its log to /var/log/snapshots.log. Make sure the user running the script has the necessary permissions to write to this file.

Notes

Before using the script, ensure that you understand the ZFS snapshot and delete operations and their impact on your system. This script assumes the ZFS tools are installed and the pool name provided is valid and mounted.

License

This script is released under the MIT License.

Contributing

Contributions to this project are welcome. Please fork the repository and submit a pull request.

Support

If you have any questions or need help with the script, please open an issue in the GitHub repository.

zfs-autosnap's People

Contributors

gestur1976 avatar

Watchers

 avatar

Forkers

ilxsh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.