diff options
author | Liu Bo <liubo2009@cn.fujitsu.com> | 2012-08-03 17:48:56 +0800 |
---|---|---|
committer | root <root@localhost.localdomain> | 2012-10-04 16:26:32 -0400 |
commit | f02827c1c03e5c6d7bd02fe49d8f365680fe1aee (patch) | |
tree | cf1da5c094c6dcf965440d61d8f034cfbb6e0727 /cmds-subvolume.c | |
parent | 95eeaf1c29774ad72b087e8b9d9938f5a17434b5 (diff) |
Btrfs-progs: list snapshots by generation
The idea is that we usually use snapshot to backup/restore our data, and the
common way can be a cron script which makes lots of snapshots, so we can end
up with spending some time to find the latest snapshot to restore.
This adds a feature for 'btrfs subvolume list' to let it list snapshots by their
_created_ generation.
What we need to do is just to list them in descending order and get the latest
snapshot. What's more, we can find the oldest snapshot as well by listing
snapshots in ascending order.
Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Diffstat (limited to 'cmds-subvolume.c')
-rw-r--r-- | cmds-subvolume.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/cmds-subvolume.c b/cmds-subvolume.c index f4aa80ff..8a81d36e 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -261,10 +261,12 @@ static int cmd_subvol_delete(int argc, char **argv) } static const char * const cmd_subvol_list_usage[] = { - "btrfs subvolume list [-p] <path>", + "btrfs subvolume list [-ps] <path>", "List subvolumes (and snapshots)", "", - "-p print parent ID", + "-p print parent ID", + "-s value list snapshots with generation in ascending/descending order", + " (1: ascending, 0: descending)", NULL }; @@ -273,11 +275,13 @@ static int cmd_subvol_list(int argc, char **argv) int fd; int ret; int print_parent = 0; + int print_snap_only = 0; + int order = 0; char *subvol; optind = 1; while(1) { - int c = getopt(argc, argv, "p"); + int c = getopt(argc, argv, "ps:"); if (c < 0) break; @@ -285,6 +289,10 @@ static int cmd_subvol_list(int argc, char **argv) case 'p': print_parent = 1; break; + case 's': + print_snap_only = 1; + order = atoi(optarg); + break; default: usage(cmd_subvol_list_usage); } @@ -310,7 +318,10 @@ static int cmd_subvol_list(int argc, char **argv) fprintf(stderr, "ERROR: can't access '%s'\n", subvol); return 12; } - ret = list_subvols(fd, print_parent, 0); + if (!print_snap_only) + ret = list_subvols(fd, print_parent, 0); + else + ret = list_snapshots(fd, print_parent, order); if (ret) return 19; return 0; |