Chapter 9. Backing up and restoring IdM servers using Ansible playbooks
Using the ipabackup
Ansible role, you can automate backing up an IdM server, transferring backup files between servers and your Ansible controller, and restoring an IdM server from a backup.
9.1. Using Ansible to create a backup of an IdM server Copy linkLink copied to clipboard!
You can use the ipabackup
role in an Ansible playbook to create a backup of an IdM server and store it on the IdM server.
Prerequisites
You have configured your Ansible control node to meet the following requirements:
- You are using Ansible version 2.15 or later.
-
You have installed the
freeipa.ansible_freeipa
collection. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_password
and that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipa
module is executed, is part of the IdM domain as an IdM client, server or replica.
Procedure
Navigate to the
~/MyPlaybooks/
directory:cd ~/MyPlaybooks/
$ cd ~/MyPlaybooks/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make a copy of the
backup-server.yml
file located in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks
directory:cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/backup-server.yml backup-my-server.yml
$ cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/backup-server.yml backup-my-server.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Open the
backup-my-server.yml
Ansible playbook file for editing. Adapt the file by setting the
hosts
variable to a host group from your inventory file. In this example, set it to theipaserver
host group:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Save the file.
Run the Ansible playbook, specifying the inventory file and the playbook file:
ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory backup-my-server.yml
$ ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory backup-my-server.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
- Log into the IdM server that you have backed up.
Verify that the backup is in the
/var/lib/ipa/backup
directory.ls /var/lib/ipa/backup/
[root@server ~]# ls /var/lib/ipa/backup/ ipa-full-2021-04-30-13-12-00
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
9.2. Using Ansible to create a backup of an IdM server on your Ansible controller Copy linkLink copied to clipboard!
You can use the ipabackup
role in an Ansible playbook to create a backup of an IdM server and automatically transfer it on your Ansible controller. Your backup file name begins with the host name of the IdM server.
Prerequisites
You have configured your Ansible control node to meet the following requirements:
- You are using Ansible version 2.15 or later.
-
You have installed the
freeipa.ansible_freeipa
collection. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_password
and that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipa
module is executed, is part of the IdM domain as an IdM client, server or replica.
Procedure
To store the backups, create a subdirectory in your home directory on the Ansible controller.
mkdir ~/ipabackups
$ mkdir ~/ipabackups
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Navigate to the
~/MyPlaybooks/
directory:cd ~/MyPlaybooks/
$ cd ~/MyPlaybooks/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make a copy of the
backup-server-to-controller.yml
file located in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks
directory:cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/backup-server-to-controller.yml backup-my-server-to-my-controller.yml
$ cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/backup-server-to-controller.yml backup-my-server-to-my-controller.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Open the
backup-my-server-to-my-controller.yml
file for editing. Adapt the file by setting the following variables:
-
Set the
hosts
variable to a host group from your inventory file. In this example, set it to theipaserver
host group. Optional: To maintain a copy of the backup on the IdM server, uncomment the following line:
ipabackup_keep_on_server: true
# ipabackup_keep_on_server: true
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Set the
By default, backups are stored in the present working directory of the Ansible controller. To specify the backup directory you created in Step 1, add the
ipabackup_controller_path
variable and set it to the/home/user/ipabackups
directory.Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Save the file.
Run the Ansible playbook, specifying the inventory file and the playbook file:
ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory backup-my-server-to-my-controller.yml
$ ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory backup-my-server-to-my-controller.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that the backup is in the
/home/user/ipabackups
directory of your Ansible controller:ls /home/user/ipabackups
[user@controller ~]$ ls /home/user/ipabackups server.idm.example.com_ipa-full-2021-04-30-13-12-00
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
9.3. Using Ansible to copy a backup of an IdM server to your Ansible controller Copy linkLink copied to clipboard!
You can use an Ansible playbook to copy a backup of an IdM server from the IdM server to your Ansible controller.
Prerequisites
On the control node:
- You are using Ansible version 2.15 or later.
-
You have installed the
freeipa.ansible_freeipa
collection. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_password
and that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipa
module is executed, is part of the IdM domain as an IdM client, server or replica.
Procedure
To store the backups, create a subdirectory in your home directory on the Ansible controller.
mkdir ~/ipabackups
$ mkdir ~/ipabackups
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Navigate to the
~/MyPlaybooks/
directory:cd ~/MyPlaybooks/
$ cd ~/MyPlaybooks/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make a copy of the
copy-backup-from-server.yml
file located in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks
directory:cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/copy-backup-from-server.yml copy-backup-from-my-server-to-my-controller.yml
$ cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/copy-backup-from-server.yml copy-backup-from-my-server-to-my-controller.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Open the
copy-my-backup-from-my-server-to-my-controller.yml
file for editing. Adapt the file by setting the following variables:
-
Set the
hosts
variable to a host group from your inventory file. In this example, set it to theipaserver
host group. -
Set the
ipabackup_name
variable to the name of theipabackup
on your IdM server to copy to your Ansible controller. By default, backups are stored in the present working directory of the Ansible controller. To specify the directory you created in Step 1, add the
ipabackup_controller_path
variable and set it to the/home/user/ipabackups
directory.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Set the
- Save the file.
Run the Ansible playbook, specifying the inventory file and the playbook file:
ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory copy-backup-from-my-server-to-my-controller.yml
$ ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory copy-backup-from-my-server-to-my-controller.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteTo copy all IdM backups to your controller, set the
ipabackup_name
variable in the Ansible playbook toall
:vars: ipabackup_name: all ipabackup_to_controller: true
vars: ipabackup_name: all ipabackup_to_controller: true
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For an example, see the
copy-all-backups-from-server.yml
Ansible playbook in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks
directory.
Verification
Verify your backup is in the
/home/user/ipabackups
directory on your Ansible controller:ls /home/user/ipabackups
[user@controller ~]$ ls /home/user/ipabackups server.idm.example.com_ipa-full-2021-04-30-13-12-00
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
9.4. Using Ansible to copy a backup of an IdM server from your Ansible controller to the IdM server Copy linkLink copied to clipboard!
You can use an Ansible playbook to copy a backup of an IdM server from your Ansible controller to the IdM server.
Prerequisites
You have configured your Ansible control node to meet the following requirements:
- You are using Ansible version 2.15 or later.
-
You have installed the
freeipa.ansible_freeipa
collection. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_password
and that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipa
module is executed, is part of the IdM domain as an IdM client, server or replica.
Procedure
Navigate to the
~/MyPlaybooks/
directory:cd ~/MyPlaybooks/
$ cd ~/MyPlaybooks/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make a copy of the
copy-backup-from-controller.yml
file located in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks
directory:cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/copy-backup-from-controller.yml copy-backup-from-my-controller-to-my-server.yml
$ cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/copy-backup-from-controller.yml copy-backup-from-my-controller-to-my-server.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Open the
copy-my-backup-from-my-controller-to-my-server.yml
file for editing. Adapt the file by setting the following variables:
-
Set the
hosts
variable to a host group from your inventory file. In this example, set it to theipaserver
host group. Set the
ipabackup_name
variable to the name of theipabackup
on your Ansible controller to copy to the IdM server.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Set the
- Save the file.
Run the Ansible playbook, specifying the inventory file and the playbook file:
ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory copy-backup-from-my-controller-to-my-server.yml
$ ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory copy-backup-from-my-controller-to-my-server.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
9.5. Using Ansible to remove a backup from an IdM server Copy linkLink copied to clipboard!
You can use an Ansible playbook to remove a backup from an IdM server.
Prerequisites
On the control node:
- You are using Ansible version 2.15 or later.
-
You have installed the
freeipa.ansible_freeipa
collection. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_password
and that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipa
module is executed, is part of the IdM domain as an IdM client, server or replica.
Procedure
Navigate to the ~/MyPlaybooks/ directory:
cd ~/MyPlaybooks/
$ cd ~/MyPlaybooks/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make a copy of the
remove-backup-from-server.yml
file located in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks
directory:cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/remove-backup-from-server.yml remove-backup-from-my-server.yml
$ cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/remove-backup-from-server.yml remove-backup-from-my-server.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Open the
remove-backup-from-my-server.yml
file for editing. Adapt the file by setting the following variables:
-
Set the
hosts
variable to a host group from your inventory file. In this example, set it to theipaserver
host group. Set the
ipabackup_name
variable to the name of theipabackup
to remove from your IdM server.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Set the
- Save the file.
Run the Ansible playbook, specifying the inventory file and the playbook file:
ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory remove-backup-from-my-server.yml
$ ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory remove-backup-from-my-server.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteTo remove all IdM backups from the IdM server, set the
ipabackup_name
variable in the Ansible playbook toall
:vars: ipabackup_name: all
vars: ipabackup_name: all
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For an example, see the
remove-all-backups-from-server.yml
Ansible playbook in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks
directory.
9.6. Using Ansible to restore an IdM server from a backup stored on the server Copy linkLink copied to clipboard!
You can use an Ansible playbook to restore an IdM server from a backup stored on that host.
Prerequisites
On the control node:
- You are using Ansible version 2.15 or later.
-
You have installed the
freeipa.ansible_freeipa
collection. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_password
and that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipa
module is executed, is part of the IdM domain as an IdM client, server or replica. - You know the LDAP Directory Manager password.
Procedure
Navigate to the
~/MyPlaybooks/
directory:cd ~/MyPlaybooks/
$ cd ~/MyPlaybooks/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make a copy of the
restore-server.yml
file located in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks
directory:cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/restore-server.yml restore-my-server.yml
$ cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/restore-server.yml restore-my-server.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Open the
restore-my-server.yml
Ansible playbook file for editing. Adapt the file by setting the following variables:
-
Set the
hosts
variable to a host group from your inventory file. In this example, set it to theipaserver
host group. -
Set the
ipabackup_name
variable to the name of theipabackup
to restore. Set the
ipabackup_password
variable to the LDAP Directory Manager password.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Set the
- Save the file.
Run the Ansible playbook specifying the inventory file and the playbook file:
ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory restore-my-server.yml
$ ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory restore-my-server.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
9.7. Using Ansible to restore an IdM server from a backup stored on your Ansible controller Copy linkLink copied to clipboard!
You can use an Ansible playbook to restore an IdM server from a backup stored on your Ansible controller.
Prerequisites
On the control node:
- You are using Ansible version 2.15 or later.
-
You have installed the
freeipa.ansible_freeipa
collection. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_password
and that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipa
module is executed, is part of the IdM domain as an IdM client, server or replica. - You know the LDAP Directory Manager password.
Procedure
Navigate to the
~/MyPlaybooks/
directory:cd ~/MyPlaybooks/
$ cd ~/MyPlaybooks/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make a copy of the
restore-server-from-controller.yml
file located in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks
directory:cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/restore-server-from-controller.yml restore-my-server-from-my-controller.yml
$ cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/restore-server-from-controller.yml restore-my-server-from-my-controller.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Open the
restore-my-server-from-my-controller.yml
file for editing. Adapt the file by setting the following variables:
-
Set the
hosts
variable to a host group from your inventory file. In this example, set it to theipaserver
host group. -
Set the
ipabackup_name
variable to the name of theipabackup
to restore. Set the
ipabackup_password
variable to the LDAP Directory Manager password.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Set the
- Save the file.
Run the Ansible playbook, specifying the inventory file and the playbook file:
ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory restore-my-server-from-my-controller.yml
$ ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory restore-my-server-from-my-controller.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow