Commit Graph

47 Commits

Author SHA1 Message Date
Jonathan Carter
9c6f065589 Check whether we have zfs-auto-snapshot before running it 2017-06-06 11:06:16 +02:00
Jonathan Carter
62f5f7d920 Merge pull request #33 from aphor/master
zfs destroy will use -d for deferred destruction
2017-01-27 20:28:01 +02:00
Jonathan Carter
b74769894c Merge pull request #35 from bernhardschmidt/master
Fix frequent cronjob
2017-01-27 20:08:24 +02:00
Jonathan Carter
11130ba8d6 Merge pull request #43 from FransUrbo/prettify_SNAPSHOTS_OLD
"Prettify" long command line
2017-01-27 20:07:39 +02:00
Turbo Fredriksson
c4ad5eeac5 Break up the huge line where SNAPSHOTS_OLD (if --fast was used) to make
it easier to read and follow.
2015-04-03 17:34:16 +02:00
Bernhard Schmidt
b2e97c5fe0 use long options in frequent cronjob 2014-12-29 20:07:18 +01:00
Bernhard Schmidt
d3bdd2dc23 include default installation prefix in frequent cronjob 2014-12-29 20:05:26 +01:00
Jeremy McMillan
f2767ad43a zfs destroy will use -d for deferred destruction
I am working on a complimentary script that does log-shipping style replication to a backup volume for highly efficient incremental backups. This relies on "zfs send -R" and that the sets of snapshots existing on the source and backup destination overlap by at least one snapshot. I plan to use snapshot clones to place a "checkpoint" reservation on a snapshot that will be required for future backups.

In order to keep zfs-auto-snapshot from destroying a snapshot necessary for a future incremental backup replication stream, I will create an unmounted clone of that snapshot, and destroy any prior clones when the backup completes. 

Any snapshots destroyed by the zfs-auto-snapshot "zfs destroy -d" will be destroyed as the dependent clones are destroyed. Without the -d option, zfs-auto-snapshot would fail to destroy the old snapshot with a checkpoint clone, and it would persist until later snapshot jobs destroy it in subsequent runs. Since monthlies and weeklies are relatively infrequent, deferred destruction will reap the snapshots opportunistically as soon as the "checkpoint" clones are gone. Intermediate snapshots between the "checkpoint" reserved snapshots and the recent snapshots preserved by the zfs-auto-snapshot.sh will still be immediately destroyed.
2014-11-17 19:21:52 -06:00
Darik Horn
d5cb31aaae Install the cron.d part without the execute bit.
Resolve this lintian error:

	E: zfs-auto-snapshot: bad-permissions-for-etc-cron.d-script etc/cron.d/zfs-auto-snapshot 0755 != 0644
	W: zfs-auto-snapshot: executable-not-elf-or-script etc/cron.d/zfs-auto-snapshot

This should also resolve a related failure on Arch Linux.

Closes: zfsonlinux/zfs-auto-snapshot#4
Thanks: @bitloggerig
Thanks: @scottj97
2014-10-13 23:12:53 -05:00
Darik Horn
1ce72681bf Merge pull request #31 from virtualguy/patch-1
Update README
2014-10-13 20:41:01 -04:00
Darik Horn
a0df1ebcc1 Merge pull request #30 from mbaynton/remove-only
--destroy-only switch, --{pre,post} fixes
2014-10-13 20:39:40 -04:00
Darik Horn
0be4466869 Merge pull request #29 from mmalecki/pre-post
Add pre and post snapshot hooks
2014-10-13 20:37:12 -04:00
Darik Horn
9d2398ed8e Merge pull request #26 from borutmrak/master
Fix manpage path
2014-10-13 20:31:06 -04:00
virtualguy
bc1b65a66e Update README
Add some simple installation instructions
2014-08-18 21:38:32 +12:00
Mike Baynton
bfe4c911a8 Make --{pre,post}-snapshot optional, add --destroy-only, revise docs 2014-08-09 17:23:02 -05:00
Maciej Małecki
10f9b3e336 Document `--{pre,post}-snapshot 2014-08-07 02:08:29 +02:00
Maciej Małecki
c08f366c1c Abort if pre snapshot hook returns non-zero 2014-08-07 02:08:29 +02:00
Maciej Małecki
da5a8bd5b7 Add --{pre,post}-snapshot for pre and post creation hook 2014-08-07 02:08:23 +02:00
Borut Mrak
a1b89b6fef Makefile:
* Remove PREFIX from cron scripts - they should always end up in /etc.
  * Leave PREFIX for man page and program, and set it to /usr/local by default.
2014-04-23 09:31:30 +02:00
Darik Horn
d625c53af1 Merge pull request #25 from stuehmer/patch-1
Fix SNAPNAME to contain the DATE if label is empty
2014-04-16 10:45:48 -04:00
Roland Stühmer
dc6f5ddcd9 Fix SNAPNAME to contain the DATE if label is empty
When I didn't specify a `--label` on the commandline, the SNAPNAME was missing the $DATE component
2014-04-16 13:47:29 +02:00
Darik Horn
39bce83e0f Merge pull request #18 from hawkowl/master
Set zfs-auto-snapshot to use UTC time for snapshots
2013-06-24 14:19:33 -07:00
HawkOwl
6ea2d7f5b1 Set the snapshots to use UTC time, which makes the date/time display correctly in Windows 7 Previous Versions. 2013-06-24 21:48:47 +08:00
Mike Swanson
dd27aa1c56 Update Makefile for the manual page 2013-06-17 08:23:57 -05:00
Mike Swanson
f5fc21ace0 Add a manpage 2013-06-16 15:31:33 -07:00
Darik Horn
bf4e97b07d Add a switch for the fast zfs list invocation.
Implement a `--fast` switch that uses the optimized `zfs list`
invocation instead of the slower regular form.

If the optimized form is generally better, then use it as the
default and reverse the switch to `--slow` sometime later.

Issue: zfsonlinux/zfs-auto-snapshot#16
2013-05-08 19:36:44 -05:00
Darik Horn
53ad1dc042 Merge pull request #15 from tisoft/patch-1
Use only name property for zfs list
2013-05-08 15:33:31 -07:00
Markus Heberling
b6fba51643 Use only name property for zfs list
zfs list is very slow if it needs to retrieve other properties than name. See zfsonlinux/zfs#450 for reference.

This change uses only the name of the snapshot and uses awk to extract the snapshot date from the name and sort to sort it:

1. get all snapshot names, sorted by name
2. use grep to filter out any snapshot, that isn't correctly prefixed (maybe a check for the correct date format could also be added here)
3. use awk to extract the date and put the date before the snapshot
4. use sort to reverse sort this, first by date, then by snapshot name
5. use awk to remove the date, so that just the snapshot name is left

This significally speeds it up on my system (/root/zfs-auto-snapshot is the changed one, running with -n to get only the times for snapshot retrieval):

root@tatooine:/root# time /root/zfs-auto-snapshot -d -v // --label=frequent --keep=4 -n
Debug: Including rpool for regular snapshot.
Debug: Including rpool/DATA for regular snapshot.
Debug: Including rpool/DATA/ldap for recursive snapshot.
Debug: Including rpool/DATA/postgresql for recursive snapshot.
Debug: Including rpool/DATA/vm for regular snapshot.
Debug: Including rpool/DATA/vm/alderaan.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/bespin.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/coruscant.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/dagobah.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/dantooine.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/dev.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/monitor.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/office.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/test.example.net for recursive snapshot.
Debug: Including rpool/ROOT for recursive snapshot.
Debug: Excluding rpool/ROOT/ubuntu-1 because rpool/ROOT includes it recursively.
Doing regular snapshots of rpool rpool/DATA rpool/DATA/vm
Doing recursive snapshots of rpool/DATA/ldap rpool/DATA/postgresql rpool/DATA/vm/alderaan.example.net rpool/DATA/vm/bespin.example.net rpool/DATA/vm/coruscant.example.net rpool/DATA/vm/dagobah.example.net rpool/DATA/vm/dantooine.example.net rpool/DATA/vm/dev.example.net rpool/DATA/vm/monitor.example.net rpool/DATA/vm/office.example.net rpool/DATA/vm/test.example.net rpool/ROOT
Doing a dry run. Not running these commands...
zfs snapshot -o com.sun:auto-snapshot-desc='-'  'rpool@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy  'rpool@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-'  'rpool/DATA@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy  'rpool/DATA@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-'  'rpool/DATA/vm@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy  'rpool/DATA/vm@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/ldap@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy -r 'rpool/DATA/ldap@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/postgresql@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy -r 'rpool/DATA/postgresql@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/alderaan.example.net@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy -r 'rpool/DATA/vm/alderaan.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/bespin.example.net@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy -r 'rpool/DATA/vm/bespin.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/coruscant.example.net@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy -r 'rpool/DATA/vm/coruscant.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/dagobah.example.net@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy -r 'rpool/DATA/vm/dagobah.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/dantooine.example.net@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy -r 'rpool/DATA/vm/dantooine.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/dev.example.net@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy -r 'rpool/DATA/vm/dev.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/monitor.example.net@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy -r 'rpool/DATA/vm/monitor.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/office.example.net@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy -r 'rpool/DATA/vm/office.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/test.example.net@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy -r 'rpool/DATA/vm/test.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/ROOT@zfs-auto-snap_frequent-2013-04-16-2344'
zfs destroy -r 'rpool/ROOT@zfs-auto-snap_frequent-2013-04-16-2315'
@zfs-auto-snap_frequent-2013-04-16-2344, 15 created, 15 destroyed, 0 warnings.

real	0m6.936s
user	0m0.076s
sys	0m0.184s
root@tatooine:/root# time /sbin/zfs-auto-snapshot -d -v // --label=frequent --keep=4 -n
Debug: Including rpool for regular snapshot.
Debug: Including rpool/DATA for regular snapshot.
Debug: Including rpool/DATA/ldap for recursive snapshot.
Debug: Including rpool/DATA/postgresql for recursive snapshot.
Debug: Including rpool/DATA/vm for regular snapshot.
Debug: Including rpool/DATA/vm/alderaan.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/bespin.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/coruscant.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/dagobah.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/dantooine.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/dev.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/monitor.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/office.example.net for recursive snapshot.
Debug: Including rpool/DATA/vm/test.example.net for recursive snapshot.
Debug: Including rpool/ROOT for recursive snapshot.
Debug: Excluding rpool/ROOT/ubuntu-1 because rpool/ROOT includes it recursively.
Doing regular snapshots of rpool rpool/DATA rpool/DATA/vm
Doing recursive snapshots of rpool/DATA/ldap rpool/DATA/postgresql rpool/DATA/vm/alderaan.example.net rpool/DATA/vm/bespin.example.net rpool/DATA/vm/coruscant.example.net rpool/DATA/vm/dagobah.example.net rpool/DATA/vm/dantooine.example.net rpool/DATA/vm/dev.example.net rpool/DATA/vm/monitor.example.net rpool/DATA/vm/office.example.net rpool/DATA/vm/test.example.net rpool/ROOT
Doing a dry run. Not running these commands...
zfs snapshot -o com.sun:auto-snapshot-desc='-'  'rpool@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy  'rpool@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-'  'rpool/DATA@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy  'rpool/DATA@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-'  'rpool/DATA/vm@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy  'rpool/DATA/vm@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/ldap@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy -r 'rpool/DATA/ldap@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/postgresql@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy -r 'rpool/DATA/postgresql@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/alderaan.example.net@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy -r 'rpool/DATA/vm/alderaan.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/bespin.example.net@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy -r 'rpool/DATA/vm/bespin.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/coruscant.example.net@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy -r 'rpool/DATA/vm/coruscant.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/dagobah.example.net@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy -r 'rpool/DATA/vm/dagobah.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/dantooine.example.net@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy -r 'rpool/DATA/vm/dantooine.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/dev.example.net@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy -r 'rpool/DATA/vm/dev.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/monitor.example.net@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy -r 'rpool/DATA/vm/monitor.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/office.example.net@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy -r 'rpool/DATA/vm/office.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/DATA/vm/test.example.net@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy -r 'rpool/DATA/vm/test.example.net@zfs-auto-snap_frequent-2013-04-16-2315'
zfs snapshot -o com.sun:auto-snapshot-desc='-' -r 'rpool/ROOT@zfs-auto-snap_frequent-2013-04-16-2348'
zfs destroy -r 'rpool/ROOT@zfs-auto-snap_frequent-2013-04-16-2315'
@zfs-auto-snap_frequent-2013-04-16-2348, 15 created, 15 destroyed, 0 warnings.

real	3m30.995s
user	0m0.152s
sys	0m0.792s
root@tatooine:/root# 

I'm not an awk god, so I tried a bit until I got a working version. There might be better ways. I also don't know if this catches every adge case, but it is a start for improvement. :)
2013-04-17 01:07:00 +03:00
Darik Horn
cc9f1802ed Fix pool exclusions.
Use $ZPOOL_STATUS instead of $ZFS_STATUS for pool exclusions.

A mistaken variable name made the pool exclusion logic a no-op and
broke the --skip-scrub switch.

Also correct a trivial comment typo.
2012-01-21 16:32:30 -06:00
Darik Horn
d77af5a902 Update the README file to be more descriptive. 2012-01-10 08:10:05 -06:00
Darik Horn
b5bf1149ca Merge pull request #2 from ulope/master
Fixed --prefix and --sep regexes
2011-12-28 10:06:04 -08:00
Ulrich Petri
5fc395c2bb Fixed --prefix and --sep regexes
Fixes: #1
2011-12-28 17:06:34 +01:00
Darik Horn
d99147db7a Set keep=8 in the weekly cron job.
A default of keep=8 for weekly snapshot is more useful than keep=4,
which is no more protective than the default daily schedule.
2011-12-21 20:29:27 -06:00
Darik Horn
c8507a0da9 Change objects to datasets in help and comments.
In the usage synopsis and program comments, change "objects" to
"datasets" for consistency with upstream ZFS terminology.
2011-12-18 07:34:40 -06:00
Darik Horn
74359e51a7 Fix the hourly-daily transposition in the Makefile.
The hourly cron job was installed to cron.daily, and the daily cron
job was installed to cron.hourly, which caused incorrect scheduling.
2011-11-28 00:07:30 -06:00
Darik Horn
afdae86271 Remove redundant lines in the cron.d file. 2011-11-28 00:05:43 -06:00
Darik Horn
4b7609791b Split the cron file for anacron compatibilty.
Split the cron file so that the hourly, daily, weekly, and monthly
zfs automatic snapshots still happen even if the system is offline
temporarily during the scheduled event, such as during a reboot.

On Debian systems, if anacron is installed, then it is used to run
the /etc/cron.{hourly,daily,weekly,monthly} directories, but not
the /etc/cron.d directory. This means that /etc/cron.d jobs are not
run if the system is offline when crond would usually invoke them.
2011-11-25 14:26:08 -06:00
Darik Horn
5ce7a23384 Implement the --event option for :auto-snap-desc.
Set the com.sun:auto-snap-desc property on each snapshot to an
arbitrary value.  On Solaris, this property is set to the dash
character by default -- which is convention for NULL -- but it
can contain an FMRI status comment or other user data.
2011-11-23 10:44:32 -06:00
Darik Horn
2e26499f6a Rebase exit codes to above 127.
Most standard shell utilities return errors less than 128. Rebase the
exit codes of this script to reduce the liklihood of overlap.
2011-11-23 10:03:56 -06:00
Darik Horn
f7ceb28963 Implement --prefix parameter checking.
Also add -p to the getopt list of short options.
2011-11-23 10:00:24 -06:00
Darik Horn
4c14da4130 Consistently quote literal strings.
Apply some syntax hygiene. Quoting everything is a safe habit because
unquoted things can have subtle side-effects.
2011-11-22 23:36:51 -06:00
Darik Horn
249e6a4cb3 Fold the main loops into a do_snapshots function.
The two primary `for` loops were identical except for the '-r' flag.
2011-11-22 23:27:24 -06:00
Darik Horn
a0a43a42af Invert the --skip-scrub test.
The $opt_skip_scrub option was tested incorrectly, which caused
the --skip-scrub option to operate opposite intent.
2011-11-22 22:09:23 -06:00
Darik Horn
d8b1730015 Add an explicit exit 0 to the end of the script.
The implicit return is "$?", which can be set non-zero by
an earlier command.
2011-11-21 21:44:37 -06:00
Darik Horn
adebbd6fee Add -q to the getopt list of short options.
This corresponds to the --quiet option.
2011-11-21 21:40:04 -06:00
Darik Horn
5bdcaad4bf Expand the options variable in the cron part file.
Cron doesn't do variable substitution and zfs-auto-snapshot doesn't
load options from its environment.
2011-11-21 20:40:24 -06:00
Darik Horn
875b55c967 Repository creation. 2011-11-21 19:47:20 -06:00