borgbase / ansible-role-borgbackup

Ansible role to set up Borg and Borgmatic
MIT License
217 stars 98 forks source link

Allow extracting files from a backup archive #104

Open jsabater opened 1 year ago

jsabater commented 1 year ago

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" \
BORG_REPO=m5vz9gp4@m5vz9gp4.repo.borgbase.com: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.

m3nu commented 1 year ago

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?

jsabater commented 1 year ago

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:

  1. Extract the database.bak file from a given archive in the remote repository somewhere into the test server.
  2. Use pg_restore (or similar) to restore the dump.
  3. Use psql to 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.