struct snapshot_list sl;
struct snapshot *victim;
struct disk_space ds;
- const char *why;
+ char *why;
lock_dss_or_die();
ret = get_disk_space(".", &ds);
return ret;
log_disk_space(&ds);
dss_get_snapshot_list(&sl);
- why = "outdated";
- victim = find_outdated_snapshot(&sl);
- if (victim)
- goto rm;
- why = "redundant";
- victim = find_redundant_snapshot(&sl);
- if (victim)
- goto rm;
- dss_msg("nothing to prune\n");
- ret = 0;
- goto out;
-rm:
+ victim = find_removable_snapshot(&sl, disk_space_low(&ds), &why);
+ if (!victim) {
+ dss_msg("nothing to prune\n");
+ ret = 0;
+ goto free_sl;
+ }
if (OPT_GIVEN(DSS, DRY_RUN)) {
- dss_msg("%s snapshot %s (interval = %i)\n",
+ dss_msg("picking %s snapshot %s (interval = %i)\n",
why, victim->name, victim->interval);
ret = 0;
- goto out;
+ goto free_why;
}
pre_remove_hook(victim, why);
if (snapshot_removal_status == HS_PRE_RUNNING) {
ret = wait_for_remove_process();
if (ret < 0)
- goto out;
+ goto free_why;
ret = -E_HOOK_FAILED;
if (snapshot_removal_status != HS_PRE_SUCCESS)
- goto out;
+ goto free_why;
}
ret = exec_rm();
if (ret < 0)
- goto out;
+ goto free_why;
ret = wait_for_remove_process();
if (ret < 0)
- goto out;
+ goto free_why;
assert(snapshot_removal_status == HS_SUCCESS);
post_remove_hook();
assert(snapshot_removal_status == HS_POST_RUNNING);
ret = wait_for_remove_process();
- if (ret < 0)
- goto out;
- ret = 1;
-out:
+free_why:
+ free(why);
+free_sl:
free_snapshot_list(&sl);
return ret;
}
snapshots.
[/description]
[subcommand prune]
- purpose = remove redundant and outdated snapshots
+ purpose = remove snapshots
[description]
- A snapshot is considered outdated if its interval number is greater or
- equal than the specified number of unit intervals. See --unit-interval
- and --num-intervals above.
-
- A snapshot is said to be redundant if the interval it belongs to
- contains more than the configured number of snapshots.
-
- The prune command gets rid of both outdated and redundant snapshots. At
- most one snapshot is removed per invocation. If --dry-run is given, the
- subcommand only prints the snapshot that would be removed.
+ A snapshot is said to be (a) outdated if its interval number is greater
+ or equal than the specified number of unit intervals, (b) redundant if
+ the interval it belongs to contains more than the configured number of
+ snapshots, and (c) orphaned if it is incomplete and not being created
+ or deleted. All other snapshots are called regular.
+
+ Unless --dry-run is given, which just prints the snapshot that would be
+ removed, this subcommand gets rid of non-regular snapshots. At most
+ one snapshot is removed per invocation. If no such snapshot exists
+ and disk space is low, the subcommand also removes regular snapshots,
+ always picking the oldest one.
+
+ The subcommand fails if there is another dss "run" process.
[/description]
[subcommand ls]
purpose = print the list of all snapshots
DSS_ERROR(INVALID_NUMBER, "invalid number"), \
DSS_ERROR(STRFTIME, "strftime() failed"), \
DSS_ERROR(LOCALTIME, "localtime() failed"), \
+ DSS_ERROR(HOOK_FAILED, "hook failure"), \
DSS_ERROR(MOUNTPOINT, "destination directory is no mountpoint"), \
DSS_ERROR(NULL_OPEN, "can not open /dev/null"), \
DSS_ERROR(DUP_PIPE, "exec error: can not create pipe"), \