From d8ad9f986e021e4b1e1e67e8376f122d55c8e816 Mon Sep 17 00:00:00 2001 From: Eric Fried Date: Fri, 24 May 2019 08:20:19 -0500 Subject: [PATCH] Clarify --before help text in nova manage The --before option to nova manage db purge and archive_deleted_rows accepts a string to be parsed by dateutils.parser.parse() with fuzzy=True. This is fairly forgiving, but doesn't handle e.g. "now - 1 day". This commit adds some clarification to the help strings, and some examples to the docs. Change-Id: Ib218b971784573fce16b6be4b79e0bf948371954 --- doc/source/cli/nova-manage.rst | 35 +++++++++++++++---- nova/cmd/manage.py | 9 +++-- ...rchive-before-option-8296af1c815f5f8a.yaml | 2 +- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/doc/source/cli/nova-manage.rst b/doc/source/cli/nova-manage.rst index 53adecb7c9..265590ab37 100644 --- a/doc/source/cli/nova-manage.rst +++ b/doc/source/cli/nova-manage.rst @@ -69,7 +69,7 @@ Nova Database deleted rows are archived. Use the ``--max_rows`` option, which defaults to 1000, as a batch size for each iteration (note that the purged API database table records are not included in this batch size). Specifying ``--before`` - will archive only instances that were deleted before the date provided, and + will archive only instances that were deleted before the date_ provided, and records in other tables related to those instances. Specifying ``--purge`` will cause a `full` DB purge to be completed after archival. If a date range is desired for the purge, then run ``nova-manage db purge --before @@ -78,12 +78,12 @@ Nova Database ``nova-manage db purge [--all] [--before ] [--verbose] [--all-cells]`` Delete rows from shadow tables. Specifying ``--all`` will delete all data from all shadow tables. Specifying ``--before`` will delete data from all shadow tables - that is older than the date provided. Date strings may be fuzzy, such as - ``Oct 21 2015``. Specifying ``--verbose`` will cause information to be printed about - purged records. Specifying ``--all-cells`` will cause the purge to be applied against - all cell databases. For ``--all-cells`` to work, the api database connection - information must be configured. Returns exit code 0 if rows were deleted, 1 if - required arguments are not provided, 2 if an invalid date is provided, 3 if no + that is older than the date_ provided. Specifying ``--verbose`` will + cause information to be printed about purged records. Specifying + ``--all-cells`` will cause the purge to be applied against all cell databases. + For ``--all-cells`` to work, the api database connection information must + be configured. Returns exit code 0 if rows were deleted, 1 if required + arguments are not provided, 2 if an invalid date is provided, 3 if no data was deleted, 4 if the list of cells cannot be obtained. ``nova-manage db null_instance_uuid_scan [--delete]`` @@ -163,6 +163,27 @@ Nova Database the work done is non-trivial. Running smaller and more targeted batches (such as specific nodes) is recommended. +.. _date: + +``--before `` + The date argument accepted by the ``--before`` option can be in any + of several formats, including ``YYYY-MM-DD [HH:mm[:ss]]`` and the default + format produced by the ``date`` command, e.g. ``Fri May 24 09:20:11 CDT 2019``. + Date strings containing spaces must be quoted appropriately. Some examples:: + + # Purge shadow table rows older than a specific date + nova-manage db purge --before 2015-10-21 + # or + nova-manage db purge --before "Oct 21 2015" + # Times are also accepted + nova-manage db purge --before "2015-10-21 12:00" + + Note that relative dates (such as ``yesterday``) are not supported natively. + The ``date`` command can be helpful here:: + + # Archive deleted rows more than one month old + nova-manage db archive_deleted_rows --before "$(date -d 'now - 1 month')" + Nova API Database ~~~~~~~~~~~~~~~~~ diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index 0f9d559177..51dba55612 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -488,8 +488,9 @@ Error: %s""") % six.text_type(e)) 'rows, if any, that are removed from the API database for ' 'deleted instances.') @args('--before', metavar='', - help=('Archive rows that have been deleted before this date' - '(YYYY-MM-DD)')) + help=('Archive rows that have been deleted before this date. ' + 'Accepts date strings in the default format output by the ' + '``date`` command, as well as ``YYYY-MM-DD [HH:mm:ss]``.')) @args('--verbose', action='store_true', dest='verbose', default=False, help='Print how many rows were archived per table.') @args('--until-complete', action='store_true', dest='until_complete', @@ -596,7 +597,9 @@ Error: %s""") % six.text_type(e)) @args('--before', metavar='', dest='before', help='If specified, purge rows from shadow tables that are older ' - 'than this. Fuzzy time specs are allowed') + 'than this. Accepts date strings in the default format output ' + 'by the ``date`` command, as well as ``YYYY-MM-DD ' + '[HH:mm:ss]``.') @args('--all', dest='purge_all', action='store_true', help='Purge all rows in the shadow tables') @args('--verbose', dest='verbose', action='store_true', default=False, diff --git a/releasenotes/notes/nova-manage-db-archive-before-option-8296af1c815f5f8a.yaml b/releasenotes/notes/nova-manage-db-archive-before-option-8296af1c815f5f8a.yaml index 9548e28761..f2a2780cc8 100644 --- a/releasenotes/notes/nova-manage-db-archive-before-option-8296af1c815f5f8a.yaml +++ b/releasenotes/notes/nova-manage-db-archive-before-option-8296af1c815f5f8a.yaml @@ -2,4 +2,4 @@ features: - An option ``--before`` has been added to `nova-manage db archive_deleted_rows` command. This options limits - archiving of records to those deleted before the specified date. + archiving of records to those deleted before the specified date.