格式化ansible输出
Format ansible output
我有一个 ansible 角色,它检查我的数据库(cassandra 和 elasticsearch)的最新备份
所以我有这个输出
ansible-playbook other/check_backup_status.yml -i hosts/mvd/prod/hosts.yml
PLAY [check backup] ***************************************************************************************************************************************************************************************************************
TASK [check_backup : check backups for cluster elasticsearch-bishkek] ***************************************************************************************************************************************************************************
skipping: [elasticsearch-bishkek-02]
skipping: [elasticsearch-bishkek-03]
skipping: [elasticsearch-kabul1]
skipping: [elasticsearch-kabul2]
skipping: [elasticsearch-kabul3]
skipping: [elasticsearch-kabul4]
skipping: [elasticsearch-kabul5]
skipping: [elasticsearch-kabul6]
skipping: [cassandra-bishkek01]
skipping: [cassandra-bishkek02]
skipping: [cassandra-bishkek03]
[WARNING]: Consider using the get_url or uri module rather than running 'curl'. If you need to use command because get_url or uri is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False'
in ansible.cfg to get rid of this message.
changed: [elasticsearch-bishkek-01]
TASK [check_backup : Show last 10 backups for elasticsearch bishkek cluster] ***********************************************************************************************************************************************************
ok: [elasticsearch-bishkek-01] => {
"msg": [
"snapshot-2021-01-02-14:20:01 SUCCESS 1609575601 08:20:01 1609575655 08:20:55 54.2s 106 364 0 364",
"snapshot-2021-01-02-20:20:01 SUCCESS 1609597201 14:20:01 1609597260 14:21:00 58.7s 106 364 0 364",
"snapshot-2021-01-03-09:20:01 SUCCESS 1609644002 03:20:02 1609644092 03:21:32 1.4m 106 364 0 364",
"snapshot-2021-01-03-14:20:01 SUCCESS 1609662001 08:20:01 1609662173 08:22:53 2.8m 106 364 0 364",
"snapshot-2021-01-03-20:20:01 SUCCESS 1609683602 14:20:02 1609683671 14:21:11 1.1m 106 364 0 364",
"snapshot-2021-01-04-09:20:01 SUCCESS 1609730401 03:20:01 1609730467 03:21:07 1m 106 364 0 364",
"snapshot-2021-01-04-14:20:01 SUCCESS 1609748402 08:20:02 1609748460 08:21:00 57.8s 106 364 0 364",
"snapshot-2021-01-04-20:20:01 SUCCESS 1609770001 14:20:01 1609770064 14:21:04 1m 106 364 0 364",
"snapshot-2021-01-05-09:20:01 SUCCESS 1609816801 03:20:01 1609816856 03:20:56 54.5s 106 364 0 364",
"snapshot-2021-01-05-14:20:01 SUCCESS 1609834802 08:20:02 1609835018 08:23:38 3.5m 107 365 0 365"
]
}
skipping: [elasticsearch-bishkek-02]
skipping: [elasticsearch-bishkek-03]
skipping: [elasticsearch-kabul1]
skipping: [elasticsearch-kabul2]
skipping: [elasticsearch-kabul3]
skipping: [elasticsearch-kabul4]
skipping: [elasticsearch-kabul5]
skipping: [elasticsearch-kabul6]
skipping: [cassandra-bishkek01]
skipping: [cassandra-bishkek02]
skipping: [cassandra-bishkek03]
TASK [check_backup : check backups for elasticsearch kabul cluster] ******************************************************************************************************************************************************************************
skipping: [elasticsearch-bishkek-01]
skipping: [elasticsearch-bishkek-02]
skipping: [elasticsearch-bishkek-03]
skipping: [elasticsearch-kabul2]
skipping: [elasticsearch-kabul3]
skipping: [elasticsearch-kabul4]
skipping: [elasticsearch-kabul5]
skipping: [elasticsearch-kabul6]
skipping: [cassandra-bishkek01]
skipping: [cassandra-bishkek02]
skipping: [cassandra-bishkek03]
changed: [elasticsearch-kabul1]
TASK [check_backup : Show last 10 backups for elasticsearch-kabul] **************************************************************************************************************************************************************************
skipping: [elasticsearch-bishkek-01]
skipping: [elasticsearch-bishkek-02]
skipping: [elasticsearch-bishkek-03]
ok: [elasticsearch-kabul1] => {
"msg": [
"snapshot-2020-12-27-06:00:01 SUCCESS 1609027201 00:00:01 1609030938 01:02:18 1h 47 131 0 131",
"snapshot-2020-12-28-06:00:01 SUCCESS 1609113602 00:00:02 1609114922 00:22:02 21.9m 50 140 0 140",
"snapshot-2020-12-29-06:00:01 SUCCESS 1609200002 00:00:02 1609201779 00:29:39 29.6m 52 146 0 146",
"snapshot-2020-12-30-06:00:01 SUCCESS 1609286402 00:00:02 1609290726 01:12:06 1.2h 30 76 0 76",
"snapshot-2020-12-31-06:00:01 SUCCESS 1609372802 00:00:02 1609375122 00:38:42 38.6m 31 79 0 79",
"snapshot-2021-01-01-06:00:01 SUCCESS 1609459202 00:00:02 1609461236 00:33:56 33.8m 33 85 0 85",
"snapshot-2021-01-02-06:00:01 SUCCESS 1609545602 00:00:02 1609546580 00:16:20 16.3m 36 94 0 94",
"snapshot-2021-01-03-06:00:01 SUCCESS 1609632003 00:00:03 1609633134 00:18:54 18.8m 37 97 0 97",
"snapshot-2021-01-04-06:00:01 SUCCESS 1609718402 00:00:02 1609719266 00:14:26 14.4m 40 106 0 106",
"snapshot-2021-01-05-06:00:01 SUCCESS 1609804802 00:00:02 1609805812 00:16:52 16.8m 41 109 0 109"
]
}
skipping: [elasticsearch-kabul2]
skipping: [elasticsearch-kabul3]
skipping: [elasticsearch-kabul4]
skipping: [elasticsearch-kabul5]
skipping: [elasticsearch-kabul6]
skipping: [cassandra-bishkek01]
skipping: [cassandra-bishkek02]
skipping: [cassandra-bishkek03]
TASK [check_backup : check backups for Cassandra cluster] *************************************************************************************************************************************************************************
skipping: [elasticsearch-bishkek-01]
skipping: [elasticsearch-bishkek-02]
skipping: [elasticsearch-bishkek-03]
skipping: [elasticsearch-kabul1]
skipping: [elasticsearch-kabul2]
skipping: [elasticsearch-kabul3]
skipping: [elasticsearch-kabul4]
skipping: [elasticsearch-kabul5]
skipping: [elasticsearch-kabul6]
skipping: [cassandra-bishkek02]
skipping: [cassandra-bishkek03]
changed: [cassandra-bishkek01]
TASK [check_backup : show last 10 backups for Cassandra cluster] *********************************************************************************************************************************************************
skipping: [elasticsearch-bishkek-01]
skipping: [elasticsearch-bishkek-02]
skipping: [elasticsearch-bishkek-03]
skipping: [elasticsearch-kabul1]
skipping: [elasticsearch-kabul2]
skipping: [elasticsearch-kabul3]
skipping: [elasticsearch-kabul4]
skipping: [elasticsearch-kabul5]
skipping: [elasticsearch-kabul6]
ok: [cassandra-bishkek01] => {
"msg": [
"2021-01-03__09:20:01 (started: 2021-01-03 09:20:02, finished: 2021-01-03 09:21:16)",
"2021-01-03__14:20:01 (started: 2021-01-03 14:20:02, finished: 2021-01-03 14:20:58)",
"2021-01-03__20:20:01 (started: 2021-01-03 20:20:02, finished: 2021-01-03 20:21:01)",
"2021-01-04__09:20:01 (started: 2021-01-04 09:20:02, finished: 2021-01-04 09:21:36)",
"2021-01-04__14:20:01 (started: 2021-01-04 14:20:02, finished: 2021-01-04 14:20:59)",
"2021-01-04__20:20:01 (started: 2021-01-04 20:20:02, finished: 2021-01-04 20:21:02)",
"2021-01-05__09:20:01 (started: 2021-01-05 09:20:02, finished: 2021-01-05 09:21:25)",
"2021-01-05__14:20:01 (started: 2021-01-05 14:20:02, finished: 2021-01-05 14:21:13)",
"",
"Incomplete backups found. You can run \"medusa status --backup-name <name>\" for more details"
]
}
skipping: [cassandra-bishkek02]
skipping: [cassandra-bishkek03]
PLAY RECAP ************************************************************************************************************************************************************************************************************************
elasticsearch-kabul1 : ok=2 changed=1 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0
elasticsearch-kabul2 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
elasticsearch-kabul3 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
elasticsearch-kabul4 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
elasticsearch-kabul5 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
elasticsearch-kabul6 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
elasticsearch-bishkek-01 : ok=2 changed=1 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0
elasticsearch-bishkek-02 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
elasticsearch-bishkek-03 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
cassandra-bishkek01 : ok=2 changed=1 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0
cassandra-bishkek02 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
cassandra-bishkek03 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
所以你可以看到输出非常大,我想排除除
显示最后 10 个备份 * 任务
例如我只想看到这个输出
TASK [check_backup : Show last 10 backups for elasticsearch bishkek cluster] ***********************************************************************************************************************************************************
ok: [elasticsearch-bishkek-01] => {
"msg": [
"snapshot-2021-01-02-14:20:01 SUCCESS 1609575601 08:20:01 1609575655 08:20:55 54.2s 106 364 0 364",
"snapshot-2021-01-02-20:20:01 SUCCESS 1609597201 14:20:01 1609597260 14:21:00 58.7s 106 364 0 364",
"snapshot-2021-01-03-09:20:01 SUCCESS 1609644002 03:20:02 1609644092 03:21:32 1.4m 106 364 0 364",
"snapshot-2021-01-03-14:20:01 SUCCESS 1609662001 08:20:01 1609662173 08:22:53 2.8m 106 364 0 364",
"snapshot-2021-01-03-20:20:01 SUCCESS 1609683602 14:20:02 1609683671 14:21:11 1.1m 106 364 0 364",
"snapshot-2021-01-04-09:20:01 SUCCESS 1609730401 03:20:01 1609730467 03:21:07 1m 106 364 0 364",
"snapshot-2021-01-04-14:20:01 SUCCESS 1609748402 08:20:02 1609748460 08:21:00 57.8s 106 364 0 364",
"snapshot-2021-01-04-20:20:01 SUCCESS 1609770001 14:20:01 1609770064 14:21:04 1m 106 364 0 364",
"snapshot-2021-01-05-09:20:01 SUCCESS 1609816801 03:20:01 1609816856 03:20:56 54.5s 106 364 0 364",
"snapshot-2021-01-05-14:20:01 SUCCESS 1609834802 08:20:02 1609835018 08:23:38 3.5m 107 365 0 365"
]
}
TASK [check_backup : show last 10 backups for Cassandra cluster] *********************************************************************************************************************************************************
skipping: [elasticsearch-bishkek-01]
skipping: [elasticsearch-bishkek-02]
skipping: [elasticsearch-bishkek-03]
skipping: [elasticsearch-kabul1]
skipping: [elasticsearch-kabul2]
skipping: [elasticsearch-kabul3]
skipping: [elasticsearch-kabul4]
skipping: [elasticsearch-kabul5]
skipping: [elasticsearch-kabul6]
ok: [cassandra-bishkek01] => {
"msg": [
"2021-01-03__09:20:01 (started: 2021-01-03 09:20:02, finished: 2021-01-03 09:21:16)",
"2021-01-03__14:20:01 (started: 2021-01-03 14:20:02, finished: 2021-01-03 14:20:58)",
"2021-01-03__20:20:01 (started: 2021-01-03 20:20:02, finished: 2021-01-03 20:21:01)",
"2021-01-04__09:20:01 (started: 2021-01-04 09:20:02, finished: 2021-01-04 09:21:36)",
"2021-01-04__14:20:01 (started: 2021-01-04 14:20:02, finished: 2021-01-04 14:20:59)",
"2021-01-04__20:20:01 (started: 2021-01-04 20:20:02, finished: 2021-01-04 20:21:02)",
"2021-01-05__09:20:01 (started: 2021-01-05 09:20:02, finished: 2021-01-05 09:21:25)",
"2021-01-05__14:20:01 (started: 2021-01-05 14:20:02, finished: 2021-01-05 14:21:13)",
"",
"Incomplete backups found. You can run \"medusa status --backup-name <name>\" for more details"
]
}
对于 Cassandra 也是如此
那么我如何使用 linux 工具来做到这一点?感谢您的回答
如果 ansible-playbook other/check_backup_status.yml -i hosts/mvd/prod/hosts.yml
命令的输出转到标准输出,我可以通过以下方式将该输出重定向到 awk:
ansible-playbook other/check_backup_status.yml -i hosts/mvd/prod/hosts.yml |
awk '/[Ss]how last 10 backups/,/^\}/'
基本上,使用上面的 awk 命令,您只打印从包含 Show last 10 backups
(是否显示大写)的行开始并在包含 }
作为第一个字符的行。
我有一个 ansible 角色,它检查我的数据库(cassandra 和 elasticsearch)的最新备份 所以我有这个输出
ansible-playbook other/check_backup_status.yml -i hosts/mvd/prod/hosts.yml
PLAY [check backup] ***************************************************************************************************************************************************************************************************************
TASK [check_backup : check backups for cluster elasticsearch-bishkek] ***************************************************************************************************************************************************************************
skipping: [elasticsearch-bishkek-02]
skipping: [elasticsearch-bishkek-03]
skipping: [elasticsearch-kabul1]
skipping: [elasticsearch-kabul2]
skipping: [elasticsearch-kabul3]
skipping: [elasticsearch-kabul4]
skipping: [elasticsearch-kabul5]
skipping: [elasticsearch-kabul6]
skipping: [cassandra-bishkek01]
skipping: [cassandra-bishkek02]
skipping: [cassandra-bishkek03]
[WARNING]: Consider using the get_url or uri module rather than running 'curl'. If you need to use command because get_url or uri is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False'
in ansible.cfg to get rid of this message.
changed: [elasticsearch-bishkek-01]
TASK [check_backup : Show last 10 backups for elasticsearch bishkek cluster] ***********************************************************************************************************************************************************
ok: [elasticsearch-bishkek-01] => {
"msg": [
"snapshot-2021-01-02-14:20:01 SUCCESS 1609575601 08:20:01 1609575655 08:20:55 54.2s 106 364 0 364",
"snapshot-2021-01-02-20:20:01 SUCCESS 1609597201 14:20:01 1609597260 14:21:00 58.7s 106 364 0 364",
"snapshot-2021-01-03-09:20:01 SUCCESS 1609644002 03:20:02 1609644092 03:21:32 1.4m 106 364 0 364",
"snapshot-2021-01-03-14:20:01 SUCCESS 1609662001 08:20:01 1609662173 08:22:53 2.8m 106 364 0 364",
"snapshot-2021-01-03-20:20:01 SUCCESS 1609683602 14:20:02 1609683671 14:21:11 1.1m 106 364 0 364",
"snapshot-2021-01-04-09:20:01 SUCCESS 1609730401 03:20:01 1609730467 03:21:07 1m 106 364 0 364",
"snapshot-2021-01-04-14:20:01 SUCCESS 1609748402 08:20:02 1609748460 08:21:00 57.8s 106 364 0 364",
"snapshot-2021-01-04-20:20:01 SUCCESS 1609770001 14:20:01 1609770064 14:21:04 1m 106 364 0 364",
"snapshot-2021-01-05-09:20:01 SUCCESS 1609816801 03:20:01 1609816856 03:20:56 54.5s 106 364 0 364",
"snapshot-2021-01-05-14:20:01 SUCCESS 1609834802 08:20:02 1609835018 08:23:38 3.5m 107 365 0 365"
]
}
skipping: [elasticsearch-bishkek-02]
skipping: [elasticsearch-bishkek-03]
skipping: [elasticsearch-kabul1]
skipping: [elasticsearch-kabul2]
skipping: [elasticsearch-kabul3]
skipping: [elasticsearch-kabul4]
skipping: [elasticsearch-kabul5]
skipping: [elasticsearch-kabul6]
skipping: [cassandra-bishkek01]
skipping: [cassandra-bishkek02]
skipping: [cassandra-bishkek03]
TASK [check_backup : check backups for elasticsearch kabul cluster] ******************************************************************************************************************************************************************************
skipping: [elasticsearch-bishkek-01]
skipping: [elasticsearch-bishkek-02]
skipping: [elasticsearch-bishkek-03]
skipping: [elasticsearch-kabul2]
skipping: [elasticsearch-kabul3]
skipping: [elasticsearch-kabul4]
skipping: [elasticsearch-kabul5]
skipping: [elasticsearch-kabul6]
skipping: [cassandra-bishkek01]
skipping: [cassandra-bishkek02]
skipping: [cassandra-bishkek03]
changed: [elasticsearch-kabul1]
TASK [check_backup : Show last 10 backups for elasticsearch-kabul] **************************************************************************************************************************************************************************
skipping: [elasticsearch-bishkek-01]
skipping: [elasticsearch-bishkek-02]
skipping: [elasticsearch-bishkek-03]
ok: [elasticsearch-kabul1] => {
"msg": [
"snapshot-2020-12-27-06:00:01 SUCCESS 1609027201 00:00:01 1609030938 01:02:18 1h 47 131 0 131",
"snapshot-2020-12-28-06:00:01 SUCCESS 1609113602 00:00:02 1609114922 00:22:02 21.9m 50 140 0 140",
"snapshot-2020-12-29-06:00:01 SUCCESS 1609200002 00:00:02 1609201779 00:29:39 29.6m 52 146 0 146",
"snapshot-2020-12-30-06:00:01 SUCCESS 1609286402 00:00:02 1609290726 01:12:06 1.2h 30 76 0 76",
"snapshot-2020-12-31-06:00:01 SUCCESS 1609372802 00:00:02 1609375122 00:38:42 38.6m 31 79 0 79",
"snapshot-2021-01-01-06:00:01 SUCCESS 1609459202 00:00:02 1609461236 00:33:56 33.8m 33 85 0 85",
"snapshot-2021-01-02-06:00:01 SUCCESS 1609545602 00:00:02 1609546580 00:16:20 16.3m 36 94 0 94",
"snapshot-2021-01-03-06:00:01 SUCCESS 1609632003 00:00:03 1609633134 00:18:54 18.8m 37 97 0 97",
"snapshot-2021-01-04-06:00:01 SUCCESS 1609718402 00:00:02 1609719266 00:14:26 14.4m 40 106 0 106",
"snapshot-2021-01-05-06:00:01 SUCCESS 1609804802 00:00:02 1609805812 00:16:52 16.8m 41 109 0 109"
]
}
skipping: [elasticsearch-kabul2]
skipping: [elasticsearch-kabul3]
skipping: [elasticsearch-kabul4]
skipping: [elasticsearch-kabul5]
skipping: [elasticsearch-kabul6]
skipping: [cassandra-bishkek01]
skipping: [cassandra-bishkek02]
skipping: [cassandra-bishkek03]
TASK [check_backup : check backups for Cassandra cluster] *************************************************************************************************************************************************************************
skipping: [elasticsearch-bishkek-01]
skipping: [elasticsearch-bishkek-02]
skipping: [elasticsearch-bishkek-03]
skipping: [elasticsearch-kabul1]
skipping: [elasticsearch-kabul2]
skipping: [elasticsearch-kabul3]
skipping: [elasticsearch-kabul4]
skipping: [elasticsearch-kabul5]
skipping: [elasticsearch-kabul6]
skipping: [cassandra-bishkek02]
skipping: [cassandra-bishkek03]
changed: [cassandra-bishkek01]
TASK [check_backup : show last 10 backups for Cassandra cluster] *********************************************************************************************************************************************************
skipping: [elasticsearch-bishkek-01]
skipping: [elasticsearch-bishkek-02]
skipping: [elasticsearch-bishkek-03]
skipping: [elasticsearch-kabul1]
skipping: [elasticsearch-kabul2]
skipping: [elasticsearch-kabul3]
skipping: [elasticsearch-kabul4]
skipping: [elasticsearch-kabul5]
skipping: [elasticsearch-kabul6]
ok: [cassandra-bishkek01] => {
"msg": [
"2021-01-03__09:20:01 (started: 2021-01-03 09:20:02, finished: 2021-01-03 09:21:16)",
"2021-01-03__14:20:01 (started: 2021-01-03 14:20:02, finished: 2021-01-03 14:20:58)",
"2021-01-03__20:20:01 (started: 2021-01-03 20:20:02, finished: 2021-01-03 20:21:01)",
"2021-01-04__09:20:01 (started: 2021-01-04 09:20:02, finished: 2021-01-04 09:21:36)",
"2021-01-04__14:20:01 (started: 2021-01-04 14:20:02, finished: 2021-01-04 14:20:59)",
"2021-01-04__20:20:01 (started: 2021-01-04 20:20:02, finished: 2021-01-04 20:21:02)",
"2021-01-05__09:20:01 (started: 2021-01-05 09:20:02, finished: 2021-01-05 09:21:25)",
"2021-01-05__14:20:01 (started: 2021-01-05 14:20:02, finished: 2021-01-05 14:21:13)",
"",
"Incomplete backups found. You can run \"medusa status --backup-name <name>\" for more details"
]
}
skipping: [cassandra-bishkek02]
skipping: [cassandra-bishkek03]
PLAY RECAP ************************************************************************************************************************************************************************************************************************
elasticsearch-kabul1 : ok=2 changed=1 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0
elasticsearch-kabul2 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
elasticsearch-kabul3 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
elasticsearch-kabul4 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
elasticsearch-kabul5 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
elasticsearch-kabul6 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
elasticsearch-bishkek-01 : ok=2 changed=1 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0
elasticsearch-bishkek-02 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
elasticsearch-bishkek-03 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
cassandra-bishkek01 : ok=2 changed=1 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0
cassandra-bishkek02 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
cassandra-bishkek03 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
所以你可以看到输出非常大,我想排除除 显示最后 10 个备份 * 任务
例如我只想看到这个输出
TASK [check_backup : Show last 10 backups for elasticsearch bishkek cluster] ***********************************************************************************************************************************************************
ok: [elasticsearch-bishkek-01] => {
"msg": [
"snapshot-2021-01-02-14:20:01 SUCCESS 1609575601 08:20:01 1609575655 08:20:55 54.2s 106 364 0 364",
"snapshot-2021-01-02-20:20:01 SUCCESS 1609597201 14:20:01 1609597260 14:21:00 58.7s 106 364 0 364",
"snapshot-2021-01-03-09:20:01 SUCCESS 1609644002 03:20:02 1609644092 03:21:32 1.4m 106 364 0 364",
"snapshot-2021-01-03-14:20:01 SUCCESS 1609662001 08:20:01 1609662173 08:22:53 2.8m 106 364 0 364",
"snapshot-2021-01-03-20:20:01 SUCCESS 1609683602 14:20:02 1609683671 14:21:11 1.1m 106 364 0 364",
"snapshot-2021-01-04-09:20:01 SUCCESS 1609730401 03:20:01 1609730467 03:21:07 1m 106 364 0 364",
"snapshot-2021-01-04-14:20:01 SUCCESS 1609748402 08:20:02 1609748460 08:21:00 57.8s 106 364 0 364",
"snapshot-2021-01-04-20:20:01 SUCCESS 1609770001 14:20:01 1609770064 14:21:04 1m 106 364 0 364",
"snapshot-2021-01-05-09:20:01 SUCCESS 1609816801 03:20:01 1609816856 03:20:56 54.5s 106 364 0 364",
"snapshot-2021-01-05-14:20:01 SUCCESS 1609834802 08:20:02 1609835018 08:23:38 3.5m 107 365 0 365"
]
}
TASK [check_backup : show last 10 backups for Cassandra cluster] *********************************************************************************************************************************************************
skipping: [elasticsearch-bishkek-01]
skipping: [elasticsearch-bishkek-02]
skipping: [elasticsearch-bishkek-03]
skipping: [elasticsearch-kabul1]
skipping: [elasticsearch-kabul2]
skipping: [elasticsearch-kabul3]
skipping: [elasticsearch-kabul4]
skipping: [elasticsearch-kabul5]
skipping: [elasticsearch-kabul6]
ok: [cassandra-bishkek01] => {
"msg": [
"2021-01-03__09:20:01 (started: 2021-01-03 09:20:02, finished: 2021-01-03 09:21:16)",
"2021-01-03__14:20:01 (started: 2021-01-03 14:20:02, finished: 2021-01-03 14:20:58)",
"2021-01-03__20:20:01 (started: 2021-01-03 20:20:02, finished: 2021-01-03 20:21:01)",
"2021-01-04__09:20:01 (started: 2021-01-04 09:20:02, finished: 2021-01-04 09:21:36)",
"2021-01-04__14:20:01 (started: 2021-01-04 14:20:02, finished: 2021-01-04 14:20:59)",
"2021-01-04__20:20:01 (started: 2021-01-04 20:20:02, finished: 2021-01-04 20:21:02)",
"2021-01-05__09:20:01 (started: 2021-01-05 09:20:02, finished: 2021-01-05 09:21:25)",
"2021-01-05__14:20:01 (started: 2021-01-05 14:20:02, finished: 2021-01-05 14:21:13)",
"",
"Incomplete backups found. You can run \"medusa status --backup-name <name>\" for more details"
]
}
对于 Cassandra 也是如此 那么我如何使用 linux 工具来做到这一点?感谢您的回答
如果 ansible-playbook other/check_backup_status.yml -i hosts/mvd/prod/hosts.yml
命令的输出转到标准输出,我可以通过以下方式将该输出重定向到 awk:
ansible-playbook other/check_backup_status.yml -i hosts/mvd/prod/hosts.yml |
awk '/[Ss]how last 10 backups/,/^\}/'
基本上,使用上面的 awk 命令,您只打印从包含 Show last 10 backups
(是否显示大写)的行开始并在包含 }
作为第一个字符的行。