Manager Handbook for Distributed AntDB-T - P20–5
Published: 2023-08-24 02:22:16

Delete a backup
Command:

```
barman cron 
```
This command will delete the expired and redundant backups according to the backup retention policy in the configuration file.
For example:

```
[antdb@localhost1 ~]$ barman list-backup db1 
db1 20170926T172835 - Tue Sep 26 17:30:07 2017 - Size: 410.6 MiB - WAL Size: 0 B 
db1 20170926T172728 - Tue Sep 26 17:27:23 2017 - Size: 408.0 MiB - WAL Size: 3.0 MiB 
db1 20170926T172446 - Tue Sep 26 17:24:23 2017 - Size: 411.1 MiB - WAL Size: 1.8 MiB - OBSOLETE 
db1 20170926T172350 - Tue Sep 26 17:23:31 2017 - Size: 411.1 MiB - WAL Size: 1.3 MiB - OBSOLETE 
[antdb@localhost1 ~]$ barman cron 
Starting WAL archiving for server db1 
Enforcing retention policy: removing backup 20170926T172350 for server db1 
Deleting backup 20170926T172350 for server db1 
Delete associated WAL segments: 
0000000A0000000000000046 
0000000A0000000000000046.00000028.backup 
0000000A0000000000000047 
00000001000000000000002B 
00000002000000000000002B 
Deleted backup 20170926T172350 (start time: Tue Sep 26 17:32:43 2017, elapsed time: less than one second) 
Enforcing retention policy: removing backup 20170926T172446 for server db1 
Deleting backup 20170926T172446 for server db1 
Delete associated WAL segments: 
0000000A0000000000000048 
0000000A0000000000000048.00000028.backup 
0000000A0000000000000049 
Deleted backup 20170926T172446 (start time: Tue Sep 26 17:32:43 2017, elapsed time: less than one second) 
[dang22@localhost1 ~]$ barman list-backup db1 
db1 20170926T172835 - Tue Sep 26 17:30:07 2017 - Size: 410.6 MiB - WAL Size: 0 B 
db1 20170926T172728 - Tue Sep 26 17:27:23 2017 - Size: 408.0 MiB - WAL Size: 3.0 MiB 
```
Delete a backup
Command:

```
barman delete  server_name backup_id 
```
For example:

```
[antdb@localhost1 ~/barman/conf]$ barman delete db1 20190104T033001 
Deleting backup 20190104T033001 for server db1 
Delete associated WAL segments: 
        000000010000000000000014 
... 
```
Backup all nodes
There are many nodes involved in the cluster and it is recommended to operate through the barman-operate.shscript provided.
The execution of sh barman-operate.sh backup_all will initiate a backup operation on all master nodes. The coordinator and gtmcoord are relatively smaller, which means the backups will take less time, and the datanode will take more time. Check the backup progress of the nodes through the barman log.
Data recovery
Restore to a particular backup id
Command:

```
barman recover server_name backup_id destination_directory 
```
For the meaning of specific parameter, refer to barman recover --help:
For example:

```
[antdb@localhost1 ~]$ barman recover dm0 20190129T152916 /home/antdb/pgdata/datanode/0 --remote-ssh-command='ssh antdb@10.1.226.201' 
Starting remote restore for server dm0 using backup 20190129T152916 
Destination directory: /home/antdb/pgdata_xc/datanode/0 
Copying the base backup. 
Copying required WAL segments. 
Generating archive status files 
Identify dangerous settings in destination directory. 
 
IMPORTANT 
These settings have been modified to prevent data losses 
 
postgresql.conf line 747: archive_command = false 
 
Your PostgreSQL server has been successfully prepared for recovery! 
```
Be aware of the last tip that the node's archive command is turned off after the recovery is complete. You need to set the archive command of all nodes back up after the recovery of all nodes is complete, the data is confirmed to be correct, and the cluster starts to run officially.