Allow extracting files from a backup archive
Dear contributors,
I'd like to kindly request adding the necessary code to be able to extract files from an archive in a remote repository. This, in turn, could be use in combination with other tasks to, say, restore a database, etc.
It would be the equivalent to executing the following commands in the console:
BORG_PASSPHRASE="CHANGEME" \
[email protected]:repo \
borg extract --strip-components 3 ::<archive> var/backups/postgresql/database.bak
The command would be executed in the host, so the file would be extracted in the host where Ansible is connected to. The target directory (e.g. /root/database.bak) should be configurable.
Thanks in advance.
I don't see why you would use Ansible for this and how it's within the scope of this project. Any reason why you can't use Borg directly?
One use case is to extract a copy of the (PostgreSQL | MongoDB | MySQL) production database(s) that was backed up last night and restore it in a test server.
Since they are all inside LinuX Containers and developers don't have access to such containers, I'd like them to connect to a bastion container with Ansible installed and execute a playbook. This playbook would execute a number of tasks, such as:
- Extract the database.bak file from a given archive in the remote repository somewhere into the test server.
- Use
pg_restore(or similar) to restore the dump. - Use
psqlto execute a number of SQL commands to finetune/adapt the restored data.
There is already a BASH script that does this. I could create an Ansible playbook that just executes such script, but I thought it nice to turn it all into a playbook, as there is already Ansible support for PostgreSQL to dump and restore databases.