https://github.com/johnramsden/zfsdesnap
Tool to destroy all ZFS snapshots before a certain date, based off name and date format +%Y-%m-%d-%H%M%S. Written in bourne shell.
https://github.com/johnramsden/zfsdesnap
bourne shell shellscript snapshot systemd-unit zfs-snapshots
Last synced: 25 days ago
JSON representation
Tool to destroy all ZFS snapshots before a certain date, based off name and date format +%Y-%m-%d-%H%M%S. Written in bourne shell.
- Host: GitHub
- URL: https://github.com/johnramsden/zfsdesnap
- Owner: johnramsden
- License: bsd-3-clause
- Created: 2016-09-24T23:18:16.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-03T10:08:38.000Z (almost 8 years ago)
- Last Synced: 2025-05-14T15:06:44.265Z (26 days ago)
- Topics: bourne, shell, shellscript, snapshot, systemd-unit, zfs-snapshots
- Language: Shell
- Size: 27.3 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# zfsdesnap
Tool to destroy all ZFS snapshots before a certain date, based off a configurable name and date format. Written in bourne shell.
## Commandline Flags
* ```-p``` Running with a prefix.
* ```-d``` Date snapshots should be destroyed before.
* ```-n``` (Optional) Run in test mode, will not destroy anything.
* ```-a``` (Optional) Ask before destroying snapshot.
* ```-r``` (Optional) Run only on specified dataset.
* ```-f``` (Optional) Set format of date. Uses grep syntax ```[[:digit:]]{n}```. Default is set to:```[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}-[[:digit:]]{6}```.## Usage
To use the script, name snapshots in the format ```zpool@${prefix}-$(date +%Y-%m-%d-%H%M%S)```, then call ```zfsdesnap``` with a specified date that all snapshots should be destroyed before. Optionally a specific dataset can be given with ```-d```, prefix with ```-p```, and with ```-f``` the format of date to look for can be changed.
### Examples
For example, to destroy all snapshots with the prefix "pre-install":
Destroy all snapshots with the prefix "pre-install" that are over a week old.
```shell
zfsdesnap -p "pre-install" -d "$(date -d '1 week ago' +%Y-%m-%d-%H%M%S)"
Running in test mode, will not destroy anything
Running with prefix: pre-install
Date: 2016-09-18-171206
2016-09-18-171206
Date 2016-09-18-171206 accepted
Destroy before date was set to 2016-09-18-171206
Removing hyphens
Destroydate: 20160918171206
Running on all datasets
```Too use a different date format it can be specified with ```id```. For example, to specify older than a week ago in format year-month-day:
```shell
zfsdesnap -p "pre-install" -d "$(date -d '1 week ago' +%Y-%m-%d)" -f "[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}"
Running in test mode, will not destroy anything
Running with prefix: pre-install
Date: 2016-09-18
Date format: [[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}
2016-09-18
Date 2016-09-18 accepted
Destroy before date was set to 2016-09-18
Removing hyphens
Destroydate: 20160918
Running on all datasets
```## systemd Units
To use routinely with the provided systemd units, move them into the location your system keeps user units in, most likely ```/etc/systemd/system```.
Next specify each prefix you would like to be delete and start or enable the timer.
So for the prefix "pre-install":
```shell
systemctl enable [email protected]
```There are provided units for snapshots a week, ```zfsdesnap-week@```, month ```zfsdesnap-month@```, and year ```zfsdesnap-year@``` old.